[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
This commit is contained in:
Lucas Perais (lpe)
2017-12-04 13:20:18 +01:00
parent 7b808982a0
commit 8b875e4dd4
@@ -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($("<span/>").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);
}