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.

93 lines
3.1 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  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_export_attachment.SidebarPreview', function (require) {
  20. "use strict";
  21. var core = require('web.core');
  22. var session = require('web.session');
  23. var Sidebar = require('web.Sidebar');
  24. var QWeb = core.qweb;
  25. var _t = core._t;
  26. Sidebar.include({
  27. willStart: function() {
  28. var self = this;
  29. var export_action = this._rpc({
  30. route: '/web/attachment/export_action',
  31. }).then(function (result) {
  32. console.log(result);
  33. self.export_action = result;
  34. });
  35. var export_formats = this._rpc({
  36. route: '/web/export_formats',
  37. }).then(function (result) {
  38. self.export_formats = result;
  39. });
  40. return this._super.apply(this, arguments);
  41. },
  42. _processAttachments: function(attachments) {
  43. var self = this;
  44. var res = this._super.apply(this, arguments);
  45. var exportable = false;
  46. _.each(this.items.files ,function (attachment) {
  47. if(self.export_formats.includes((/(?:\.([^.]+))?$/).exec(attachment.name)[1])) {
  48. attachment.exportable = 'exportable';
  49. exportable = true;
  50. } else {
  51. attachment.exportable = 'unexportable';
  52. }
  53. });
  54. if(!exportable) {
  55. _.each(this.items.files ,function (attachment) {
  56. attachment.exportable = 'nothing-exportable';
  57. });
  58. }
  59. return res;
  60. },
  61. _redraw: function () {
  62. this._super.apply(this, arguments);
  63. this.$el.find('.o_sidebar_export_attachment')
  64. .click(this._on_attachment_export.bind(this));
  65. },
  66. _on_attachment_export: function(e) {
  67. var self = this;
  68. var $target = $(e.currentTarget);
  69. this.do_action({
  70. 'type': 'ir.actions.act_window',
  71. 'res_model': "muk_converter.convert",
  72. 'name': _t('Convert File'),
  73. 'views': [[self.export_action, 'form']],
  74. 'view_type': 'form',
  75. 'view_mode': 'form',
  76. 'target': 'new',
  77. 'context': {
  78. 'default_res_id': self.env.activeIds[0],
  79. 'default_res_model': self.env.model,
  80. 'default_type': "url",
  81. 'default_input_url': $target.data("url"),
  82. 'default_input_name': $target.data("name"),
  83. },
  84. });
  85. e.preventDefault();
  86. e.stopPropagation();
  87. }
  88. });
  89. });