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.

80 lines
2.7 KiB

7 years ago
7 years ago
7 years ago
7 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_preview.PreviewHandler', function (require) {
  20. "use strict";
  21. var core = require('web.core');
  22. var QWeb = core.qweb;
  23. var _t = core._t;
  24. var BaseHandler = core.Class.extend({
  25. init: function(widget) {
  26. this.widget = widget;
  27. },
  28. checkExtension: function(extension) {
  29. return false;
  30. },
  31. checkType: function(mimetype) {
  32. return false;
  33. },
  34. createHtml: function(url, mimetype, extension, title) {
  35. return $.when();
  36. },
  37. });
  38. var PDFHandler = BaseHandler.extend({
  39. checkExtension: function(extension) {
  40. return ['.pdf', 'pdf'].includes(extension);
  41. },
  42. checkType: function(mimetype) {
  43. return ['application/pdf'].includes(mimetype);
  44. },
  45. createHtml: function(url, mimetype, extension, title) {
  46. var result = $.Deferred();
  47. var viewerUrlTempalte = _.template('/muk_web_preview/static/lib/PDFjs/web/viewer.html?file=<%= url %>');
  48. result.resolve($(QWeb.render('ViewerJSFrame', {url: viewerUrlTempalte({url})})));
  49. return result;
  50. },
  51. });
  52. var OpenOfficeHandler = BaseHandler.extend({
  53. checkExtension: function(extension) {
  54. return ['.odt', '.odp', '.ods', '.fodt', '.ott', '.fodp', '.otp', '.fods', '.ots',
  55. 'odt', 'odp', 'ods', 'fodt', 'ott', 'fodp', 'otp', 'fods', 'ots'].includes(extension);
  56. },
  57. checkType: function(mimetype) {
  58. return ['application/vnd.oasis.opendocument.text', 'application/vnd.oasis.opendocument.presentation',
  59. 'application/vnd.oasis.opendocument.spreadsheet'].includes(mimetype);
  60. },
  61. createHtml: function(url, mimetype, extension, title) {
  62. var result = $.Deferred();
  63. var viewerUrlTempalte = _.template('/muk_web_preview/static/lib/ViewerJS/index.html#<%= url %>');
  64. result.resolve($(QWeb.render('ViewerJSFrame', {url: viewerUrlTempalte({url})})));
  65. return result;
  66. },
  67. });
  68. return {
  69. BaseHandler: BaseHandler,
  70. PDFHandler: PDFHandler,
  71. OpenOfficeHandler: OpenOfficeHandler,
  72. }
  73. });