summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/core/utils.js
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2018-01-12 19:13:10 +0100
committerChristophe Simonis <chs@odoo.com>2018-01-12 19:13:10 +0100
commit03a36a9bbadbf874837ff85692a1d8f1c13cc36d (patch)
treeb50823afe76b8300faf02962bcd265fb3a8b3e60 /addons/web/static/src/js/core/utils.js
parent2304edd46cc12aaef4fddaa22887ff51f51581bc (diff)
parent56974322f8c67ec5680654ed4bcb08ca57117c46 (diff)
[MERGE] forward port branch saas-11.1 up to 56974322f8c
Diffstat (limited to 'addons/web/static/src/js/core/utils.js')
-rw-r--r--addons/web/static/src/js/core/utils.js18
1 files changed, 17 insertions, 1 deletions
diff --git a/addons/web/static/src/js/core/utils.js b/addons/web/static/src/js/core/utils.js
index 99534708a94..1bdd9e70a69 100644
--- a/addons/web/static/src/js/core/utils.js
+++ b/addons/web/static/src/js/core/utils.js
@@ -24,6 +24,22 @@ var utils = {
}
},
/**
+ * Check 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
+ * @return {string} bin_size (human-readable)
+ */
+ binaryToBinsize: function (value) {
+ if (!this.is_bin_size(value)) {
+ // Computing approximate size out of base64 encoded string
+ // http://en.wikipedia.org/wiki/Base64#MIME
+ return this.human_size(value.length / 1.37);
+ }
+ // already bin_size
+ return value;
+ },
+ /**
* Confines a value inside an interval
*
* @param {number} [val] the value to confine
@@ -132,7 +148,7 @@ var utils = {
size /= 1024;
++i;
}
- return size.toFixed(2) + ' ' + units[i];
+ return size.toFixed(2) + ' ' + units[i].trim();
},
/**
* Insert "thousands" separators in the provided number (which is actually