diff --git a/mail_activity/__manifest__.py b/mail_activity/__manifest__.py index 3a0be090..49ddf625 100644 --- a/mail_activity/__manifest__.py +++ b/mail_activity/__manifest__.py @@ -12,12 +12,15 @@ 'mail', ], "data": [ + "views/res_partner.xml", "data/mail_message_subtype.xml", 'security/ir.model.access.csv', 'views/mail_activity.xml', 'data/mail_activity.xml', 'data/ir_model_data.xml', + 'views/templates.xml', ], "qweb": [ + 'static/src/xml/mail_activity.xml', ], } diff --git a/mail_activity/static/src/css/mail_activity.css b/mail_activity/static/src/css/mail_activity.css index e69de29b..664289f6 100644 --- a/mail_activity/static/src/css/mail_activity.css +++ b/mail_activity/static/src/css/mail_activity.css @@ -0,0 +1,64 @@ +.o_mail_activity #o_chatter_planned_activities .o_thread_message .o_thread_message_sidebar .o_avatar_stack img { + width: 31px; + height: 31px; +} +#o_chatter_planned_activities .o_thread_message .o_thread_message_sidebar .o_avatar_stack .o_avatar_icon { + position: absolute; + top: auto; + left: auto; + bottom: -5px; + right: -5px; + width: 25px; + height: 25px; + padding: 6px 5px; + text-align: center; + line-height: 1.2; + color: white; + border-radius: 100%; + border: 2px solid white; +} +.o_mail_activity .o_thread_message { + display: -ms-flexbox; + display: -moz-box; + display: -webkit-box; + display: -webkit-flex; + display: flex; + padding: 4px 16px; + margin-bottom: 0px; +} +.o_mail_activity .o_thread_message .o_thread_message_sidebar { + -ms-flex: 0 0 36px; + -moz-flex: 0 0 36px; + -webkit-box-flex: 0; + -webkit-flex: 0 0 36px; + flex: 0 0 36px; + margin-right: 10px; + margin-top: 2px; + text-align: center; + font-size: smaller; +} +.o_mail_activity .o_thread_message .o_thread_message_core { + -ms-flex: 1 1 auto; + -moz-flex: 1 1 auto; + -webkit-box-flex: 1; + -webkit-flex: 1 1 auto; + flex: 1 1 auto; + min-width: 0; + max-width: 100%; + word-wrap: break-word; +} +.o_mail_activity .o_thread_date_separator.o_border_dashed[data-toggle="collapse"] { + cursor: pointer; +} +.o_mail_activity .o_thread_date_separator.o_border_dashed { + border-bottom-style: dashed; +} +.o_mail_activity .o_thread_date_separator { + margin-top: 15px; + margin-bottom: 30px; + border-bottom: 1px solid #d9d7d7; + text-align: center; +} +.o_mail_activity.o_form_field { + display: block; +} diff --git a/mail_activity/static/src/js/mail_activity.js b/mail_activity/static/src/js/mail_activity.js index 1d0908ea..2a38d594 100644 --- a/mail_activity/static/src/js/mail_activity.js +++ b/mail_activity/static/src/js/mail_activity.js @@ -1,7 +1,172 @@ //-*- coding: utf-8 -*- -//© 2017 Therp BV +//© 2017-2018 Therp BV //License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -openerp.mail_activity = function(instance) +odoo.define('mail.Activity', function(require) { -}; + "use strict"; + var Chatter = require('mail.Chatter'), + Model = require('web.Model'), + form_common = require('web.form_common'), + core = require('web.core'), + _t = core._t; + Chatter.include({ + init: function() { + this._super.apply(this, arguments); + this.schedule_activity_btn = !!this.view.fields.activity_ids + }, + start: function() { + this.$('button.o_chatter_button_schedule_activity').click( + this.proxy('_onScheduleActivity') + ); + this.activity = this.view.fields.activity_ids; + if(this.activity) { + this.$('.o_chatter_topbar').after(this.activity.$el); + } + return this._super.apply(this, arguments); + }, + _onScheduleActivity: function() { + return this.view.fields.activity_ids._scheduleActivity(false); + }, + }); + + /** + * Set the 'label_delay' entry in activity data according to the deadline date + * @param {Array} activities list of activity Object + * @return {Array} : list of modified activity Object + */ + var setDelayLabel = function(activities) { + var today = moment().startOf('day'); + _.each(activities, function(activity){ + var to_display = ''; + var deadline = moment(activity.date_deadline + ' 00:00:00'); + var diff = deadline.diff(today, 'days', true); // true means no rounding + if(diff === 0){ + to_display = _t('Today'); + }else{ + if(diff < 0){ // overdue + if(diff === -1){ + to_display = _t('Yesterday'); + }else{ + to_display = _.str.sprintf(_t('%d days overdue'), Math.abs(diff)); + } + }else{ // due + if(diff === 1){ + to_display = _t('Tomorrow'); + }else{ + to_display = _.str.sprintf(_t('Due in %d days'), Math.abs(diff)); + } + } + } + activity.label_delay = to_display; + }); + return activities; + }; + + var Activity = form_common.AbstractField.extend({ + className: 'o_mail_activity', + events: { + 'click .o_activity_edit': '_onEditActivity', + 'click .o_activity_unlink': '_onUnlinkActivity', + 'click .o_activity_done': '_onMarkActivityDone', + }, + render_value: function() { + return $.when( + this._super.apply(this, arguments), + this._readActivities(), + ).then(this.proxy('_render_value')); + }, + _render_value: function() { + var activities = setDelayLabel(this.activities); + if (activities.length) { + var nbActivities = _.countBy(activities, 'state'); + this.$el.html(core.qweb.render('mail.activity_items', { + activities: activities, + nbPlannedActivities: nbActivities.planned, + nbTodayActivities: nbActivities.today, + nbOverdueActivities: nbActivities.overdue, + })); + } else { + this.$el.empty(); + } + }, + _readActivities: function() { + var self = this; + return new Model('mail.activity') + .query([]) + .filter([['id', 'in', this.get('value')]]) + .all() + .then(function(activities) { + self.activities = activities; + }); + }, + _scheduleActivity: function (id, previous_activity_type_id, callback) { + var self = this, + action = { + type: 'ir.actions.act_window', + res_model: 'mail.activity', + view_mode: 'form', + view_type: 'form', + views: [[false, 'form']], + target: 'new', + context: { + default_res_id: this.view.datarecord.id, + default_res_model: this.view.dataset.model, + default_previous_activity_type_id: + previous_activity_type_id || false, + }, + res_id: id || false, + }; + return this.do_action(action, { + on_close: function() { + if(callback) { + callback(); + } + return self.field_manager.reload() + }, + }) + }, + // handlers + _onEditActivity: function (event, options) { + event.preventDefault(); + var self = this; + var activity_id = $(event.currentTarget).data('activity-id'); + var action = _.defaults(options || {}, { + type: 'ir.actions.act_window', + res_model: 'mail.activity', + view_mode: 'form', + view_type: 'form', + views: [[false, 'form']], + target: 'new', + context: { + default_res_id: this.view.datarecord.id, + default_res_model: this.view.dataset.model, + }, + res_id: activity_id, + }); + return this.do_action(action, { + on_close: function () { + self._render_value(); + }, + }); + }, + _onUnlinkActivity: function (event, options) { + event.preventDefault(); + var activity_id = $(event.currentTarget).data('activity-id'); + options = _.defaults(options || {}, { + model: 'mail.activity', + args: [[activity_id]], + }); + return new Model('mail.activity') + .call('unlink', [activity_id]) + .then(this.render_value.bind(this)); + }, + _onMarkActivityDone: function (event) { + //TODO: this should open a wizard to write a comment and call action_feedback + }, + }); + + core.form_widget_registry.add('mail_activity', Activity); + + return Activity; +}); diff --git a/mail_activity/static/src/xml/mail_activity.xml b/mail_activity/static/src/xml/mail_activity.xml new file mode 100644 index 00000000..86f6fdd7 --- /dev/null +++ b/mail_activity/static/src/xml/mail_activity.xml @@ -0,0 +1,80 @@ + + + + + + + + +
+ + + Planned activities + + + + + + +
+
+ +
+
+
+ + +
+
+
+
+ : + + + for + + +
+
+
Activity type
+
+ +
+
Created on
+
+ +
+
Assigned to
+
+ + + , due on +
+
+
+
+
+ +
+ +
+
+
+
+
+
diff --git a/mail_activity/views/res_partner.xml b/mail_activity/views/res_partner.xml new file mode 100644 index 00000000..fb9ee1d9 --- /dev/null +++ b/mail_activity/views/res_partner.xml @@ -0,0 +1,12 @@ + + + + res.partner + + + + + + + + diff --git a/mail_activity/views/templates.xml b/mail_activity/views/templates.xml new file mode 100644 index 00000000..1403fc9b --- /dev/null +++ b/mail_activity/views/templates.xml @@ -0,0 +1,9 @@ + + + +