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.

86 lines
2.7 KiB

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