From e8b369e7245697dd9ccae800ba09e5cfb45deeee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Wed, 7 Sep 2022 13:34:52 +0000 Subject: [PATCH] [IMP] mail: clean legacy activity file (2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - move BasicActivity to KanbanActivity (only usage of that abstract class) - remove useless class o_activity_link - remove useless class o_activity_label - move d-flex from o_activity_title_entry to template - move align-items-baseline from o_activity_title_entry to template - move o_no_activity SCSS to template - clean selection compute - clean record_id - clean activityState, _setState, _reset - remove obsolete unlink activity code closes odoo/odoo#99824 Related: odoo/enterprise#31201 Signed-off-by: Alexandre Kühn (aku) --- addons/mail/static/src/js/activity.js | 145 +++++------------- .../js/views/activity/activity_renderer.js | 2 +- .../mail/static/src/scss/mail_activity.scss | 7 - .../static/src/xml/web_kanban_activity.xml | 20 +-- 4 files changed, 52 insertions(+), 122 deletions(-) diff --git a/addons/mail/static/src/js/activity.js b/addons/mail/static/src/js/activity.js index 9e1f30857ba..8f71065ebe2 100644 --- a/addons/mail/static/src/js/activity.js +++ b/addons/mail/static/src/js/activity.js @@ -13,25 +13,38 @@ const QWeb = core.qweb; const _t = core._t; const _lt = core._lt; -const BasicActivity = AbstractField.extend({ +// ----------------------------------------------------------------------------- +// Activities Widget for Kanban views ('kanban_activity' widget) +// ----------------------------------------------------------------------------- +const KanbanActivity = AbstractField.extend({ + template: 'mail.KanbanActivity', events: { - 'click .o_edit_activity': '_onEditActivity', 'change input.o_input_file': '_onFileChanged', + 'click .o_activity_template_preview': '_onPreviewMailTemplate', + 'click .o_activity_template_send': '_onSendMailTemplate', + 'click .o_edit_activity': '_onEditActivity', 'click .o_mark_as_done': '_onMarkActivityDone', 'click .o_mark_as_done_upload_file': '_onMarkActivityDoneUploadFile', - 'click .o_activity_template_preview': '_onPreviewMailTemplate', 'click .o_schedule_activity': '_onScheduleActivity', - 'click .o_activity_template_send': '_onSendMailTemplate', - 'click .o_unlink_activity': '_onUnlinkActivity', + 'show.bs.dropdown': '_onDropdownShow', }, - init() { - this._super.apply(this, arguments); - this._draftFeedback = {}; + fieldDependencies: { + activity_exception_decoration: { type: 'selection' }, + activity_exception_icon: { type: 'char' }, + activity_state: { type: 'selection' }, }, - //------------------------------------------------------------ - // Public - //------------------------------------------------------------ + /** + * @override + */ + init(parent, name, record) { + this._super.apply(this, arguments); + this._draftFeedback = {}; + this.selection = {}; + for (const [key, value] of record.fields.activity_state.selection) { + this.selection[key] = value; + } + }, /** * @param {integer} previousActivityTypeID @@ -118,21 +131,6 @@ const BasicActivity = AbstractField.extend({ this.trigger_up('reload', { keepChanges: true }); } }, - /** - * @private - * @param {integer} id - * @param {function} callback - * @return {Promise} - */ - _openActivityForm(id, callback) { - const action = this._getActivityFormAction(id); - return this.do_action(action, { on_close: callback }); - }, - - //------------------------------------------------------------ - // Handlers - //------------------------------------------------------------ - /** * @private * @param {MouseEvent} ev @@ -347,6 +345,15 @@ const BasicActivity = AbstractField.extend({ }, }); }, + /** + * @private + * @param {MouseEvent} ev + * @returns {Promise} + */ + _onScheduleActivity(ev) { + ev.preventDefault(); + return this._openActivityForm(false, this._reload.bind(this)); + }, /** * @private * @param {MouseEvent} ev @@ -365,71 +372,19 @@ const BasicActivity = AbstractField.extend({ }, /** * @private - * @param {MouseEvent} ev - * @returns {Promise} + * @param {integer} id + * @param {function} callback + * @return {Promise} */ - _onScheduleActivity(ev) { - ev.preventDefault(); - return this._openActivityForm(false, this._reload.bind(this)); + _openActivityForm(id, callback) { + const action = this._getActivityFormAction(id); + return this.do_action(action, { on_close: callback }); }, - - /** - * @private - * @param {MouseEvent} ev - * @param {Object} options - * @returns {Promise} - */ - async _onUnlinkActivity(ev, options) { - ev.preventDefault(); - const activityID = $(ev.currentTarget).data('activity-id'); - options = _.defaults(options || {}, { - model: 'mail.activity', - args: [[activityID]], - }); - await this._rpc({ - model: options.model, - method: 'unlink', - args: options.args, - }); - this._reload.bind({ activity: true }); - }, -}); - -// ----------------------------------------------------------------------------- -// Activities Widget for Kanban views ('kanban_activity' widget) -// ----------------------------------------------------------------------------- -const KanbanActivity = BasicActivity.extend({ - template: 'mail.KanbanActivity', - events: _.extend({}, BasicActivity.prototype.events, { - 'show.bs.dropdown': '_onDropdownShow', - }), - fieldDependencies: _.extend({}, BasicActivity.prototype.fieldDependencies, { - activity_exception_decoration: { type: 'selection' }, - activity_exception_icon: { type: 'char' }, - activity_state: { type: 'selection' }, - }), - - /** - * @override - */ - init(parent, name, record) { - this._super.apply(this, arguments); - const selection = {}; - _.each(record.fields.activity_state.selection, function (value) { - selection[value[0]] = value[1]; - }); - this.selection = selection; - this._setState(record); - }, - //------------------------------------------------------------ - // Private - //------------------------------------------------------------ - /** * @private */ _reload() { - this.trigger_up('reload', { db_id: this.record_id, keepChanges: true }); + this.trigger_up('reload', { db_id: this.record.id, keepChanges: true }); }, /** * @override @@ -439,7 +394,7 @@ const KanbanActivity = BasicActivity.extend({ // span classes need to be updated manually because the template cannot // be re-rendered eaasily (because of the dropdown state) const spanClasses = ['fa', 'fa-lg', 'fa-fw']; - spanClasses.push('o_activity_color_' + (this.activityState || 'default')); + spanClasses.push('o_activity_color_' + (this.record.data.activity_state || 'default')); if (this.recordData.activity_exception_decoration) { spanClasses.push('text-' + this.recordData.activity_exception_decoration); spanClasses.push(this.recordData.activity_exception_icon); @@ -500,7 +455,6 @@ const KanbanActivity = BasicActivity.extend({ } const sortedActivities = _.sortBy(activities, 'date_deadline'); this.$('.o_activity').html(QWeb.render('mail.KanbanActivityDropdown', { - selection: this.selection, records: _.groupBy(sortedActivities, 'state'), session: session, widget: this, @@ -520,23 +474,6 @@ const KanbanActivity = BasicActivity.extend({ } } }, - /** - * @override - * @private - * @param {Object} record - */ - _reset(record) { - this._super.apply(this, arguments); - this._setState(record); - }, - /** - * @private - * @param {Object} record - */ - _setState(record) { - this.record_id = record.id; - this.activityState = this.recordData.activity_state; - }, //------------------------------------------------------------ // Handlers diff --git a/addons/mail/static/src/js/views/activity/activity_renderer.js b/addons/mail/static/src/js/views/activity/activity_renderer.js index e5e7098c627..a74048b57d4 100644 --- a/addons/mail/static/src/js/views/activity/activity_renderer.js +++ b/addons/mail/static/src/js/views/activity/activity_renderer.js @@ -31,7 +31,7 @@ class ActivityRecordAdapter extends ComponentAdapter { } /** - * Owl Component Adapter for ActivityCell which is BasicActivity (AbstractField) + * Owl Component Adapter for ActivityCell which is KanbanActivity (AbstractField) * TODO: Remove this adapter when ActivityCell is a Component */ class ActivityCellAdapter extends ComponentAdapter { diff --git a/addons/mail/static/src/scss/mail_activity.scss b/addons/mail/static/src/scss/mail_activity.scss index 6f00500fb08..78040be387e 100644 --- a/addons/mail/static/src/scss/mail_activity.scss +++ b/addons/mail/static/src/scss/mail_activity.scss @@ -79,8 +79,6 @@ li { .o_activity_title_entry { - display: flex; - align-items: baseline; max-width: 275px; .o_activity_summary { @include o-text-overflow; @@ -111,11 +109,6 @@ } } } - - .o_no_activity { - padding: 10px; - cursor: initial; - } } } } diff --git a/addons/mail/static/src/xml/web_kanban_activity.xml b/addons/mail/static/src/xml/web_kanban_activity.xml index 4919149c4f0..2928e0041c0 100644 --- a/addons/mail/static/src/xml/web_kanban_activity.xml +++ b/addons/mail/static/src/xml/web_kanban_activity.xml @@ -6,7 +6,7 @@ - + @@ -19,13 +19,13 @@ -