diff options
| author | RomainLibert <rli@odoo.com> | 2018-08-09 14:22:00 +0200 |
|---|---|---|
| committer | RomainLibert <rli@odoo.com> | 2018-08-10 12:08:09 +0200 |
| commit | fd02fec8d8d0dc73d2403cef540922dc25534e93 (patch) | |
| tree | d1a05b00fe352cb57e69c3fa860a0705ea6c98a4 /addons/mail/static/src/js/activity.js | |
| parent | 3f3593a4fd35cb4956e9ae0954b7c0944ce418df (diff) | |
[IMP] mail: add feedback option to kanban activities
In the kanban view, there was no possibility to add a feedback when
closing an activity this commit adds the same popover as the one we have
in the form view.
This commit also add the templates to this popover with the possible to
directly send the template or open the composer.
Task #1870662
Closes #26280
Diffstat (limited to 'addons/mail/static/src/js/activity.js')
| -rw-r--r-- | addons/mail/static/src/js/activity.js | 110 |
1 files changed, 108 insertions, 2 deletions
diff --git a/addons/mail/static/src/js/activity.js b/addons/mail/static/src/js/activity.js index 1221cab2f52..acd15cbef20 100644 --- a/addons/mail/static/src/js/activity.js +++ b/addons/mail/static/src/js/activity.js @@ -447,6 +447,8 @@ var KanbanActivity = AbstractActivityField.extend({ 'show.bs.dropdown': '_onDropdownShow', 'click .o_schedule_activity': '_onScheduleActivity', 'click .o_mark_as_done': '_onMarkActivityDone', + 'click .o_activity_template_preview': '_onPreviewMailTemplate', + 'click .o_activity_template_send': '_onSendMailTemplate', }, /** @@ -460,6 +462,7 @@ var KanbanActivity = AbstractActivityField.extend({ }); this.selection = selection; this._setState(record); + this._draftFeedback = {}; }, //------------------------------------------------------------ @@ -523,6 +526,19 @@ var KanbanActivity = AbstractActivityField.extend({ //------------------------------------------------------------ + // Public + //------------------------------------------------------------ + + /** + * @param {integer} previousActivityTypeID + * @return {$.Promise} + */ + scheduleActivity: function (previousActivityTypeID) { + var callback = this._reload.bind(this, { activity: true, thread: true }); + return this._scheduleActivity(false, previousActivityTypeID, callback); + }, + + //------------------------------------------------------------ // Handlers //------------------------------------------------------------ @@ -538,8 +554,61 @@ var KanbanActivity = AbstractActivityField.extend({ */ _onMarkActivityDone: function (ev) { ev.stopPropagation(); - var activityID = $(ev.currentTarget).data('activity-id'); - this._sendActivityFeedback(activityID).then(this._reload.bind(this)); + var self = this; + var $popoverElement = $(ev.currentTarget); + var activityID = $popoverElement.data('activity-id'); + var previousActivityTypeID = $popoverElement.data('previous-activity-type-id'); + + if (!$popoverElement.data('bs.popover')) { + $popoverElement.popover({ + template: $(Popover.Default.template).addClass('o_mail_activity_feedback')[0].outerHTML, // Ugly but cannot find another way + container: $popoverElement.parent(), // FIXME Ugly and should probably be in the body as by default but form view should handle destroying popovers + title : _t("Feedback"), + html: true, + trigger:'click', + content : function () { + var $popover = $(QWeb.render('mail.activity_feedback_form', { 'previous_activity_type_id': previousActivityTypeID })); + $popover.find('#activity_feedback').val(self._draftFeedback[activityID]); + $popover.on('click', function (ev) { + ev.stopPropagation(); + }); + $popover.on('click', '.o_activity_popover_done', function (ev) { + ev.stopPropagation(); + self._markActivityDone({ + activityID: activityID, + feedback: _.escape($popover.find('#activity_feedback').val()), + }); + }); + $popover.on('click', '.o_activity_popover_done_next', function (ev) { + ev.stopPropagation(); + self._markActivityDoneAndScheduleNext({ + activityID: activityID, + activityTypeID: $popoverElement.data('previous-activity-type-id'), + feedback: _.escape($popover.find('#activity_feedback').val()), + }); + }); + $popover.on('click', '.o_activity_popover_discard', function (ev) { + ev.stopPropagation(); + $popoverElement.popover('hide'); + }); + return $popover; + }, + }).on('shown.bs.popover', function () { + var $popover = $($(this).data("bs.popover").tip); + $(".o_mail_activity_feedback.popover").not($popover).popover("hide"); + $popover.addClass('o_mail_activity_feedback').attr('tabindex', 0); + $popover.find('#activity_feedback').focus(); + $popover.off('focusout'); + $popover.focusout(function (e) { + // outside click of popover hide the popover + // e.relatedTarget is the element receiving the focus + if (!$popover.is(e.relatedTarget) && !$popover.find(e.relatedTarget).length) { + self._draftFeedback[activityID] = $popover.find('#activity_feedback').val(); + $popover.popover('hide'); + } + }); + }).popover('show'); + } }, /** * @private @@ -550,6 +619,43 @@ var KanbanActivity = AbstractActivityField.extend({ var activityID = $(ev.currentTarget).data('activity-id') || false; return this._scheduleActivity(activityID, false, this._reload.bind(this)); }, + /** + * @private + * @param {MouseEvent} ev + */ + _onPreviewMailTemplate: function (ev) { + ev.stopPropagation(); + var templateID = $(ev.target).data('template-id'); + var action = { + name: _t('Compose Email'), + type: 'ir.actions.act_window', + res_model: 'mail.compose.message', + views: [[false, 'form']], + target: 'new', + context: { + default_res_id: this.res_id, + default_model: this.model, + default_use_template: true, + default_template_id: templateID, + force_email: true, + }, + }; + return this.do_action(action, { on_close: function(){}}); + }, + /** + * @private + * @param {MouseEvent} ev + */ + _onSendMailTemplate: function (ev) { + ev.stopPropagation(); + var templateID = $(ev.target).data('template-id'); + return this._rpc({ + model: this.model, + method: 'activity_send_mail', + args: [[this.res_id], templateID], + }) + .then(this._reload.bind(this, {activity: true, thread: true, followers: true})); + }, }); field_registry |
