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
76
|
odoo.define('web.ProgressBar', function (require) {
'use strict';
const { _t } = require('web.core');
const Dialog = require('web.Dialog');
const Widget = require('web.Widget');
const ProgressBar = Widget.extend({
template: 'web.FileUploadProgressBar',
events: {
'click .o_upload_cross': '_onClickCross',
},
/**
* @override
* @param {Object} param1
* @param {String} param1.title
* @param {String} param1.fileUploadId
* @param {XMLHttpRequest} param2.xhr
*/
init(parent, { title, fileUploadId, xhr }) {
this._super(...arguments);
this.title = title;
this.fileUploadId = fileUploadId;
this.xhr = xhr;
},
/**
* @override
* @return {Promise}
*/
start() {
this.xhr.onabort = () => this.do_notify(false, _t("Upload cancelled"));
return this._super(...arguments);
},
//--------------------------------------------------------------------------
// Public
//--------------------------------------------------------------------------
/**
* @param {integer} loaded
* @param {integer} total
*/
update(loaded, total) {
if (!this.$el) {
return;
}
const percent = Math.round((loaded / total) * 100);
this.$('.o_file_upload_progress_bar_value').css("width", percent + "%");
},
//--------------------------------------------------------------------------
// Handlers
//--------------------------------------------------------------------------
/**
* @private
* @param {MouseEvent} ev
*/
_onClickCross(ev) {
ev.stopPropagation();
const promptText = _.str.sprintf(_t("Do you really want to cancel the upload of %s?"), _.escape(this.title));
Dialog.confirm(this, promptText, {
confirm_callback: () => {
this.xhr.abort();
this.trigger_up('progress_bar_abort', { fileUploadId: this.fileUploadId });
}
});
},
});
return ProgressBar;
});
|