[FIX] Saving a binary field not saved yet crashes

lp bug: https://launchpad.net/bugs/1010475 fixed

bzr revid: fme@openerp.com-20120614150010-ik6f3rqk8li314aq
This commit is contained in:
Fabien Meghazi 2012-06-14 17:00:10 +02:00
parent 8c01d7ba59
commit edcf216d33
2 changed files with 37 additions and 19 deletions

View File

@ -3986,7 +3986,7 @@ instance.web.form.FieldBinary = instance.web.form.AbstractField.extend(_.extend(
},
initialize_content: function() {
this.$element.find('input.oe-binary-file').change(this.on_file_change);
this.$element.find('button.oe-binary-file-save').click(this.on_save_as);
this.$element.find('button.oe_binary_file_save').click(this.on_save_as);
this.$element.find('.oe-binary-file-clear').click(this.on_clear);
},
human_filesize : function(size) {
@ -4016,6 +4016,7 @@ instance.web.form.FieldBinary = instance.web.form.AbstractField.extend(_.extend(
// TODO: use openerp web crashmanager
console.warn("Error while uploading file : ", name);
} else {
this.filename = name;
this.on_file_uploaded_and_valid.apply(this, arguments);
}
this.$element.find('.oe-binary-progress').hide();
@ -4023,20 +4024,33 @@ instance.web.form.FieldBinary = instance.web.form.AbstractField.extend(_.extend(
},
on_file_uploaded_and_valid: function(size, name, content_type, file_base64) {
},
on_save_as: function() {
$.blockUI();
this.session.get_file({
url: '/web/binary/saveas_ajax',
data: {data: JSON.stringify({
model: this.view.dataset.model,
id: (this.view.datarecord.id || ''),
field: this.name,
filename_field: (this.node.attrs.filename || ''),
context: this.view.dataset.get_context()
})},
complete: $.unblockUI,
error: instance.webclient.crashmanager.on_rpc_error
});
on_save_as: function(ev) {
var value = this.get('value');
if (!value) {
this.do_warn(_t("Save As..."), _t("The field is empty, there's nothing to save !"));
ev.stopPropagation();
} else if (this._dirty_flag) {
var link = this.$('.oe_binary_file_save_data')[0];
link.download = this.filename || "download.bin"; // Works on only on Google Chrome
//link.target = '_blank';
link.href = "data:application/octet-stream;base64," + value;
} else {
$.blockUI();
this.session.get_file({
url: '/web/binary/saveas_ajax',
data: {data: JSON.stringify({
model: this.view.dataset.model,
id: (this.view.datarecord.id || ''),
field: this.name,
filename_field: (this.node.attrs.filename || ''),
context: this.view.dataset.get_context()
})},
complete: $.unblockUI,
error: instance.webclient.crashmanager.on_rpc_error
});
ev.stopPropagation();
return false;
}
},
on_clear: function() {
if (this.get('value') !== false) {
@ -4088,6 +4102,7 @@ instance.web.form.FieldBinaryFile = instance.web.form.FieldBinary.extend({
var show_value = name + " (" + this.human_filesize(size) + ")";
this.$element.find('input').eq(0).val(show_value);
this.set_filename(name);
this.trigger('changed_value');
},
set_filename: function(value_) {
var filename = this.node.attrs.filename;
@ -4130,6 +4145,7 @@ instance.web.form.FieldBinaryImage = instance.web.form.FieldBinary.extend({
this.set({'value': file_base64});
this.binary_value = true;
this.render_value();
this.trigger('changed_value');
},
on_clear: function() {
this._super.apply(this, arguments);

View File

@ -1074,10 +1074,12 @@
</t>
</td>
<td>
<button class="oe_button oe-binary-file-save" type="button" title="Save As">
<img t-att-src='_s + "/web/static/src/img/icons/gtk-save.png"'/>
<span>Save As</span>
</button>
<a class="oe_binary_file_save_data">
<button class="oe_button oe_binary_file_save" type="button" title="Save As">
<img t-att-src='_s + "/web/static/src/img/icons/gtk-save.png"'/>
<span>Save As</span>
</button>
</a>
</td>
<td>
<button class="oe_button oe-binary-file-clear" type="button" title="Clear">