summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/js/activity.js
diff options
context:
space:
mode:
Diffstat (limited to 'addons/mail/static/src/js/activity.js')
-rw-r--r--addons/mail/static/src/js/activity.js293
1 files changed, 200 insertions, 93 deletions
diff --git a/addons/mail/static/src/js/activity.js b/addons/mail/static/src/js/activity.js
index fce7eb29f6f..828e29e195d 100644
--- a/addons/mail/static/src/js/activity.js
+++ b/addons/mail/static/src/js/activity.js
@@ -1,12 +1,13 @@
odoo.define('mail.Activity', function (require) {
"use strict";
+var mailUtils = require('mail.utils');
+
var AbstractField = require('web.AbstractField');
var BasicModel = require('web.BasicModel');
var core = require('web.core');
var field_registry = require('web.field_registry');
var time = require('web.time');
-var utils = require('mail.utils');
var QWeb = core.qweb;
var _t = core._t;
@@ -71,38 +72,49 @@ BasicModel.include({
/**
* 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 setDelayLabel = function (activities){
var today = moment().startOf('day');
- _.each(activities, function(activity){
- var to_display = '';
+ _.each(activities, function (activity){
+ var toDisplay = '';
var diff = activity.date_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));
+ if (diff === 0){
+ toDisplay = _t("Today");
+ } else {
+ if (diff < 0){ // overdue
+ if (diff === -1){
+ toDisplay = _t("Yesterday");
+ } else {
+ toDisplay = _.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));
+ } else { // due
+ if (diff === 1){
+ toDisplay = _t("Tomorrow");
+ } else {
+ toDisplay = _.str.sprintf(_t("Due in %d days"), Math.abs(diff));
}
}
}
- activity.label_delay = to_display;
+ activity.label_delay = toDisplay;
});
return activities;
};
var AbstractActivityField = AbstractField.extend({
- // private
+
+ //------------------------------------------------------------
+ // Private
+ //------------------------------------------------------------
+
+ /**
+ * @private
+ * @param {integer} id
+ * @param {string} feedback
+ * @return {$.Promise}
+ */
_markActivityDone: function (id, feedback) {
return this._rpc({
model: 'mail.activity',
@@ -112,7 +124,14 @@ var AbstractActivityField = AbstractField.extend({
context: this.record.getContext(),
});
},
- _scheduleActivity: function (id, previous_activity_type_id, callback) {
+ /**
+ * @private
+ * @param {integer} id
+ * @param {integer} previousActivityTypeID
+ * @param {function} callback
+ * @return {$.Promise}
+ */
+ _scheduleActivity: function (id, previousActivityTypeID, callback) {
var action = {
type: 'ir.actions.act_window',
res_model: 'mail.activity',
@@ -123,7 +142,7 @@ var AbstractActivityField = AbstractField.extend({
context: {
default_res_id: this.res_id,
default_res_model: this.model,
- default_previous_activity_type_id: previous_activity_type_id,
+ default_previous_activity_type_id: previousActivityTypeID,
},
res_id: id || false,
};
@@ -144,18 +163,49 @@ var Activity = AbstractActivityField.extend({
},
specialData: '_fetchSpecialActivity',
- // inherited
+ /**
+ * @override
+ */
init: function () {
this._super.apply(this, arguments);
- this.activities = this.record.specialData[this.name];
+ this._activities = this.record.specialData[this.name];
+ },
+
+ //------------------------------------------------------------
+ // 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);
},
+
+ //------------------------------------------------------------
+ // Private
+ //------------------------------------------------------------
+
+ /**
+ * @private
+ * @param {Object} fieldsToReload
+ */
+ _reload: function (fieldsToReload) {
+ this.trigger_up('reload_mail_fields', fieldsToReload);
+ },
+ /**
+ * @override
+ * @private
+ */
_render: function () {
- _.each(this.activities, function (activity) {
+ _.each(this._activities, function (activity) {
if (activity.note) {
- activity.note = utils.parse_and_transform(activity.note, utils.add_link);
+ activity.note = mailUtils.parseAndTransform(activity.note, mailUtils.addLink);
}
});
- var activities = setDelayLabel(this.activities);
+ var activities = setDelayLabel(this._activities);
if (activities.length) {
var nbActivities = _.countBy(activities, 'state');
this.$el.html(QWeb.render('mail.activity_items', {
@@ -163,31 +213,33 @@ var Activity = AbstractActivityField.extend({
nbPlannedActivities: nbActivities.planned,
nbTodayActivities: nbActivities.today,
nbOverdueActivities: nbActivities.overdue,
- date_format: time.getLangDateFormat(),
- datetime_format: time.getLangDatetimeFormat(),
+ dateFormat: time.getLangDateFormat(),
+ datetimeFormat: time.getLangDatetimeFormat(),
}));
} else {
this.$el.empty();
}
},
+ /**
+ * @override
+ * @private
+ * @param {Object} record
+ */
_reset: function (record) {
this._super.apply(this, arguments);
- this.activities = this.record.specialData[this.name];
+ this._activities = this.record.specialData[this.name];
// the mail widgets being persistent, one need to update the res_id on reset
this.res_id = record.res_id;
},
- // public
- scheduleActivity: function (previous_activity_type_id) {
- var callback = this._reload.bind(this, {activity: true, thread: true});
- return this._scheduleActivity(false, previous_activity_type_id, callback);
- },
- // private
- _reload: function (fieldsToReload) {
- this.trigger_up('reload_mail_fields', fieldsToReload);
- },
+ //------------------------------------------------------------
+ // Handlers
+ //------------------------------------------------------------
- // handlers
+ /**
+ * @private
+ * @param {MouseEvent} ev
+ */
_onClickRedirect: function (ev) {
var id = $(ev.target).data('oe-id');
if (id) {
@@ -199,10 +251,15 @@ var Activity = AbstractActivityField.extend({
});
}
},
- _onEditActivity: function (event, options) {
- event.preventDefault();
+ /**
+ * @private
+ * @param {MouseEvent} ev
+ * @param {Object} options
+ */
+ _onEditActivity: function (ev, options) {
+ ev.preventDefault();
var self = this;
- var activity_id = $(event.currentTarget).data('activity-id');
+ var activity_id = $(ev.currentTarget).data('activity-id');
var action = _.defaults(options || {}, {
type: 'ir.actions.act_window',
res_model: 'mail.activity',
@@ -222,12 +279,17 @@ var Activity = AbstractActivityField.extend({
},
});
},
- _onUnlinkActivity: function (event, options) {
- event.preventDefault();
- var activity_id = $(event.currentTarget).data('activity-id');
+ /**
+ * @private
+ * @param {MouseEvent} ev
+ * @param {Object} options
+ */
+ _onUnlinkActivity: function (ev, options) {
+ ev.preventDefault();
+ var activityID = $(ev.currentTarget).data('activity-id');
options = _.defaults(options || {}, {
model: 'mail.activity',
- args: [[activity_id]],
+ args: [[activityID]],
});
return this._rpc({
model: options.model,
@@ -236,47 +298,51 @@ var Activity = AbstractActivityField.extend({
})
.then(this._reload.bind(this, {activity: true}));
},
- _onMarkActivityDone: function (event) {
- event.preventDefault();
+ /**
+ * @private
+ * @param {MouseEvent} ev
+ */
+ _onMarkActivityDone: function (ev) {
+ ev.preventDefault();
var self = this;
- var $popover_el = $(event.currentTarget);
- var activity_id = $popover_el.data('activity-id');
- var previous_activity_type_id = $popover_el.data('previous-activity-type-id');
- if (!$popover_el.data('bs.popover')) {
- $popover_el.popover({
- title : _t('Feedback'),
+ 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({
+ title : _t("Feedback"),
html: 'true',
trigger:'click',
- content : function() {
- var $popover = $(QWeb.render("mail.activity_feedback_form", {'previous_activity_type_id': previous_activity_type_id}));
+ content : function () {
+ var $popover = $(QWeb.render('mail.activity_feedback_form', { 'previous_activity_type_id': previousActivityTypeID }));
$popover.on('click', '.o_activity_popover_done_next', function () {
var feedback = _.escape($popover.find('#activity_feedback').val());
- var previous_activity_type_id = $popover_el.data('previous-activity-type-id');
- self._markActivityDone(activity_id, feedback)
- .then(self.scheduleActivity.bind(self, previous_activity_type_id));
+ var previousActivityTypeID = $popoverElement.data('previous-activity-type-id');
+ self._markActivityDone(activityID, feedback)
+ .then(self.scheduleActivity.bind(self, previousActivityTypeID));
});
$popover.on('click', '.o_activity_popover_done', function () {
var feedback = _.escape($popover.find('#activity_feedback').val());
- self._markActivityDone(activity_id, feedback)
- .then(self._reload.bind(self, {activity: true, thread: true}));
+ self._markActivityDone(activityID, feedback)
+ .then(self._reload.bind(self, { activity: true, thread: true }));
});
$popover.on('click', '.o_activity_popover_discard', function () {
- $popover_el.popover('hide');
+ $popoverElement.popover('hide');
});
return $popover;
},
- }).on("show.bs.popover", function (e) {
- var $popover = $(this).data("bs.popover").tip();
+ }).on('show.bs.popover', function (e) {
+ var $popover = $(this).data('bs.popover').tip();
$popover.addClass('o_mail_activity_feedback').attr('tabindex', 0);
- $(".o_mail_activity_feedback.popover").not(e.target).popover("hide");
- }).on("shown.bs.popover", function () {
- var $popover = $(this).data("bs.popover").tip();
+ $('.o_mail_activity_feedback.popover').not(e.target).popover('hide');
+ }).on('shown.bs.popover', function () {
+ var $popover = $(this).data('bs.popover').tip();
$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) {
+ if (!$popover.is(e.relatedTarget) && !$popover.find(e.relatedTarget).length) {
$popover.popover('hide');
}
});
@@ -296,7 +362,9 @@ var KanbanActivity = AbstractActivityField.extend({
'click .o_mark_as_done': '_onMarkActivityDone',
},
- // inherited
+ /**
+ * @override
+ */
init: function (parent, name, record) {
this._super.apply(this, arguments);
var selection = {};
@@ -306,59 +374,98 @@ var KanbanActivity = AbstractActivityField.extend({
this.selection = selection;
this._setState(record);
},
+
+ //------------------------------------------------------------
+ // Private
+ //------------------------------------------------------------
+
+ /**
+ * @private
+ */
+ _reload: function () {
+ this.trigger_up('reload', { db_id: this.record_id });
+ },
+ /**
+ * @override
+ * @private
+ */
_render: function () {
- var $span = this.$(".o_activity_btn > span");
+ var $span = this.$('.o_activity_btn > span');
$span.removeClass(function (index, classNames) {
return classNames.split(/\s+/).filter(function (className) {
return _.str.startsWith(className, 'o_activity_color_');
}).join(' ');
});
- $span.addClass('o_activity_color_' + (this.activity_state || 'default'));
+ $span.addClass('o_activity_color_' + (this.activityState || 'default'));
if (this.$el.hasClass('open')) {
// note: this part of the rendering might be asynchronous
this._renderDropdown();
}
},
- _reset: function (record) {
- this._super.apply(this, arguments);
- this._setState(record);
- },
-
- // private
- _reload: function () {
- this.trigger_up('reload', {db_id: this.record_id});
- },
+ /**
+ * @private
+ */
_renderDropdown: function () {
var self = this;
- this.$('.o_activity').html(QWeb.render("mail.KanbanActivityLoading"));
+ this.$('.o_activity').html(QWeb.render('mail.KanbanActivityLoading'));
return _readActivities(this, this.value.res_ids).then(function (activities) {
- self.$('.o_activity').html(QWeb.render("mail.KanbanActivityDropdown", {
+ self.$('.o_activity').html(QWeb.render('mail.KanbanActivityDropdown', {
selection: self.selection,
records: _.groupBy(setDelayLabel(activities), 'state'),
uid: self.getSession().uid,
}));
});
},
+ /**
+ * @override
+ * @private
+ * @param {Object} record
+ */
+ _reset: function (record) {
+ this._super.apply(this, arguments);
+ this._setState(record);
+ },
+ /**
+ * @private
+ * @param {Object} record
+ */
_setState: function (record) {
this.record_id = record.id;
- this.activity_state = this.recordData.activity_state;
+ this.activityState = this.recordData.activity_state;
},
- // handlers
- _onButtonClicked: function (event) {
- event.preventDefault();
+
+ //------------------------------------------------------------
+ // Handlers
+ //------------------------------------------------------------
+
+ /**
+ * @private
+ * @param {MouseEvent} ev
+ */
+ _onButtonClicked: function (ev) {
+ ev.preventDefault();
if (!this.$el.hasClass('open')) {
this._renderDropdown();
}
},
- _onMarkActivityDone: function (event) {
- event.stopPropagation();
- var activity_id = $(event.currentTarget).data('activity-id');
- this._markActivityDone(activity_id).then(this._reload.bind(this));
+ /**
+ * @private
+ * @param {MouseEvent} ev
+ */
+ _onMarkActivityDone: function (ev) {
+ ev.stopPropagation();
+ var activityID = $(ev.currentTarget).data('activity-id');
+ this._markActivityDone(activityID).then(this._reload.bind(this));
},
- _onScheduleActivity: function (event) {
- var activity_id = $(event.currentTarget).data('activity-id') || false;
- return this._scheduleActivity(activity_id, false, this._reload.bind(this));
+ /**
+ * @private
+ * @param {MouseEvent} ev
+ * @returns {$.Promise}
+ */
+ _onScheduleActivity: function (ev) {
+ var activityID = $(ev.currentTarget).data('activity-id') || false;
+ return this._scheduleActivity(activityID, false, this._reload.bind(this));
},
});