diff options
| author | Christophe Simonis <chs@odoo.com> | 2018-08-21 18:48:13 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2018-08-21 18:48:13 +0200 |
| commit | ef6b574eda3c3c5c8e911f2e8923e24ea8b50b50 (patch) | |
| tree | a7f41d2feb24bf87a80ed67e529ed25a105b6416 /addons/document/static/src/js/document.js | |
| parent | 0c34698c478ab3adc7d768ad140fa4a4dd3d0969 (diff) | |
| parent | 6cc7d3f9451eb41a472053dc3c04da0bbd3c7d1e (diff) | |
[MERGE] forward port branch saas-11.3 up to 6cc7d3f9451
Diffstat (limited to 'addons/document/static/src/js/document.js')
| -rw-r--r-- | addons/document/static/src/js/document.js | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/addons/document/static/src/js/document.js b/addons/document/static/src/js/document.js index 0af85179b49..98bfe4e5ef3 100644 --- a/addons/document/static/src/js/document.js +++ b/addons/document/static/src/js/document.js @@ -15,12 +15,13 @@ Sidebar.include({ */ init : function (parent, options) { this._super.apply(this, arguments); - if (options.viewType === "form") { + this.hasAttachments = options.viewType === "form"; + if (this.hasAttachments) { this.sections.splice(1, 0, { 'name' : 'files', 'label' : _t('Attachment(s)'), }); this.items.files = []; + this.fileuploadId = _.uniqueId('oe_fileupload'); + $(window).on(this.fileuploadId, this._onFileUploaded.bind(this)); } - this.fileuploadId = _.uniqueId('oe_fileupload'); - $(window).on(this.fileuploadId, this._onFileUploaded.bind(this)); }, /** * Get the attachment linked to the record when the toolbar started @@ -29,13 +30,16 @@ Sidebar.include({ */ start: function () { var _super = this._super.bind(this); - this._updateAttachments().then(_super); + var def = this.hasAttachments ? this._updateAttachments() : $.when(); + return def.then(_super); }, /** * @override */ destroy: function () { - $(window).off(this.fileuploadId); + if (this.hasAttachments) { + $(window).off(this.fileuploadId); + } this._super.apply(this, arguments); }, @@ -46,8 +50,10 @@ Sidebar.include({ * @override */ updateEnv: function (env) { - this.env = env; - this._updateAttachments().then(this._redraw.bind(this)); + if (this.hasAttachments) { + this.env = env; + this._updateAttachments().then(this._redraw.bind(this)); + } }, //-------------------------------------------------------------------------- @@ -90,10 +96,12 @@ Sidebar.include({ */ _redraw: function () { this._super.apply(this, arguments); - this.$('.o_sidebar_add_attachment .o_form_binary_form') - .change(this._onAddAttachment.bind(this)); - this.$('.o_sidebar_delete_attachment') - .click(this._onDeleteAttachment.bind(this)); + if (this.hasAttachments) { + this.$('.o_sidebar_add_attachment .o_form_binary_form') + .change(this._onAddAttachment.bind(this)); + this.$('.o_sidebar_delete_attachment') + .click(this._onDeleteAttachment.bind(this)); + } }, /** * Update the attachments to be displayed in the attachment section @@ -102,6 +110,9 @@ Sidebar.include({ * @private */ _updateAttachments: function () { + if (this.items.files === undefined) { + return $.when(); + } var activeId = this.env.activeIds[0]; if (!activeId) { this.items.files = []; |
