You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.7 KiB

  1. //Copyright2018 Eficent <http://www.eficent.com>
  2. //License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
  3. odoo.define('mail.Activity.done', function(require) {
  4. "use strict";
  5. var core = require('web.core');
  6. var utils = require('mail.utils');
  7. var time = require('web.time');
  8. var mail_activity = require('mail.Activity');
  9. var QWeb = core.qweb;
  10. var _t = core._t;
  11. // We are forced here to override the method, as there is no possibility
  12. // to inherit it.
  13. var setDelayLabel = function(activities) {
  14. var today = moment().startOf('day');
  15. _.each(activities, function(activity) {
  16. var to_display = '';
  17. var deadline = moment(activity.date_deadline).startOf('day');
  18. var diff = deadline.diff(today, 'days', true); // true means no rounding
  19. if(diff === 0){
  20. to_display = _t('Today');
  21. }else{
  22. if(diff < 0){ // overdue
  23. if(diff === -1){
  24. to_display = _t('Yesterday');
  25. }else{
  26. to_display = _.str.sprintf(_t('%d days overdue'), Math.abs(diff));
  27. }
  28. }else{ // due
  29. if(diff === 1){
  30. to_display = _t('Tomorrow');
  31. }else{
  32. to_display = _.str.sprintf(_t('Due in %d days'), Math.abs(diff));
  33. }
  34. }
  35. }
  36. activity.label_delay = to_display;
  37. });
  38. // We do not want to show the activities that have been completed.
  39. var open_activities = _.filter(activities, function(activity){
  40. return activity.done !== true
  41. });
  42. return open_activities;
  43. };
  44. var Activity = mail_activity.include({
  45. _render: function () {
  46. _.each(this.activities, function (activity) {
  47. if (activity.note) {
  48. activity.note = utils.parse_and_transform(activity.note, utils.add_link);
  49. }
  50. });
  51. var activities = setDelayLabel(this.activities);
  52. if (activities.length) {
  53. var nbActivities = _.countBy(activities, 'state');
  54. this.$el.html(QWeb.render('mail.activity_items', {
  55. activities: activities,
  56. nbPlannedActivities: nbActivities.planned,
  57. nbTodayActivities: nbActivities.today,
  58. nbOverdueActivities: nbActivities.overdue,
  59. date_format: time.getLangDateFormat(),
  60. datetime_format: time.getLangDatetimeFormat(),
  61. }));
  62. } else {
  63. this.$el.empty();
  64. }
  65. },
  66. });
  67. });