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: '/config/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. _renderReadonly: function () {
  38. this._super.apply(this, arguments);
  39. var $wrapper = $('<div/>', {
  40. class: "mk_field_binary_wrapper"
  41. });
  42. $wrapper.addClass(this.$el.attr('class'));
  43. this.$el.removeClass("o_field_widget");
  44. this.$el.removeClass("o_hidden");
  45. $wrapper.append(this.$el);
  46. this.setElement($wrapper);
  47. },
  48. });
  49. var FieldBinarySize = fields.FieldFloat.extend({
  50. init: function(parent, name, record) {
  51. this._super.apply(this, arguments);
  52. this.nodeOptions = _.defaults(this.nodeOptions, {
  53. si: true,
  54. });
  55. },
  56. _formatValue: function (value) {
  57. var options = _.extend({},
  58. this.nodeOptions,
  59. { data: this.recordData },
  60. this.formatOptions,
  61. );
  62. return utils.format['binary_size'](value, this.field, options)
  63. },
  64. });
  65. registry.add('binary_size', FieldBinarySize);
  66. return {
  67. FieldBinarySize: FieldBinarySize,
  68. };
  69. });