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.

71 lines
2.9 KiB

  1. /**********************************************************************************
  2. *
  3. * Copyright (C) 2018 MuK IT GmbH
  4. *
  5. * Odoo Proprietary License v1.0
  6. * This software and associated files (the "Software") may only be used
  7. * (executed, modified, executed after modifications) if you have
  8. * purchased a valid license from the authors, typically via Odoo Apps,
  9. * or if you have received a written agreement from the authors of the
  10. * Software (see the COPYRIGHT file).
  11. *
  12. * You may develop Odoo modules that use the Software as a library
  13. * (typically by depending on it, importing it and using its resources),
  14. * but without copying any source code or material from the Software.
  15. * You may distribute those modules under the license of your choice,
  16. * provided that this license is compatible with the terms of the Odoo
  17. * Proprietary License (For example: LGPL, MIT, or proprietary licenses
  18. * similar to this one).
  19. *
  20. * It is forbidden to publish, distribute, sublicense, or sell copies of
  21. * the Software or modified copies of the Software.
  22. *
  23. * The above copyright notice and this permission notice must be included
  24. * in all copies or substantial portions of the Software.
  25. *
  26. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  27. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  28. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  29. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  30. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  31. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  32. * DEALINGS IN THE SOFTWARE.
  33. *
  34. **********************************************************************************/
  35. odoo.define('muk_web_utils.image', function (require) {
  36. "use strict";
  37. var core = require('web.core');
  38. var session = require('web.session');
  39. var fields = require('web.basic_fields');
  40. var _t = core._t;
  41. var QWeb = core.qweb;
  42. fields.FieldBinaryImage.include({
  43. willStart: function () {
  44. var def = this._rpc({
  45. route: '/params/muk_web_utils.binary_max_size',
  46. }).done(function(result) {
  47. this.max_upload_size = result.max_upload_size * 1024 * 1024;
  48. }.bind(this));
  49. return $.when(this._super.apply(this, arguments), def);
  50. },
  51. _render: function () {
  52. this._super.apply(this, arguments);
  53. this.$('.mk_field_image_wrapper').remove();
  54. this.$('img').wrap($('<div/>', {
  55. class: "mk_field_image_wrapper"
  56. }));
  57. var $wrapper = $('.mk_field_image_wrapper');
  58. var width = this.nodeOptions.size ?
  59. this.nodeOptions.size[0] : this.attrs.width;
  60. var height = this.nodeOptions.size ?
  61. this.nodeOptions.size[1] : this.attrs.height;
  62. $wrapper.css('min-width', (width || 50) + 'px');
  63. $wrapper.css('min-height', (height || 50) + 'px');
  64. },
  65. });
  66. });