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