From 810558659df8c6fb2519552701dd49897e5558e5 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Fri, 16 Nov 2018 18:23:43 -0400 Subject: [PATCH] Documents: Add invalid document server template Invalid document template is now served or included from a specific template file. Documents with invalid API image URLs now return None instead of the template code specific '#'. The new template is called invalid_document.html. Signed-off-by: Roberto Rosario --- HISTORY.rst | 4 ++ .../static/appearance/js/mayan_image.js | 43 ++++++++++--------- .../appearance/templates/appearance/root.html | 15 ++----- mayan/apps/documents/apps.py | 7 ++- mayan/apps/documents/models.py | 4 -- .../forms/widgets/document_page_image.html | 4 +- .../templates/documents/invalid_document.html | 8 ++++ 7 files changed, 47 insertions(+), 38 deletions(-) create mode 100644 mayan/apps/documents/templates/documents/invalid_document.html diff --git a/HISTORY.rst b/HISTORY.rst index 34d5a796fe..d115ec07cb 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,5 +1,9 @@ 3.2 (2018-XX-XX) ================ +- Documents: Add a server side template for invalid documents. + The new template can be accessed via the templates API. + Improve the way invalid documents are detected in the JavaScript + code. - Pagination: Fix page AJAX reload when clicking on pagination active page link. - Pagination: Add pure pagination subclass that supports custom page diff --git a/mayan/apps/appearance/static/appearance/js/mayan_image.js b/mayan/apps/appearance/static/appearance/js/mayan_image.js index d04f896832..869faf547e 100644 --- a/mayan/apps/appearance/static/appearance/js/mayan_image.js +++ b/mayan/apps/appearance/static/appearance/js/mayan_image.js @@ -6,10 +6,11 @@ class MayanImage { this.load(); } - static intialize () { - var app = this; + static intialize (options) { + this.options = options || {}; + this.options.templateInvalidDocument = this.options.templateInvalidDocument || 'Error loading document image'; - this.fancybox = $().fancybox({ + $().fancybox({ animationDuration : 300, buttons : [ 'fullScreen', @@ -58,30 +59,32 @@ class MayanImage { } static timerFunction () { - $.fn.matchHeight._maintainScroll = true; $.fn.matchHeight._update(); } load () { - var self = this; var container = this.element.parent().parent().parent(); + var dataURL = this.element.attr('data-url'); - this.element.attr('src', this.element.attr('data-url')); - this.element.on('error', function() { - // Check the .complete property to see if it is a real error - // or it was a cached image - if (this.complete === false) { - // It is a cached image, set the src attribute to trigger - // it's display. - this.src = this.src; - } else { - container.html(MayanImage.templateInvalidDocument); - } - }); - - $.fn.matchHeight._maintainScroll = true; + if (dataURL === '') { + container.html(MayanImage.options.templateInvalidDocument); + } else { + this.element.attr('src', dataURL); + this.element.on('error', function() { + // Check the .complete property to see if it is a real error + // or it was a cached image + if (this.complete === false) { + // It is a cached image, set the src attribute to trigger + // it's display. + this.src = this.src; + } else { + container.html(MayanImage.options.templateInvalidDocument); + } + }); + } }; } -MayanImage.templateInvalidDocument = $('#template-invalid-document').html(); MayanImage.timer = setTimeout(null); + +$.fn.matchHeight._maintainScroll = true; diff --git a/mayan/apps/appearance/templates/appearance/root.html b/mayan/apps/appearance/templates/appearance/root.html index 3a98e2d645..b986ffc988 100644 --- a/mayan/apps/appearance/templates/appearance/root.html +++ b/mayan/apps/appearance/templates/appearance/root.html @@ -61,17 +61,6 @@ - -