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.

63 lines
2.5 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_image.PreviewGenerator', function (require) {
  20. "use strict";
  21. var core = require('web.core');
  22. var PreviewHandler = require('muk_preview.PreviewHandler');
  23. var PreviewGenerator = require('muk_preview.PreviewGenerator');
  24. var QWeb = core.qweb;
  25. var _t = core._t;
  26. var ImageHandler = PreviewHandler.extend({
  27. checkExtension: function(extension) {
  28. return ['.cod', '.ras', '.fif', '.gif', '.ief', '.jpeg', '.jpg', '.jpe', '.png', '.tiff',
  29. '.tif', '.mcf', '.wbmp', '.fh4', '.fh5', '.fhc', '.ico', '.pnm', '.pbm', '.pgm',
  30. '.ppm', '.rgb', '.xwd', '.xbm', '.xpm'].includes(extension);
  31. },
  32. checkType: function(mimetype) {
  33. return ['image/cis-cod', 'image/cmu-raster', 'image/fif', 'image/gif', 'image/ief', 'image/jpeg',
  34. 'image/png', 'image/tiff', 'image/vasa', 'image/vnd.wap.wbmp', 'image/x-freehand', 'image/x-icon',
  35. 'image/x-portable-anymap', 'image/x-portable-bitmap', 'image/x-portable-graymap', 'image/x-portable-pixmap',
  36. 'image/x-rgb', 'image/x-windowdump', 'image/x-xbitmap', 'image/x-xpixmap'].includes(mimetype);
  37. },
  38. createHtml: function(url, mimetype, extension, title) {
  39. var result = $.Deferred();
  40. var $content = $(QWeb.render('ImageHTMLContent', {url: url, alt: title}));
  41. $content.find('img').click(function (e) {
  42. ImageViewer().show(this.src, this.src);
  43. });
  44. result.resolve($content);
  45. return $.when(result);
  46. },
  47. });
  48. PreviewGenerator.include({
  49. imageHandler: {
  50. "ImageHandler": new ImageHandler(),
  51. },
  52. init: function(additional_handler) {
  53. additional_handler = _.extend(this.imageHandler, additional_handler);
  54. this._super(additional_handler);
  55. },
  56. });
  57. });