Browse Source

publish muk_web_utils - 12.0

pull/48/head
MuK IT GmbH 6 years ago
parent
commit
f770116070
  1. 2
      muk_web_utils/__manifest__.py
  2. 29
      muk_web_utils/static/src/js/fields/binary.js

2
muk_web_utils/__manifest__.py

@ -20,7 +20,7 @@
{ {
"name": "MuK Web Utils", "name": "MuK Web Utils",
"summary": """Utility Features""", "summary": """Utility Features""",
"version": "12.0.2.8.1",
"version": "12.0.2.8.2",
"category": "Extra Tools", "category": "Extra Tools",
"license": "AGPL-3", "license": "AGPL-3",
"author": "MuK IT", "author": "MuK IT",

29
muk_web_utils/static/src/js/fields/binary.js

@ -22,7 +22,9 @@ odoo.define('muk_web_utils.binary', function(require) {
var core = require('web.core'); var core = require('web.core');
var session = require('web.session'); var session = require('web.session');
var utils = require('web.field_utils');
var fields = require('web.basic_fields'); var fields = require('web.basic_fields');
var registry = require('web.field_registry');
var _t = core._t; var _t = core._t;
var QWeb = core.qweb; var QWeb = core.qweb;
@ -49,4 +51,31 @@ fields.FieldBinaryImage.include({
}, },
}); });
var FieldBinarySize = fields.FieldFloat.extend({
init: function(parent, name, record) {
this._super.apply(this, arguments);
this.units = this.nodeOptions.si ?
['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] :
['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
this.thresh = this.nodeOptions.si ? 1000 : 1024;
},
_formatValue: function (value) {
if(Math.abs(value) < this.thresh) {
return this._super.call(this, value) + ' B';
}
var unit = -1;
do {
value /= this.thresh;
++unit;
} while(Math.abs(value) >= this.thresh && unit < this.units.length - 1);
return this._super.call(this, value) + ' ' + this.units[unit];
},
});
registry.add('binary_size', FieldBinarySize);
return {
FieldBinarySize: FieldBinarySize,
};
}); });
Loading…
Cancel
Save