diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/mail/static/src/js/views/activity/activity_model.js | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/mail/static/src/js/views/activity/activity_model.js')
| -rw-r--r-- | addons/mail/static/src/js/views/activity/activity_model.js | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/addons/mail/static/src/js/views/activity/activity_model.js b/addons/mail/static/src/js/views/activity/activity_model.js new file mode 100644 index 00000000..cfb9e36a --- /dev/null +++ b/addons/mail/static/src/js/views/activity/activity_model.js @@ -0,0 +1,124 @@ +odoo.define('mail.ActivityModel', function (require) { +'use strict'; + +const BasicModel = require('web.BasicModel'); +const session = require('web.session'); + +const ActivityModel = BasicModel.extend({ + + //-------------------------------------------------------------------------- + // Public + //-------------------------------------------------------------------------- + /** + * Add the following (activity specific) keys when performing a `get` on the + * main list datapoint: + * - activity_types + * - activity_res_ids + * - grouped_activities + * + * @override + */ + __get: function () { + var result = this._super.apply(this, arguments); + if (result && result.model === this.modelName && result.type === 'list') { + _.extend(result, this.additionalData, {getKanbanActivityData: this.getKanbanActivityData}); + } + return result; + }, + /** + * @param {Object} activityGroup + * @param {integer} resId + * @returns {Object} + */ + getKanbanActivityData(activityGroup, resId) { + return { + data: { + activity_ids: { + model: 'mail.activity', + res_ids: activityGroup.ids, + }, + activity_state: activityGroup.state, + closest_deadline: activityGroup.o_closest_deadline, + }, + fields: { + activity_ids: {}, + activity_state: { + selection: [ + ['overdue', "Overdue"], + ['today', "Today"], + ['planned', "Planned"], + ], + }, + }, + fieldsInfo: {}, + model: this.model, + type: 'record', + res_id: resId, + getContext: function () { + return {}; + }, + }; + }, + /** + * @override + * @param {Array[]} params.domain + */ + __load: function (params) { + this.originalDomain = _.extend([], params.domain); + params.domain.push(['activity_ids', '!=', false]); + this.domain = params.domain; + this.modelName = params.modelName; + params.groupedBy = []; + var def = this._super.apply(this, arguments); + return Promise.all([def, this._fetchData()]).then(function (result) { + return result[0]; + }); + }, + /** + * @override + * @param {Array[]} [params.domain] + */ + __reload: function (handle, params) { + if (params && 'domain' in params) { + this.originalDomain = _.extend([], params.domain); + params.domain.push(['activity_ids', '!=', false]); + this.domain = params.domain; + } + if (params && 'groupBy' in params) { + params.groupBy = []; + } + var def = this._super.apply(this, arguments); + return Promise.all([def, this._fetchData()]).then(function (result) { + return result[0]; + }); + }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * Fetch activity data. + * + * @private + * @returns {Promise} + */ + _fetchData: function () { + var self = this; + return this._rpc({ + model: "mail.activity", + method: 'get_activity_data', + kwargs: { + res_model: this.modelName, + domain: this.domain, + context: session.user_context, + } + }).then(function (result) { + self.additionalData = result; + }); + }, +}); + +return ActivityModel; + +}); |
