summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabien Meghazi <fme@openerp.com>2012-12-11 11:33:57 +0100
committerFabien Meghazi <fme@openerp.com>2012-12-11 11:33:57 +0100
commitc124fc3281ff92df60eb82ddb3ba617a48e48fba (patch)
tree6a52a03d4fe6832afaaf8bacdc477b36de8d3be8
parente616a9aa149c6d67ee4b2febb891438929607dfe (diff)
[FIX] Roundtrips binary field value if not bin size
lp bug: https://launchpad.net/bugs/1082616 fixed bzr revid: fme@openerp.com-20121211103357-csqirmhxehmszyu4
-rw-r--r--addons/web/controllers/main.py5
-rw-r--r--addons/web/static/src/js/view_form.js12
-rw-r--r--addons/web_kanban/static/src/js/kanban.js2
3 files changed, 11 insertions, 8 deletions
diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py
index 6a26e7dd422..93e526093f1 100644
--- a/addons/web/controllers/main.py
+++ b/addons/web/controllers/main.py
@@ -1246,6 +1246,7 @@ class Binary(openerpweb.Controller):
jdata = simplejson.loads(data)
model = jdata['model']
field = jdata['field']
+ data = jdata['data']
id = jdata.get('id', None)
filename_field = jdata.get('filename_field', None)
context = jdata.get('context', {})
@@ -1254,7 +1255,9 @@ class Binary(openerpweb.Controller):
fields = [field]
if filename_field:
fields.append(filename_field)
- if id:
+ if data:
+ res = { field: data }
+ elif id:
res = Model.read([int(id)], fields, context)[0]
else:
res = Model.default_get(fields, context)
diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js
index 74204034c7a..7d5585b01df 100644
--- a/addons/web/static/src/js/view_form.js
+++ b/addons/web/static/src/js/view_form.js
@@ -1694,6 +1694,10 @@ instance.web.form.compute_domain = function(expr, fields) {
return _.all(stack, _.identity);
};
+instance.web.form.is_bin_size = function(v) {
+ return /^\d+(\.\d*)? \w+$/.test(v);
+};
+
/**
* Must be applied over an class already possessing the PropertiesMixin.
*
@@ -4867,11 +4871,6 @@ instance.web.form.FieldBinary = instance.web.form.AbstractField.extend(instance.
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_form_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 {
instance.web.blockUI();
var c = instance.webclient.crashmanager;
@@ -4882,6 +4881,7 @@ instance.web.form.FieldBinary = instance.web.form.AbstractField.extend(instance.
id: (this.view.datarecord.id || ''),
field: this.name,
filename_field: (this.node.attrs.filename || ''),
+ data: instance.web.form.is_bin_size(value) ? null : value,
context: this.view.dataset.get_context()
})},
complete: instance.web.unblockUI,
@@ -4961,7 +4961,7 @@ instance.web.form.FieldBinaryImage = instance.web.form.FieldBinary.extend({
render_value: function() {
var self = this;
var url;
- if (this.get('value') && ! /^\d+(\.\d*)? \w+$/.test(this.get('value'))) {
+ if (this.get('value') && !instance.web.form.is_bin_size(this.get('value'))) {
url = 'data:image/png;base64,' + this.get('value');
} else if (this.get('value')) {
var id = JSON.stringify(this.view.datarecord.id || null);
diff --git a/addons/web_kanban/static/src/js/kanban.js b/addons/web_kanban/static/src/js/kanban.js
index be8a1f5c519..982c27c03fc 100644
--- a/addons/web_kanban/static/src/js/kanban.js
+++ b/addons/web_kanban/static/src/js/kanban.js
@@ -988,7 +988,7 @@ instance.web_kanban.KanbanRecord = instance.web.Widget.extend({
kanban_image: function(model, field, id, cache, options) {
options = options || {};
var url;
- if (this.record[field] && this.record[field].value && ! /^\d+(\.\d*)? \w+$/.test(this.record[field].value)) {
+ if (this.record[field] && this.record[field].value && !instance.web.form.is_bin_size(this.record[field].value)) {
url = 'data:image/png;base64,' + this.record[field].value;
} else if (this.record[field] && ! this.record[field].value) {
url = "/web/static/src/img/placeholder.png";