diff --git a/muk_web_preview/__manifest__.py b/muk_web_preview/__manifest__.py index b3080cb..095971d 100644 --- a/muk_web_preview/__manifest__.py +++ b/muk_web_preview/__manifest__.py @@ -29,7 +29,7 @@ - Portable Document Format (.pdf) - Open Document (.odt, .odp, .ods, .otp) """, - "version": "11.0.1.0.5", + "version": "11.0.1.1.0", "category": "Extra Tools", "license": "AGPL-3", "website": "http://www.mukit.at", diff --git a/muk_web_preview/doc/changelog.rst b/muk_web_preview/doc/changelog.rst new file mode 100644 index 0000000..0a9ed4b --- /dev/null +++ b/muk_web_preview/doc/changelog.rst @@ -0,0 +1,10 @@ +`1.1.0` +------- + +- Lazy load javascript + + +`1.0.0` +------- + +- Init version diff --git a/muk_web_preview/i18n/muk_web_preview.pot b/muk_web_preview/i18n/muk_web_preview.pot new file mode 100644 index 0000000..41b0501 --- /dev/null +++ b/muk_web_preview/i18n/muk_web_preview.pot @@ -0,0 +1,94 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * muk_web_preview +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-01-18 23:26+0000\n" +"PO-Revision-Date: 2018-01-18 23:26+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: muk_web_preview +#. openerp-web +#: code:addons/muk_web_preview/static/src/xml/preview_content.xml:69 +#, python-format +msgid "Download" +msgstr "" + +#. module: muk_web_preview +#. openerp-web +#: code:addons/muk_web_preview/static/src/xml/preview_content.xml:62 +#, python-format +msgid "Extension:" +msgstr "" + +#. module: muk_web_preview +#. openerp-web +#: code:addons/muk_web_preview/static/src/xml/preview_content.xml:54 +#, python-format +msgid "Filename:" +msgstr "" + +#. module: muk_web_preview +#. openerp-web +#: code:addons/muk_web_preview/static/src/xml/preview_content.xml:43 +#, python-format +msgid "Odoo App Store" +msgstr "" + +#. module: muk_web_preview +#. openerp-web +#: code:addons/muk_web_preview/static/src/xml/preview_dialog.xml:35 +#, python-format +msgid "Ok" +msgstr "" + +#. module: muk_web_preview +#. openerp-web +#: code:addons/muk_web_preview/static/src/js/preview_dialog.js:44 +#, python-format +msgid "Preview" +msgstr "" + +#. module: muk_web_preview +#. openerp-web +#: code:addons/muk_web_preview/static/src/xml/preview_content.xml:41 +#, python-format +msgid "This file type is currently not supported. By installing further extension via the" +msgstr "" + +#. module: muk_web_preview +#. openerp-web +#: code:addons/muk_web_preview/static/src/xml/preview_content.xml:58 +#, python-format +msgid "Type:" +msgstr "" + +#. module: muk_web_preview +#. openerp-web +#: code:addons/muk_web_preview/static/src/js/preview_generator.js:51 +#, python-format +msgid "Unknown" +msgstr "" + +#. module: muk_web_preview +#. openerp-web +#: code:addons/muk_web_preview/static/src/xml/preview_content.xml:37 +#, python-format +msgid "Unsupported File Extension" +msgstr "" + +#. module: muk_web_preview +#. openerp-web +#: code:addons/muk_web_preview/static/src/xml/preview_content.xml:43 +#, python-format +msgid "it is possible to improve the Preview." +msgstr "" + diff --git a/muk_web_preview/static/src/js/preview_dialog.js b/muk_web_preview/static/src/js/preview_dialog.js index 0d3c9c6..b7458f7 100644 --- a/muk_web_preview/static/src/js/preview_dialog.js +++ b/muk_web_preview/static/src/js/preview_dialog.js @@ -20,8 +20,10 @@ odoo.define('muk_preview.PreviewDialog', function (require) { "use strict"; +var ajax = require('web.ajax'); var core = require('web.core'); var framework = require('web.framework'); + var Widget = require('web.Widget'); var PreviewHandler = require('muk_preview.PreviewHandler'); @@ -31,6 +33,11 @@ var QWeb = core.qweb; var _t = core._t; var PreviewDialog = Widget.extend({ + cssLibs: [ + ], + jsLibs: [ + '/muk_web_preview/static/lib/printThis/printThis.js', + ], init: function(parent, generator, url, mimetype, extension, title) { this._super(parent); this._opened = $.Deferred(); @@ -38,26 +45,39 @@ var PreviewDialog = Widget.extend({ this.url = url; this.mimetype = mimetype; this.extension = extension; - this.$modal = $(QWeb.render('PreviewDialog', {title: this.title, url: this.url})); - this.$modal.on('hidden.bs.modal', _.bind(this.destroy, this)); - this.$modal.find('.preview-maximize').on('click', _.bind(this.maximize, this)); - this.$modal.find('.preview-minimize').on('click', _.bind(this.minimize, this)); - this.$modal.find('.preview-print').on('click', _.bind(this.print, this)); this.generator = generator; this.generator.widget = this; }, + willStart: function() { + var self = this; + return $.when(ajax.loadLibs(this), this._super()).then(function() { + self.$modal = $(QWeb.render('PreviewDialog', {title: self.title, url: self.url})); + }); + }, + start: function() { + var self = this; + return this._super().then(function() { + self.$modal.on('hidden.bs.modal', _.bind(self.destroy, self)); + self.$modal.find('.preview-maximize').on('click', _.bind(self.maximize, self)); + self.$modal.find('.preview-minimize').on('click', _.bind(self.minimize, self)); + self.$modal.find('.preview-print').on('click', _.bind(self.print, self)); + }); + }, renderElement: function() { this._super(); var self = this; - this.generator.createPreview(this.url, this.mimetype, this.extension, this.title).then(function($content) { - self.setElement($("
").addClass("modal-body preview-body").append($content)); - self.$modal.find('.preview-print').toggle($content.hasClass('printable')); + this.generator.createPreview(this.url, this.mimetype, + this.extension, this.title).then(function($content) { + self.$el.replaceWith($content); + self.setElement($content); + self.$modal.find('.preview-print').toggle($content.hasClass('printable')); }); }, open: function() { var self = this; $('.tooltip').remove(); - this.replace(this.$modal.find(".modal-body")).then(function() { + this.appendTo($('
')).then(function() { + self.$modal.find(".modal-body").append(self.$el); self.$modal.modal('show'); self._opened.resolve(); }); @@ -96,25 +116,32 @@ var PreviewDialog = Widget.extend({ }); } }, + opened: function (handler) { + return (handler)? this._opened.then(handler) : this._opened; + }, close: function() { - this.$modal.modal('hide'); + this.destroy(); }, - destroy: function(reason) { - $('.tooltip').remove(); - if(this.isDestroyed()) { + destroy: function (reason) { + if (!this.__closed) { + this.__closed = true; + this.trigger("closed", reason); + } + if (this.isDestroyed()) { return; } - this.trigger("closed", reason); this._super(); - this.$modal.modal('hide'); - this.$modal.remove(); - setTimeout(function () { - var modals = $('body > .modal').filter(':visible'); - if(modals.length) { - modals.last().focus(); - $('body').addClass('modal-open'); - } - }, 0); + + $('.tooltip').remove(); + if (this.$modal) { + this.$modal.modal('hide'); + this.$modal.remove(); + } + var modals = $('body > .modal').filter(':visible'); + if (modals.length) { + modals.last().focus(); + $('body').addClass('modal-open'); + } } }); diff --git a/muk_web_preview/static/src/js/preview_generator.js b/muk_web_preview/static/src/js/preview_generator.js index ec76fea..b4243c5 100644 --- a/muk_web_preview/static/src/js/preview_generator.js +++ b/muk_web_preview/static/src/js/preview_generator.js @@ -47,8 +47,13 @@ var PreviewGenerator = core.Class.extend({ if(matchedHandler) { return matchedHandler.createHtml(url, mimetype, extension, title); } else { - return $.when($.Deferred().resolve($(QWeb.render('UnsupportedContent', - {url: url, mimetype: mimetype || _t('Unknown'), extension: extension || _t('Unknown'), title: title || _t('Unknown')})))); + var $content = $.Deferred(); + $content.resolve($(QWeb.render('UnsupportedContent', { + url: url, mimetype: mimetype || _t('Unknown'), + extension: extension || _t('Unknown'), + title: title || _t('Unknown') + }))); + return $content; } } }); diff --git a/muk_web_preview/static/src/js/preview_handler.js b/muk_web_preview/static/src/js/preview_handler.js index 47f6f67..f7e92cb 100644 --- a/muk_web_preview/static/src/js/preview_handler.js +++ b/muk_web_preview/static/src/js/preview_handler.js @@ -36,7 +36,7 @@ var BaseHandler = core.Class.extend({ return false; }, createHtml: function(url, mimetype, extension, title) { - $.when(); + return $.when(); }, }); @@ -51,7 +51,7 @@ var PDFHandler = BaseHandler.extend({ var result = $.Deferred(); var viewerUrlTempalte = _.template('/muk_web_preview/static/lib/PDFjs/web/viewer.html?file=<%= url %>'); result.resolve($(QWeb.render('ViewerJSFrame', {url: viewerUrlTempalte({url})}))); - return $.when(result); + return result; }, }); @@ -68,7 +68,7 @@ var OpenOfficeHandler = BaseHandler.extend({ var result = $.Deferred(); var viewerUrlTempalte = _.template('/muk_web_preview/static/lib/ViewerJS/index.html#<%= url %>'); result.resolve($(QWeb.render('ViewerJSFrame', {url: viewerUrlTempalte({url})}))); - return $.when(result); + return result; }, }); diff --git a/muk_web_preview/static/src/less/preview_content.less b/muk_web_preview/static/src/less/preview_content.less index 4975e51..d05b296 100644 --- a/muk_web_preview/static/src/less/preview_content.less +++ b/muk_web_preview/static/src/less/preview_content.less @@ -20,6 +20,7 @@ .o_preview_viewerjs, .o_preview_viewerjs iframe { position: absolute; + display: block; width: 100%; height: 100%; } @@ -27,6 +28,7 @@ .o_preview_pdfjs, .o_preview_pdfjs iframe { position: absolute; + display: block; width: 100%; height: 100%; } diff --git a/muk_web_preview/static/src/less/preview_dialog.less b/muk_web_preview/static/src/less/preview_dialog.less index 830f37e..c74a17a 100644 --- a/muk_web_preview/static/src/less/preview_dialog.less +++ b/muk_web_preview/static/src/less/preview_dialog.less @@ -79,9 +79,14 @@ button.preview-minimize { .preview-body { padding: 0; + position: relative; min-height: 420px; } +.preview-footer { + padding: 10px; +} + .modal.modal-fullscreen { position: fixed; diff --git a/muk_web_preview/static/src/xml/preview_dialog.xml b/muk_web_preview/static/src/xml/preview_dialog.xml index a7f993a..c02b8f3 100644 --- a/muk_web_preview/static/src/xml/preview_dialog.xml +++ b/muk_web_preview/static/src/xml/preview_dialog.xml @@ -29,9 +29,9 @@
-