1 openerp.google_calendar = function(instance) {
2 var _t = instance.web._t,
3 _lt = instance.web._lt;
4 var QWeb = instance.web.qweb;
6 instance.web_calendar.CalendarView.include({
7 view_loading: function(r) {
9 this.$el.on('click', 'div.oe_cal_sync_button', function() {
10 self.sync_calendar(r);
12 return this._super(r);
14 sync_calendar: function(res, button) {
16 var context = instance.web.pyeval.eval('context');
17 //$('div.oe_cal_sync_button').hide();
18 $('div.oe_cal_sync_button').prop('disabled', true);
20 self.rpc('/google_calendar/sync_data', {
24 fromurl: window.location.href,
25 local_context: context
27 if (o.status === "need_auth") {
28 alert(_t("You will be redirected to Google to authorize access to your calendar!"));
29 instance.web.redirect(o.url);
31 else if (o.status === "need_config_from_admin"){
32 if (!_.isUndefined(o.action) && parseInt(o.action)){
33 if (confirm(_t("The Google Synchronization needs to be configured before you can use it, do you want to do it now?"))) {
34 self.do_action(o.action);
38 alert(_t("An administrator needs to configure Google Synchronization before you can use it!"));
41 else if (o.status === "need_refresh"){
42 self.$calendar.fullCalendar('refetchEvents');
44 else if (o.status === "need_reset"){
45 var confirm_text1 = _t("The account you are trying to synchronize (%s) is not the same as the last one used (%s)!");
46 var confirm_text2 = _t("In order to do this, you first need to disconnect all existing events from the old account.");
47 var confirm_text3 = _t("Do you want to do this now?");
48 var text = _.str.sprintf(confirm_text1 + "\n" + confirm_text2 + "\n\n" + confirm_text3, o.info.new_name, o.info.old_name);
50 self.rpc('/google_calendar/remove_references', {
54 if (o.status === "OK") {
55 alert(_t("All events have been disconnected from your previous account. You can now restart the synchronization"));
57 else if (o.status === "KO") {
58 alert(_t("An error occured while disconnecting events from your previous account. Please retry or contact your administrator."));
64 }).always(function(o) { $('div.oe_cal_sync_button').prop('disabled',false); });
68 instance.web_calendar.CalendarView.include({
69 extraSideBar: function() {
71 if (this.dataset.model == "calendar.event") {
72 this.$el.find('.oe_calendar_filter').prepend(QWeb.render('GoogleCalendar.buttonSynchro'));