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.9 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_preview.PreviewWidgets', function (require) {
  20. "use strict";
  21. var core = require('web.core');
  22. var utils = require('web.utils');
  23. var Widget = require('web.Widget');
  24. var PreviewHandler = require('muk_preview.PreviewHandler');
  25. var PreviewGenerator = require('muk_preview.PreviewGenerator');
  26. var PreviewDialog = require('muk_preview.PreviewDialog');
  27. var QWeb = core.qweb;
  28. var _t = core._t;
  29. core.form_widget_registry.get("binary").include({
  30. initialize_content: function() {
  31. var self = this;
  32. this._super();
  33. if (this.get("effective_readonly")) {
  34. this.$('.o_binary_preview').click(function(e) {
  35. e.stopPropagation();
  36. var value = self.get('value');
  37. var filename_fieldname = self.node.attrs.filename;
  38. var filename_field = self.view.fields && self.view.fields[filename_fieldname];
  39. var filename = filename_field ? filename_field.get('value') : null;
  40. PreviewDialog.createPreviewDialog(self, '/web/content?' + $.param({
  41. 'model': self.view.dataset.model,
  42. 'id': self.view.datarecord.id,
  43. 'field': self.name,
  44. 'filename_field': filename_fieldname,
  45. 'filename': filename,
  46. 'download': true,
  47. 'data': utils.is_bin_size(value) ? null : value,
  48. }), false, filename.split('.').pop(), filename);
  49. });
  50. }
  51. },
  52. render_value: function() {
  53. var filename = this.view.datarecord[this.node.attrs.filename];
  54. if (this.get("effective_readonly")) {
  55. this.do_toggle(!!this.get('value'));
  56. if (this.get('value')) {
  57. var $link = this.$el.find('a')
  58. $link.empty().append($("<span/>").addClass('fa fa-download'));
  59. if (filename) {
  60. $link.append(" " + filename);
  61. } else {
  62. $link.append(" " + _t("Download"));
  63. }
  64. }
  65. } else {
  66. this._super();
  67. }
  68. }
  69. });
  70. });