diff options
| author | Aurélien (avd) <avd@odoo.com> | 2021-02-04 13:22:15 +0000 |
|---|---|---|
| committer | Aurélien (avd) <avd@odoo.com> | 2021-02-04 14:09:10 +0000 |
| commit | 0564b4a6dacf449e2a87dfdd58bb48b4e79ebfab (patch) | |
| tree | ca13cdd44b47a3f82d4acb079f98af378f327a67 /addons | |
| parent | 506755ef8ced187c0f5cd2fa600e7bb1e1fc0fe3 (diff) | |
[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.
Diffstat (limited to 'addons')
6 files changed, 81 insertions, 1 deletions
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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<templates> + <t t-extend="Calendar.attendee.status.popover"> + <t t-jquery=".o_cw_popover_edit" t-operation="after"> + <a t-if="widget.isGEventSyncedAndArchivable() and widget.isEventDetailsVisible()" href="#" class="btn btn-secondary o_cw_popover_archive_g">Archive</a> + </t> + </t> +</templates> 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 @@ <template id="assets_backend" name="google_calendar assets" inherit_id="web.assets_backend"> <xpath expr="." position="inside"> <link rel="stylesheet" type="text/scss" href="/google_calendar/static/src/scss/google_calendar.scss"/> + <script type="text/javascript" src="/google_calendar/static/src/js/google_calendar_popover.js"></script> <script type="text/javascript" src="/google_calendar/static/src/js/google_calendar.js"></script> </xpath> </template> 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 @@ +<?xml version="1.0"?> +<odoo> + <record id="view_google_calendar_event" model="ir.ui.view"> + <field name="name">google_calendar.event.calendar</field> + <field name="model">calendar.event</field> + <field name="inherit_id" ref="calendar.view_calendar_event_calendar"/> + <field name="arch" type="xml"> + <field name="attendee_status" position="after"> + <field name="google_id" invisible="1"/> + </field> + </field> + </record> +</odoo> |
