You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.4 KiB

  1. /**********************************************************************************
  2. *
  3. * Copyright (C) 2017 MuK IT GmbH
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. **********************************************************************************/
  19. odoo.define('muk_web_utils.binary', function(require) {
  20. "use strict";
  21. var core = require('web.core');
  22. var session = require('web.session');
  23. var utils = require('web.field_utils');
  24. var fields = require('web.basic_fields');
  25. var registry = require('web.field_registry');
  26. var _t = core._t;
  27. var QWeb = core.qweb;
  28. fields.FieldBinaryFile.include({
  29. willStart: function () {
  30. var def = this._rpc({
  31. route: '/params/muk_web_utils.binary_max_size',
  32. }).done(function(result) {
  33. this.max_upload_size = result.max_upload_size * 1024 * 1024;
  34. }.bind(this));
  35. return this._super.apply(this, arguments);
  36. },
  37. });
  38. fields.FieldBinaryImage.include({
  39. willStart: function () {
  40. var def = this._rpc({
  41. route: '/params/muk_web_utils.binary_max_size',
  42. }).done(function(result) {
  43. this.max_upload_size = result.max_upload_size * 1024 * 1024;
  44. }.bind(this));
  45. return this._super.apply(this, arguments);
  46. },
  47. });
  48. var FieldBinarySize = fields.FieldFloat.extend({
  49. init: function(parent, name, record) {
  50. this._super.apply(this, arguments);
  51. this.nodeOptions = _.defaults(this.nodeOptions, {
  52. si: true,
  53. });
  54. },
  55. _formatValue: function (value) {
  56. var options = _.extend({},
  57. this.nodeOptions,
  58. { data: this.recordData },
  59. this.formatOptions,
  60. );
  61. return utils.format['binary_size'](value, this.field, options)
  62. },
  63. });
  64. registry.add('binary_size', FieldBinarySize);
  65. return {
  66. FieldBinarySize: FieldBinarySize,
  67. };
  68. });