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.

126 lines
3.9 KiB

7 years ago
7 years ago
7 years ago
  1. ===========
  2. MuK Preview
  3. ===========
  4. MuK Preview enables support to preview binary files directly in Odoo. It adds a
  5. button to the binary field, which opens a file preview dialog. The preview can
  6. be easily extended by adding new Handlers to the Preview Generator.
  7. Installation
  8. ============
  9. To install this module, you need to:
  10. Download the module and add it to your Odoo addons folder. Afterward, log on to
  11. your Odoo server and go to the Apps menu. Trigger the debug modus and update the
  12. list by clicking on the "Update Apps List" link. Now install the module by
  13. clicking on the install button.
  14. Configuration
  15. =============
  16. No additional configuration is needed to use this module.
  17. Usage
  18. =============
  19. To each Binary Field Widget a button is added, which opens the Preview Dialog.
  20. Framework
  21. =============
  22. To extend the preview a new "PreviewHandler" has to be created and subsequently added to the "PreviewGenerator".
  23. The following steps show the implementation of the image preview.
  24. PreviewHandler
  25. --------------
  26. .. code-block:: javascript
  27. odoo.define('muk_preview_image.PreviewHandler', function (require) {
  28. "use strict";
  29. var core = require('web.core');
  30. var PreviewHandler = require('muk_preview.PreviewHandler');
  31. var QWeb = core.qweb;
  32. var _t = core._t;
  33. var ImageHandler = PreviewHandler.BaseHandler.extend({
  34. checkExtension: function(extension) {
  35. return ['.cod', '.ras', '.fif', '.gif', '.ief', '.jpeg', '.jpg', '.jpe', '.png', '.tiff',
  36. '.tif', '.mcf', '.wbmp', '.fh4', '.fh5', '.fhc', '.ico', '.pnm', '.pbm', '.pgm',
  37. '.ppm', '.rgb', '.xwd', '.xbm', '.xpm', 'cod', 'ras', 'fif', 'gif', 'ief', 'jpeg',
  38. 'jpg', 'jpe', 'png', 'tiff', '.tif', 'mcf', 'wbmp', 'fh4', 'fh5', 'fhc', 'ico',
  39. 'pnm', 'pbm', 'pgm', '.ppm', 'rgb', 'xwd', 'xbm', 'xpm'].includes(extension);
  40. },
  41. checkType: function(mimetype) {
  42. return ['image/cis-cod', 'image/cmu-raster', 'image/fif', 'image/gif', 'image/ief', 'image/jpeg',
  43. 'image/png', 'image/tiff', 'image/vasa', 'image/vnd.wap.wbmp', 'image/x-freehand', 'image/x-icon',
  44. 'image/x-portable-anymap', 'image/x-portable-bitmap', 'image/x-portable-graymap', 'image/x-portable-pixmap',
  45. 'image/x-rgb', 'image/x-windowdump', 'image/x-xbitmap', 'image/x-xpixmap'].includes(mimetype);
  46. },
  47. createHtml: function(url, mimetype, extension, title) {
  48. var result = $.Deferred();
  49. var $content = $(QWeb.render('ImageHTMLContent', {url: url, alt: title}));
  50. $content.find('img').click(function (e) {
  51. ImageViewer().show(this.src, this.src);
  52. });
  53. result.resolve($content);
  54. return $.when(result);
  55. },
  56. });
  57. return {
  58. ImageHandler: ImageHandler,
  59. }
  60. });
  61. PreviewGenerator
  62. ----------------
  63. .. code-block:: javascript
  64. odoo.define('muk_preview_image.PreviewGenerator', function (require) {
  65. "use strict";
  66. var core = require('web.core');
  67. var PreviewGenerator = require('muk_preview.PreviewGenerator');
  68. var PreviewHandler = require('muk_preview_image.PreviewHandler');
  69. var QWeb = core.qweb;
  70. var _t = core._t;
  71. PreviewGenerator.include({
  72. init: function(widget, additional_handler) {
  73. this._super(widget, additional_handler);
  74. this.handler = _.extend(this.handler, {
  75. "ImageHandler": new PreviewHandler.ImageHandler(widget),
  76. });
  77. },
  78. });
  79. });
  80. Credits
  81. =======
  82. Contributors
  83. ------------
  84. * Mathias Markl <mathias.markl@mukit.at>
  85. Author & Maintainer
  86. -------------------
  87. This module is maintained by the `MuK IT GmbH <https://www.mukit.at/>`_.
  88. MuK IT is an Austrian company specialized in customizing and extending Odoo.
  89. We develop custom solutions for your individual needs to help you focus on
  90. your strength and expertise to grow your business.
  91. If you want to get in touch please contact us via mail
  92. (sale@mukit.at) or visit our website (https://mukit.at).