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.

66 lines
2.3 KiB

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.PreviewGenerator', function (require) {
  20. "use strict";
  21. var core = require('web.core');
  22. var PreviewHandler = require('muk_preview.PreviewHandler');
  23. var QWeb = core.qweb;
  24. var _t = core._t;
  25. var PreviewGenerator = core.Class.extend({
  26. handler: {},
  27. init: function(widget, additional_handler) {
  28. this.widget = widget;
  29. this.handler = _.extend(this.handler, {
  30. "PDFHandler": new PreviewHandler.PDFHandler(widget),
  31. "OpenOfficeHandler": new PreviewHandler.OpenOfficeHandler(widget)
  32. });
  33. this.handler = _.extend(this.handler, additional_handler);
  34. },
  35. createPreview: function(url, mimetype, extension, title) {
  36. var matchedHandler = false;
  37. _.each(this.handler, function(handler, key, handler_list) {
  38. if(handler.checkExtension(extension) || handler.checkType(mimetype)) {
  39. matchedHandler = handler;
  40. }
  41. });
  42. if(matchedHandler) {
  43. return matchedHandler.createHtml(url, mimetype, extension, title);
  44. } else {
  45. var $content = $.Deferred();
  46. $content.resolve($(QWeb.render('UnsupportedContent', {
  47. url: url, mimetype: mimetype || _t('Unknown'),
  48. extension: extension || _t('Unknown'),
  49. title: title || _t('Unknown')
  50. })));
  51. return $content;
  52. }
  53. }
  54. });
  55. PreviewGenerator.createPreview = function(widget, url, mimetype, extension, title) {
  56. return new PreviewGenerator(widget, {}).createPreview(url, mimetype, extension, title);
  57. };
  58. return PreviewGenerator;
  59. });