[FIX] Roundtrips binary field value if not bin size
authorFabien Meghazi <fme@openerp.com>
Tue, 11 Dec 2012 10:33:57 +0000 (11:33 +0100)
committerFabien Meghazi <fme@openerp.com>
Tue, 11 Dec 2012 10:33:57 +0000 (11:33 +0100)
lp bug: https://launchpad.net/bugs/1082616 fixed

bzr revid: fme@openerp.com-20121211103357-csqirmhxehmszyu4

addons/web/controllers/main.py
addons/web/static/src/js/view_form.js
addons/web_kanban/static/src/js/kanban.js

index 6a26e7d..93e5260 100644 (file)
@@ -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)
index 7420403..7d5585b 100644 (file)
@@ -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);
index be8a1f5..982c27c 100644 (file)
@@ -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";