[FIX] Listview does not handle base64 value for binary fields
lp bug: https://launchpad.net/bugs/1077858 fixed bzr revid: fme@openerp.com-20121112171128-a1aoq2q4fma6fpxc
This commit is contained in:
parent
c74e620701
commit
cd4c3c61ff
|
@ -83,6 +83,42 @@ instance.web.strip_raw_chars = function (value) {
|
|||
var normalize_format = function (format) {
|
||||
return Date.normalizeFormat(instance.web.strip_raw_chars(format));
|
||||
};
|
||||
|
||||
/**
|
||||
* Check with a scary heuristic if the value is a bin_size or not.
|
||||
* If not, compute an approximate size out of the base64 encoded string.
|
||||
*
|
||||
* @param {String} value original format
|
||||
*/
|
||||
instance.web.binary_to_binsize = function (value) {
|
||||
if (!value) {
|
||||
return instance.web.human_size(0);
|
||||
}
|
||||
if (value.substr(0, 10).indexOf(' ') == -1) {
|
||||
// Computing approximate size out of base64 encoded string
|
||||
// http://en.wikipedia.org/wiki/Base64#MIME
|
||||
return instance.web.human_size(value.length / 1.37);
|
||||
} else {
|
||||
// already bin_size
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a human readable size
|
||||
*
|
||||
* @param {Number} numner of bytes
|
||||
*/
|
||||
instance.web.human_size = function(size) {
|
||||
var units = _t("Bytes,Kb,Mb,Gb,Tb,Pb,Eb,Zb,Yb").split(',');
|
||||
var i = 0;
|
||||
while (size >= 1024) {
|
||||
size /= 1024;
|
||||
++i;
|
||||
}
|
||||
return size.toFixed(2) + ' ' + units[i];
|
||||
};
|
||||
|
||||
/**
|
||||
* Formats a single atomic value based on a field descriptor
|
||||
*
|
||||
|
|
|
@ -4790,15 +4790,6 @@ instance.web.form.FieldBinary = instance.web.form.AbstractField.extend(instance.
|
|||
this.$el.find('button.oe_form_binary_file_save').click(this.on_save_as);
|
||||
this.$el.find('.oe_form_binary_file_clear').click(this.on_clear);
|
||||
},
|
||||
human_filesize : function(size) {
|
||||
var units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
||||
var i = 0;
|
||||
while (size >= 1024) {
|
||||
size /= 1024;
|
||||
++i;
|
||||
}
|
||||
return size.toFixed(2) + ' ' + units[i];
|
||||
},
|
||||
on_file_change: function(e) {
|
||||
var self = this;
|
||||
var file_node = e.target;
|
||||
|
@ -4915,7 +4906,7 @@ instance.web.form.FieldBinaryFile = instance.web.form.FieldBinary.extend({
|
|||
on_file_uploaded_and_valid: function(size, name, content_type, file_base64) {
|
||||
this.binary_value = true;
|
||||
this.internal_set_value(file_base64);
|
||||
var show_value = name + " (" + this.human_filesize(size) + ")";
|
||||
var show_value = name + " (" + instance.web.human_size(size) + ")";
|
||||
this.$el.find('input').eq(0).val(show_value);
|
||||
this.set_filename(name);
|
||||
},
|
||||
|
|
|
@ -2176,7 +2176,7 @@ instance.web.list.Binary = instance.web.list.Column.extend({
|
|||
return _.template('<a href="<%-href%>"><%-text%></a> (<%-size%>)', {
|
||||
text: text,
|
||||
href: download_url,
|
||||
size: row_data[this.id].value
|
||||
size: instance.web.binary_to_binsize(row_data[this.id].value),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue