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.

88 lines
2.7 KiB

7 years ago
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_vector.PreviewHandler', function (require) {
  20. "use strict";
  21. var ajax = require('web.ajax');
  22. var core = require('web.core');
  23. var PreviewHandler = require('muk_preview.PreviewHandler');
  24. var QWeb = core.qweb;
  25. var _t = core._t;
  26. var VectorHandler = PreviewHandler.BaseHandler.extend({
  27. cssLibs: [
  28. ],
  29. jsLibs: [
  30. '/muk_web_preview_vector/static/lib/svg-pan-zoom/svg-pan-zoom.js',
  31. ],
  32. checkExtension: function(extension) {
  33. return ['.svg', 'svg'].includes(extension);
  34. },
  35. checkType: function(mimetype) {
  36. return ['image/svg+xml'].includes(mimetype);
  37. },
  38. createHtml: function(url, mimetype, extension, title) {
  39. var result = $.Deferred();
  40. var $content = $(QWeb.render('VectorHTMLContent', {url: url}));
  41. ajax.loadLibs(this).then(function() {
  42. $.ajax(url, {
  43. dataType: "text",
  44. success: function(vector) {
  45. $content.find('.vector-loader').hide();
  46. $content.find('.vector-container').show();
  47. $content.find('.vector-content').html(vector);
  48. var svgPanZoom = $("svg").svgPanZoom({
  49. events: {
  50. mouseWheel: true,
  51. doubleClick: true,
  52. drag: true,
  53. dragCursor: "move",
  54. },
  55. animationTime: 300,
  56. zoomFactor: 0.1,
  57. maxZoom: 5,
  58. panFactor: 100,
  59. });
  60. $content.find('.zoom-plus').click(function(){
  61. svgPanZoom.zoomIn()
  62. });
  63. $content.find('.zoom-minus').click(function(){
  64. svgPanZoom.zoomOut()
  65. });
  66. $content.find('.zoom-reset').click(function(){
  67. svgPanZoom.reset()
  68. });
  69. },
  70. error: function(request, status, error) {
  71. console.error(request.responseText);
  72. }
  73. });
  74. });
  75. result.resolve($content);
  76. return result;
  77. },
  78. });
  79. return {
  80. VectorHandler: VectorHandler,
  81. }
  82. });