diff --git a/HISTORY.rst b/HISTORY.rst index cae6f658c1..bc1de6d87d 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -147,6 +147,10 @@ - Improve the speed of the document indexing. - Move the matchHeight call from lazy loading to image loading. Reduces the chance of wrongly sized cards. +- Generalize the Javascript menu rendering into an API for + templates that only refresh the menu when there are changes. + Closes GitLab issue #511. Thanks to Daniel Carrico + @daniel1113 for the report. 3.0.3 (2018-08-17) ================== diff --git a/docs/releases/3.1.rst b/docs/releases/3.1.rst index 57ef915336..51b1b901e2 100644 --- a/docs/releases/3.1.rst +++ b/docs/releases/3.1.rst @@ -363,6 +363,10 @@ classes beyond the provide line chart. - Improve the speed of the document indexing. - Move the matchHeight call from lazy loading to image loading. Reduces the chance of wrongly sized cards. +- Generalize the Javascript menu rendering into an API for + templates that only refresh the menu when there are changes. + Closes GitLab issue #511. Thanks to Daniel Carrico + @daniel1113 for the report. Removals -------- @@ -446,5 +450,6 @@ Bugs fixed or issues closed * `GitLab issue #7 `_ Feature: other compressors than zip for compressed documents * `GitLab issue #259 `_ Thumbnails: why are they created on the fly (therefore: not cached) * `GitLab issue #360 `_ Should quick rename (optionally) retain original file type extension? - +* `GitLab issue #511 `_ Menu bar flickering in 3.1b1 + .. _PyPI: https://pypi.python.org/pypi/mayan-edms/ diff --git a/mayan/apps/appearance/static/appearance/js/mayan_app.js b/mayan/apps/appearance/static/appearance/js/mayan_app.js index ba69e424cd..e1e351a2fe 100644 --- a/mayan/apps/appearance/static/appearance/js/mayan_app.js +++ b/mayan/apps/appearance/static/appearance/js/mayan_app.js @@ -8,6 +8,15 @@ class MayanApp { this.ajaxSpinnerSeletor = '#ajax-spinner'; this.ajaxExecuting = false; + this.ajaxMenusOptions = [ + { + app: this, + interval: 5000, + menuSelector: '#main-menu', + url: apiTemplateMainMenuURL, + } + ]; + this.ajaxMenuHashes = {}; this.window = $(window); } @@ -113,25 +122,22 @@ class MayanApp { } } - doRefreshMainMenu (options) { - var self = this; - var $mainMenu = $('#main-menu'); - var $mainMenuBuffer = $('#main-menu-buffer'); - + doRefreshAJAXMenu (options) { $.ajax({ complete: function() { - setTimeout(app.doRefreshMainMenu, options.interval, options); + setTimeout(app.doRefreshAJAXMenu, options.interval, options); }, success: function(data) { - var $elements = $('.dropdown.open'); - if ($elements.length === 0) { - // Don't refresh the HTML if there are open dropdowns - $mainMenuBuffer.html(data); - $mainMenuBuffer.show(); - $mainMenu.hide(); - $mainMenu.html($mainMenuBuffer.html()); - $mainMenu.show(); - $mainMenuBuffer.hide(); + console.log(data); + var menuHash = options.app.ajaxMenuHashes[data.name]; + console.log('menuHash' + menuHash); + + if ((menuHash === undefined) || (menuHash !== data.hex_hash)) { + $(options.menuSelector).html(data.html); + if (options.callback !== undefined) { + options.callback(); + } + options.app.ajaxMenuHashes[data.name] = data.hex_hash; } }, url: options.url, @@ -217,9 +223,8 @@ class MayanApp { this.setupItemsSelector(); this.setupNavbarCollapse(); this.setupNewWindowAnchor(); - this.doRefreshMainMenu({ - interval: 5000, - url: '/main_menu' + $.each(this.ajaxMenusOptions, function(index, value) { + app.doRefreshAJAXMenu(value); }); partialNavigation.initialize(); } diff --git a/mayan/apps/appearance/templates/appearance/root.html b/mayan/apps/appearance/templates/appearance/root.html index 61818e8940..3a98e2d645 100644 --- a/mayan/apps/appearance/templates/appearance/root.html +++ b/mayan/apps/appearance/templates/appearance/root.html @@ -36,7 +36,6 @@ -
@@ -114,6 +113,7 @@ {# Transfer variable from Django to javascript #} var initialURL = '{% url home_view %}'; var djangoDEBUG = {% if debug %}true{% else %}false{% endif %}; + var apiTemplateMainMenuURL = '{% url "rest_api:template-detail" "main_menu" %}';