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.

42 lines
1.4 KiB

  1. /* Copyright 2016 Flavio Corpa <flavio.corpa@tecnativa.com>
  2. * Copyright 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
  3. * License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). */
  4. odoo.define('web_widget_image_download.widget', function (require) {
  5. 'use strict';
  6. var core = require('web.core');
  7. var $ = require('$');
  8. core.form_widget_registry.get("image").include({
  9. render_value: function () {
  10. this._super();
  11. var $widget = this.$el.find('.oe_form_binary_file_download');
  12. this.imgSrc = this.$el.find('img[name="' + this.name + '"]')
  13. .attr('src');
  14. $.ajax({
  15. type: 'HEAD', // Avoid downloading full image, just headers
  16. url: this.imgSrc,
  17. complete: function (xhr) {
  18. $widget.attr(
  19. 'download',
  20. xhr.getResponseHeader("Content-Type")
  21. .replace('/', '.')
  22. );
  23. }
  24. });
  25. // Replace with jQuery to keep inheritance intact
  26. if (this.has_custom_image()) {
  27. this.$el.find('.oe_form_binary_file_clear')
  28. .removeClass('col-md-offset-5');
  29. }
  30. $widget.attr('href', this.imgSrc);
  31. },
  32. has_custom_image: function () {
  33. return this.imgSrc != this.placeholder;
  34. },
  35. });
  36. });