[IMP] Show button google cal only on crm meeting model
[odoo/odoo.git] / addons / google_calendar / static / src / js / calendar_sync.js
1 openerp.google_calendar = function(instance) {
2     var _t = instance.web._t,
3        _lt = instance.web._lt;
4     var QWeb = instance.web.qweb;
5
6     instance.web_calendar.FullCalendarView.include({
7         view_loading: function(r) {
8             var self = this;
9             this.$el.on('click', 'div.oe_cal_sync_button', function() {
10                 console.log("Launch synchro");
11                 self.sync_calendar(r);
12             });
13             return this._super(r);
14         },
15         sync_calendar: function(res,button) {
16             var self = this;
17             var context = instance.web.pyeval.eval('context');
18             //$('div.oe_cal_sync_button').hide();
19             $('div.oe_cal_sync_button').prop('disabled',true);
20             
21             self.rpc('/web_calendar_sync/sync_calendar/sync_data', {
22                 arch: res.arch,
23                 fields: res.fields,
24                 model:res.model,
25                 fromurl: window.location.href,
26                 LocalContext:context
27             }).done(function(o) {
28                 console.log(o);
29                 
30                 if (o.status == "NeedAuth") {
31                     alert(_t("You will be redirected on gmail to authorize your OpenErp to access your calendar !"));
32                     window.location = o.url;
33                 }
34                 else if (o.status == "NeedConfigFromAdmin") {
35                     alert(_t("Admin need to configure Google Synchronization before to use it !"));
36                     window.location = o.url;
37                 }
38                 else if (o.status == "NeedRefresh"){
39                     self.$calendar.fullCalendar('refetchEvents');
40                 }
41
42             }).always(function(o) { $('div.oe_cal_sync_button').prop('disabled',false); });
43         }
44     });
45     
46     instance.web_calendar.FullCalendarView.include({
47         extraSideBar: function() {
48             this._super();
49             if (this.dataset.model == "crm.meeting") {
50                 var button = QWeb.render('GoogleCalendar.buttonSynchro');
51                 this.$el.find('.oe_calendar_filter').prepend(button);
52                 console.log("added");
53            }
54         }
55     });
56
57 };