portal_sidebar.js
2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
odoo.define('portal.PortalSidebar', function (require) {
'use strict';
var core = require('web.core');
var publicWidget = require('web.public.widget');
var time = require('web.time');
var session = require('web.session');
var _t = core._t;
var PortalSidebar = publicWidget.Widget.extend({
/**
* @override
*/
start: function () {
this._setDelayLabel();
return this._super.apply(this, arguments);
},
//--------------------------------------------------------------------------
// Private
//---------------------------------------------------------------------------
/**
* Set the due/delay information according to the given date
* like : <span class="o_portal_sidebar_timeago" t-att-datetime="invoice.date_due"/>
*
* @private
*/
_setDelayLabel: function () {
var $sidebarTimeago = this.$el.find('.o_portal_sidebar_timeago');
_.each($sidebarTimeago, function (el) {
var dateTime = moment(time.auto_str_to_date($(el).attr('datetime'))),
today = moment().startOf('day'),
diff = dateTime.diff(today, 'days', true),
displayStr;
session.is_bound.then(function (){
if (diff === 0) {
displayStr = _t('Due today');
} else if (diff > 0) {
// Workaround: force uniqueness of these two translations. We use %1d because the string
// with %d is already used in mail and mail's translations are not sent to the frontend.
displayStr = _.str.sprintf(_t('Due in %1d days'), Math.abs(diff));
} else {
displayStr = _.str.sprintf(_t('%1d days overdue'), Math.abs(diff));
}
$(el).text(displayStr);
});
});
},
/**
* @private
* @param {string} href
*/
_printIframeContent: function (href) {
// due to this issue : https://bugzilla.mozilla.org/show_bug.cgi?id=911444
// open a new window with pdf for print in Firefox (in other system: http://printjs.crabbly.com)
if ($.browser.mozilla) {
window.open(href, '_blank');
return;
}
if (!this.printContent) {
this.printContent = $('<iframe id="print_iframe_content" src="' + href + '" style="display:none"></iframe>');
this.$el.append(this.printContent);
this.printContent.on('load', function () {
$(this).get(0).contentWindow.print();
});
} else {
this.printContent.get(0).contentWindow.print();
}
},
});
return PortalSidebar;
});