openerp.calendar = function(instance) {
var _t = instance.web._t;
var QWeb = instance.web.qweb;
instance.calendar = {}
instance.web.WebClient = instance.web.WebClient.extend({
getMyNotifBox: function(me) {
return $(me).closest(".ui-notify-message-style");
},
get_next_event: function() {
var self= this;
this.rpc("/calendar/NextNotify", {
type: "GET"
})
.then(
function(result) {
console.log(result);
_.each(result, function(res) {
setTimeout(function() {
//If notification not already displayed, we add button and action on it
if (!($.find(".eid_"+res.event_id)).length) {
res.title = "" + res.title + "";
res.message += "
\
\
";
a = self.do_notify(res.title,res.message,true);
$(".link2event").on('click', function() {
self.rpc("/web/action/load", {
action_id: "calendar.action_crm_meeting_notify",
}).then( function(r) {
r.res_id = res.event_id;
return self.action_manager.do_action(r);
});
});
a.element.find(".link2recall").on('click',function() {
self.getMyNotifBox(this).find('.ui-notify-close').trigger("click");
});
a.element.find(".link2showed").on('click',function() {
self.getMyNotifBox(this).find('.ui-notify-close').trigger("click");
self.rpc("/calendar/NextNotify", {
type: "UPDATE"
});
});
}
//If notification already displayed in the past, we remove the css attribute which hide this notification
else if (self.getMyNotifBox($.find(".eid_"+res.event_id)).attr("style") !== ""){
self.getMyNotifBox($.find(".eid_"+res.event_id)).attr("style","");
}
},res.timer * 1000);
});
}
);
},
check_notifications: function() {
var self= this;
self.get_next_event();
setInterval(function(){
self.get_next_event();
}, 5 * 60 * 1000 );
},
//Override the show_application of addons/web/static/src/js/chrome.js
show_application: function() {
this._super();
this.check_notifications();
}
});
instance.calendar.invitation = instance.web.Widget.extend({
init: function(parent, db, action, id, view, attendee_data) {
this._super();
this.db = db;
this.action = action;
this.id = id;
this.view = view;
this.attendee_data = attendee_data;
},
start: function() {
var self = this;
if(instance.session.session_is_valid(self.db) && instance.session.username != "anonymous") {
self.redirect_meeting_view(self.db,self.action,self.id,self.view);
} else {
self.open_invitation_form(self.attendee_data);
}
},
open_invitation_form : function(invitation){
this.$el.html(QWeb.render('invitation_view', {'invitation': JSON.parse(invitation)}));
},
redirect_meeting_view : function(db, action, meeting_id, view){
var self = this;
var action_url = '';
if(view == "form") {
action_url = _.str.sprintf('/?db=%s#id=%s&view_type=%s&model=crm.meeting', db, meeting_id, view, meeting_id);
} else {
action_url = _.str.sprintf('/?db=%s#view_type=%s&model=crm.meeting&action=%s',self.db,self.view,self.action);
}
var reload_page = function(){
return location.replace(action_url);
}
reload_page();
},
});
instance.web.form.Many2ManyAttendee = instance.web.form.FieldMany2ManyTags.extend({
tag_template: "many2manyattendee",
initialize_texttext: function() {
return _.extend(this._super(),{
html : {
tag: '