From 8b875e4dd4c20bf03452a06b7d01356367c9a605 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Mon, 13 Nov 2017 14:51:54 +0100 Subject: [PATCH] [FIX] web: hide binary file download when new record Let's have: - on res.company a binary file field named x_file - on res.users a related binary field to company_id.x_file, and make it readonly On the res.users form view, display the new field Before this commit in create mode, upon clicking on download the file, the server crashed, because the record id was empty. Then, the JS crashed in turn because of the unhandled 404 from the server. Since the id of a new record will always be unset, we choose to disable the download event in this very specific case OPW 777042 --- addons/web/static/src/js/views/form_widgets.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/views/form_widgets.js b/addons/web/static/src/js/views/form_widgets.js index 26bebd98c0d..a074c094de8 100644 --- a/addons/web/static/src/js/views/form_widgets.js +++ b/addons/web/static/src/js/views/form_widgets.js @@ -1177,7 +1177,7 @@ var FieldBinaryFile = FieldBinary.extend({ this._super(); if (this.get("effective_readonly")) { this.$el.click(function(ev) { - if (self.get('value')) { + if (self.get('value') && self.view.datarecord.id) { self.on_save_as(ev); } return false; @@ -1195,6 +1195,11 @@ var FieldBinaryFile = FieldBinary.extend({ this.do_toggle(!!this.get('value')); if (this.get('value')) { this.$el.empty().append($("").addClass('fa fa-download')); + if (this.view.datarecord.id) { + this.$el.css('cursor', 'pointer'); + } else { + this.$el.css('cursor', 'not-allowed'); + } if (filename) { this.$el.append(" " + filename); }