From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- .../static/description/an_event.png | Bin 0 -> 6153 bytes .../static/description/calendar_in_action.png | Bin 0 -> 84708 bytes .../static/description/coworker.png | Bin 0 -> 8501 bytes .../static/description/create_quick.png | Bin 0 -> 9583 bytes .../google_calendar/static/description/email.png | Bin 0 -> 32902 bytes addons/google_calendar/static/description/icon.png | Bin 0 -> 10162 bytes addons/google_calendar/static/description/icon.svg | 22 ++ .../google_calendar/static/description/index.html | 116 +++++++++++ .../static/description/notification.png | Bin 0 -> 18674 bytes .../static/description/recurrent.png | Bin 0 -> 33459 bytes .../static/description/the_calendar.png | Bin 0 -> 95173 bytes .../google_calendar/static/src/img/calendar_32.png | Bin 0 -> 1390 bytes .../static/src/js/google_calendar.js | 224 +++++++++++++++++++++ .../static/src/js/google_calendar_popover.js | 26 +++ .../static/src/scss/google_calendar.scss | 14 ++ .../static/src/xml/google_calendar_popover.xml | 8 + .../static/tests/google_calendar_tests.js | 125 ++++++++++++ addons/google_calendar/static/tests/mock_server.js | 20 ++ 18 files changed, 555 insertions(+) create mode 100644 addons/google_calendar/static/description/an_event.png create mode 100644 addons/google_calendar/static/description/calendar_in_action.png create mode 100644 addons/google_calendar/static/description/coworker.png create mode 100644 addons/google_calendar/static/description/create_quick.png create mode 100644 addons/google_calendar/static/description/email.png create mode 100644 addons/google_calendar/static/description/icon.png create mode 100644 addons/google_calendar/static/description/icon.svg create mode 100644 addons/google_calendar/static/description/index.html create mode 100644 addons/google_calendar/static/description/notification.png create mode 100644 addons/google_calendar/static/description/recurrent.png create mode 100644 addons/google_calendar/static/description/the_calendar.png create mode 100644 addons/google_calendar/static/src/img/calendar_32.png create mode 100644 addons/google_calendar/static/src/js/google_calendar.js create mode 100644 addons/google_calendar/static/src/js/google_calendar_popover.js create mode 100644 addons/google_calendar/static/src/scss/google_calendar.scss create mode 100644 addons/google_calendar/static/src/xml/google_calendar_popover.xml create mode 100644 addons/google_calendar/static/tests/google_calendar_tests.js create mode 100644 addons/google_calendar/static/tests/mock_server.js (limited to 'addons/google_calendar/static') diff --git a/addons/google_calendar/static/description/an_event.png b/addons/google_calendar/static/description/an_event.png new file mode 100644 index 00000000..8cffaf9e Binary files /dev/null and b/addons/google_calendar/static/description/an_event.png differ diff --git a/addons/google_calendar/static/description/calendar_in_action.png b/addons/google_calendar/static/description/calendar_in_action.png new file mode 100644 index 00000000..e03c217b Binary files /dev/null and b/addons/google_calendar/static/description/calendar_in_action.png differ diff --git a/addons/google_calendar/static/description/coworker.png b/addons/google_calendar/static/description/coworker.png new file mode 100644 index 00000000..e432095c Binary files /dev/null and b/addons/google_calendar/static/description/coworker.png differ diff --git a/addons/google_calendar/static/description/create_quick.png b/addons/google_calendar/static/description/create_quick.png new file mode 100644 index 00000000..a877ed2d Binary files /dev/null and b/addons/google_calendar/static/description/create_quick.png differ diff --git a/addons/google_calendar/static/description/email.png b/addons/google_calendar/static/description/email.png new file mode 100644 index 00000000..b7ea5a0d Binary files /dev/null and b/addons/google_calendar/static/description/email.png differ diff --git a/addons/google_calendar/static/description/icon.png b/addons/google_calendar/static/description/icon.png new file mode 100644 index 00000000..b8734363 Binary files /dev/null and b/addons/google_calendar/static/description/icon.png differ diff --git a/addons/google_calendar/static/description/icon.svg b/addons/google_calendar/static/description/icon.svg new file mode 100644 index 00000000..6056dc85 --- /dev/null +++ b/addons/google_calendar/static/description/icon.svg @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/addons/google_calendar/static/description/index.html b/addons/google_calendar/static/description/index.html new file mode 100644 index 00000000..8ff283aa --- /dev/null +++ b/addons/google_calendar/static/description/index.html @@ -0,0 +1,116 @@ +
+
+

Google Calendar

+

Get your meetings, your leaves... Get your calendar anywhere and never forget an event.

+
+ +
+
+
+ +
+
+

Keep an eye on your events

+
+

+ See easily the purpose of the meeting, the start time and also the attendee(s)... All that without click on anything... +

+
+
+ +
+
+
+ +
+
+

Create so easily an event

+
+ +
+
+

+ In just one click you can create an event...
+ You can drag and drop your event if you want moved it to another timing.
+ You can shrink or extend the event if you need to change the start's hours or the duration of your meeting. +

+
+
+
+ +
+
+

Create recurrent event

+
+

+ You can also create recurrent events with only one event.
+ You need to create an event each monday of the week ? With only one it's possible, you could specify the recurrence and if one of this event is moved, or deleted, it's not a problem, you can untie your event from the others recurrences. +

+
+
+ +
+ +
+
+ +
+
+

See all events you wants

+
+ +
+
+

+ See in your calendar, the event from others peoples where your are attendee, but also their events by simply adding your favorites coworkers.
+ Every coworker will have their own color in your calendar, and every attendee will have their avatar in the event...
+

+
+ +
+
+ +
+
+

Get an email

+
+

+ You will receive an email at creation of an event where you are attendee, but also when this event is updated for some fields as date start, ... +

+
+
+ +
+ +
+
+ +
+
+

Be notified

+
+ +
+
+

+ You can ask to have a alarm of type 'notification' in your Odoo.
+ You will have a notification in you Odoo which ever the page you are. +

+
+ +
+
+
+
+

Google Calendar

+
+

+ With the plugin Google_calendar, you can synchronize your Odoo calendar with Google Calendar. +

+
+
+ +
+ +
+
diff --git a/addons/google_calendar/static/description/notification.png b/addons/google_calendar/static/description/notification.png new file mode 100644 index 00000000..199d7868 Binary files /dev/null and b/addons/google_calendar/static/description/notification.png differ diff --git a/addons/google_calendar/static/description/recurrent.png b/addons/google_calendar/static/description/recurrent.png new file mode 100644 index 00000000..35b6609e Binary files /dev/null and b/addons/google_calendar/static/description/recurrent.png differ diff --git a/addons/google_calendar/static/description/the_calendar.png b/addons/google_calendar/static/description/the_calendar.png new file mode 100644 index 00000000..87cd4c01 Binary files /dev/null and b/addons/google_calendar/static/description/the_calendar.png differ diff --git a/addons/google_calendar/static/src/img/calendar_32.png b/addons/google_calendar/static/src/img/calendar_32.png new file mode 100644 index 00000000..40dd085f Binary files /dev/null and b/addons/google_calendar/static/src/img/calendar_32.png differ diff --git a/addons/google_calendar/static/src/js/google_calendar.js b/addons/google_calendar/static/src/js/google_calendar.js new file mode 100644 index 00000000..6e250d7b --- /dev/null +++ b/addons/google_calendar/static/src/js/google_calendar.js @@ -0,0 +1,224 @@ +odoo.define('google_calendar.CalendarView', function (require) { +"use strict"; + +var core = require('web.core'); +var Dialog = require('web.Dialog'); +var framework = require('web.framework'); +const CalendarView = require('calendar.CalendarView'); +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; + +const GoogleCalendarModel = CalendarModel.include({ + + /** + * @override + */ + init: function () { + this._super.apply(this, arguments); + this.google_is_sync = true; + this.google_pending_sync = false; + }, + + /** + * @override + */ + __get: function () { + var result = this._super.apply(this, arguments); + result.google_is_sync = this.google_is_sync; + return result; + }, + + + /** + * @override + * @returns {Promise} + */ + async _loadCalendar() { + const _super = this._super.bind(this); + // When the calendar synchronization takes some time, prevents retriggering the sync while navigating the calendar. + if (this.google_pending_sync) { + return _super(...arguments); + } + + try { + await Promise.race([ + new Promise(resolve => setTimeout(resolve, 1000)), + this._syncGoogleCalendar(true) + ]); + } catch (error) { + if (error.event) { + error.event.preventDefault(); + } + console.error("Could not synchronize Google events now.", error); + this.google_pending_sync = false; + } + return _super(...arguments); + }, + + _syncGoogleCalendar(shadow = false) { + var self = this; + var context = this.getSession().user_context; + this.google_pending_sync = true; + return this._rpc({ + route: '/google_calendar/sync_data', + params: { + model: this.modelName, + fromurl: window.location.href, + local_context: context, // LUL TODO remove this local_context + } + }, {shadow}).then(function (result) { + if (result.status === "need_config_from_admin" || result.status === "need_auth") { + self.google_is_sync = false; + } else if (result.status === "no_new_event_from_google" || result.status === "need_refresh") { + self.google_is_sync = true; + } + self.google_pending_sync = false; + 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', + }), + + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * Try to sync the calendar with Google Calendar. According to the result + * from Google API, this function may require an action of the user by the + * mean of a dialog. + * + * @private + * @returns {OdooEvent} event + */ + _onGoogleSyncCalendar: function (event) { + var self = this; + + return this.model._syncGoogleCalendar().then(function (o) { + if (o.status === "need_auth") { + Dialog.alert(self, _t("You will be redirected to Google to authorize access to your calendar!"), { + confirm_callback: function() { + framework.redirect(o.url); + }, + title: _t('Redirection'), + }); + } else if (o.status === "need_config_from_admin") { + if (!_.isUndefined(o.action) && parseInt(o.action)) { + Dialog.confirm(self, _t("The Google Synchronization needs to be configured before you can use it, do you want to do it now?"), { + confirm_callback: function() { + self.do_action(o.action); + }, + title: _t('Configuration'), + }); + } else { + Dialog.alert(self, _t("An administrator needs to configure Google Synchronization before you can use it!"), { + title: _t('Configuration'), + }); + } + } else if (o.status === "need_refresh") { + 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 + //-------------------------------------------------------------------------- + + /** + * Adds the Sync with Google button in the sidebar + * + * @private + */ + _initSidebar: function () { + var self = this; + this._super.apply(this, arguments); + this.$googleButton = $(); + if (this.model === "calendar.event") { + if (this.state.google_is_sync) { + this.$googleButton = $('', {html: _t("Synched with Google")}) + .addClass('o_google_sync badge badge-pill badge-success') + .prepend($('', {class: "fa mr-2 fa-check"})) + .appendTo(self.$sidebar); + } else { + this.$googleButton = $('