From 0564b4a6dacf449e2a87dfdd58bb48b4e79ebfab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20=28avd=29?= Date: Thu, 4 Feb 2021 13:22:15 +0000 Subject: [IMP] google_calendar: allow to archive from calendar view Change Delete secondary button on calendar popover to Archive for synced calendar event. This makes it easier to delete synced calendar events. --- addons/google_calendar/__manifest__.py | 1 + .../static/src/js/google_calendar.js | 33 +++++++++++++++++++++- .../static/src/js/google_calendar_popover.js | 26 +++++++++++++++++ .../static/src/xml/google_calendar_popover.xml | 8 ++++++ .../views/google_calendar_templates.xml | 1 + .../views/google_calendar_views.xml | 13 +++++++++ 6 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 addons/google_calendar/static/src/js/google_calendar_popover.js create mode 100644 addons/google_calendar/static/src/xml/google_calendar_popover.xml create mode 100644 addons/google_calendar/views/google_calendar_views.xml (limited to 'addons') diff --git a/addons/google_calendar/__manifest__.py b/addons/google_calendar/__manifest__.py index a743f7528a2..8e90d83ac8c 100644 --- a/addons/google_calendar/__manifest__.py +++ b/addons/google_calendar/__manifest__.py @@ -14,6 +14,7 @@ 'wizard/reset_account_views.xml', 'views/res_config_settings_views.xml', 'views/res_users_views.xml', + 'views/google_calendar_views.xml', 'views/google_calendar_templates.xml', ], 'demo': [], diff --git a/addons/google_calendar/static/src/js/google_calendar.js b/addons/google_calendar/static/src/js/google_calendar.js index c7157aa359e..ec8313e0e9e 100644 --- a/addons/google_calendar/static/src/js/google_calendar.js +++ b/addons/google_calendar/static/src/js/google_calendar.js @@ -9,6 +9,7 @@ const CalendarRenderer = require('calendar.CalendarRenderer'); const CalendarController = require('calendar.CalendarController'); const CalendarModel = require('calendar.CalendarModel'); const viewRegistry = require('web.view_registry'); +const session = require('web.session'); var _t = core._t; @@ -71,11 +72,21 @@ const GoogleCalendarModel = CalendarModel.include({ return result }); }, + + archiveRecords: function (ids, model) { + return this._rpc({ + model: model, + method: 'action_archive', + args: [ids], + context: session.user_context, + }); + }, }) const GoogleCalendarController = CalendarController.include({ custom_events: _.extend({}, CalendarController.prototype.custom_events, { syncGoogleCalendar: '_onGoogleSyncCalendar', + archiveRecord: '_onArchiveRecord', }), @@ -119,13 +130,28 @@ const GoogleCalendarController = CalendarController.include({ self.reload(); } }).then(event.data.on_always, event.data.on_always); - } + }, + + _onArchiveRecord: function (ev) { + var self = this; + Dialog.confirm(this, _t("Are you sure you want to archive this record ?"), { + confirm_callback: function () { + self.model.archiveRecords([ev.data.id], self.modelName).then(function () { + self.reload(); + }); + } + }); + }, }); const GoogleCalendarRenderer = CalendarRenderer.include({ events: _.extend({}, CalendarRenderer.prototype.events, { 'click .o_google_sync_button': '_onGoogleSyncCalendar', }), + + custom_events: _.extend({}, CalendarRenderer.prototype.custom_events, { + archive_event: '_onArchiveEvent', + }), //-------------------------------------------------------------------------- // Private @@ -173,6 +199,11 @@ const GoogleCalendarRenderer = CalendarRenderer.include({ }, }); }, + + _onArchiveEvent: function (ev) { + this._unselectEvent(); + this.trigger_up('archiveRecord', {id: parseInt(ev.data.id, 10)}); + } }); return { diff --git a/addons/google_calendar/static/src/js/google_calendar_popover.js b/addons/google_calendar/static/src/js/google_calendar_popover.js new file mode 100644 index 00000000000..89296d62113 --- /dev/null +++ b/addons/google_calendar/static/src/js/google_calendar_popover.js @@ -0,0 +1,26 @@ +odoo.define('google_calendar.GoogleCalendarPopover', function(require) { + "use strict"; + + const CalendarPopover = require('web.CalendarPopover'); + + const GoogleCalendarPopover = CalendarPopover.include({ + events: _.extend({}, CalendarPopover.prototype.events, { + 'click .o_cw_popover_archive_g': '_onClickPopoverGArchive', + }), + + isGEventSyncedAndArchivable() { + return this.event.extendedProps.record.google_id; + }, + + isEventDeletable() { + return !this.isGEventSyncedAndArchivable() && this._super(); + }, + + _onClickPopoverGArchive: function (ev) { + ev.preventDefault(); + this.trigger_up('archive_event', {id: this.event.id}); + }, + }) + + return GoogleCalendarPopover; +}); diff --git a/addons/google_calendar/static/src/xml/google_calendar_popover.xml b/addons/google_calendar/static/src/xml/google_calendar_popover.xml new file mode 100644 index 00000000000..641b1fcc60a --- /dev/null +++ b/addons/google_calendar/static/src/xml/google_calendar_popover.xml @@ -0,0 +1,8 @@ + + + + + Archive + + + diff --git a/addons/google_calendar/views/google_calendar_templates.xml b/addons/google_calendar/views/google_calendar_templates.xml index 3b79f6a5a1e..5ec3eaaf234 100644 --- a/addons/google_calendar/views/google_calendar_templates.xml +++ b/addons/google_calendar/views/google_calendar_templates.xml @@ -3,6 +3,7 @@ diff --git a/addons/google_calendar/views/google_calendar_views.xml b/addons/google_calendar/views/google_calendar_views.xml new file mode 100644 index 00000000000..1d22a10e548 --- /dev/null +++ b/addons/google_calendar/views/google_calendar_views.xml @@ -0,0 +1,13 @@ + + + + google_calendar.event.calendar + calendar.event + + + + + + + + -- cgit v1.2.3