From 18faaa69bd9005e9e84332c5568cf1883c633ff8 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Sun, 14 Apr 2019 00:46:57 -0400 Subject: [PATCH] Add server side invalid document template Signed-off-by: Roberto Rosario --- HISTORY.rst | 1 + docs/releases/3.2.rst | 1 + .../static/appearance/js/mayan_image.js | 66 +++++++++++-------- .../appearance/templates/appearance/root.html | 15 +---- mayan/apps/documents/apps.py | 7 +- .../templates/documents/invalid_document.html | 11 ++++ 6 files changed, 59 insertions(+), 42 deletions(-) create mode 100644 mayan/apps/documents/templates/documents/invalid_document.html diff --git a/HISTORY.rst b/HISTORY.rst index 1b7ec55e03..87bfd7d018 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -50,6 +50,7 @@ recently accessed documents from 40 to 400. * Integrate django-autoadmin into the core apps. * Update middleware to new style classes. +* Add server side invalid document template. 3.1.11 (2019-04-XX) =================== diff --git a/docs/releases/3.2.rst b/docs/releases/3.2.rst index e8daf27a6f..9fc1531085 100644 --- a/docs/releases/3.2.rst +++ b/docs/releases/3.2.rst @@ -74,6 +74,7 @@ Other changes recently accessed documents from 40 to 400. * Integrate django-autoadmin into the core apps. * Update middleware to new style classes. +* Add server side invalid document template. Removals -------- diff --git a/mayan/apps/appearance/static/appearance/js/mayan_image.js b/mayan/apps/appearance/static/appearance/js/mayan_image.js index d04f896832..aa544d509d 100644 --- a/mayan/apps/appearance/static/appearance/js/mayan_image.js +++ b/mayan/apps/appearance/static/appearance/js/mayan_image.js @@ -6,23 +6,24 @@ 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({ - animationDuration : 300, - buttons : [ - 'fullScreen', - 'close', - ], - selector: 'a.fancybox', + $().fancybox({ afterShow: function (instance, current) { $('a.a-caption').on('click', function(event) { instance.close(true); }); }, + animationEffect: 'fade', + animationDuration : 100, + buttons : [ + 'fullScreen', + 'close', + ], infobar: true, - + selector: 'a.fancybox' }); $('img.lazy-load').lazyload({ @@ -42,46 +43,53 @@ class MayanImage { $('.lazy-load').one('load', function() { $(this).hide(); - $(this).fadeIn(300); + $(this).show(); $(this).siblings('.spinner-container').remove(); $(this).removeClass('lazy-load pull-left'); clearTimeout(MayanImage.timer); - MayanImage.timer = setTimeout(MayanImage.timerFunction, 100); + MayanImage.timer = setTimeout(MayanImage.timerFunction, 250); }); $('.lazy-load-carousel').one('load', function() { $(this).hide(); - $(this).fadeIn(300); + $(this).show(); $(this).siblings('.spinner-container').remove(); $(this).removeClass('lazy-load-carousel pull-left'); }); } 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); + setTimeout(function () { + self.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 = dataURL; + } else { + container.html( + MayanImage.options.templateInvalidDocument + ); + } + }); + }, 1); + } }; } -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 @@ - -