Restore the side bar menu state after a refresh

Add code to detect the current URL and open the parent of
the menu entry that correlates to it.

Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
This commit is contained in:
Roberto Rosario
2018-12-24 18:51:53 -04:00
parent 38228b4fe8
commit 2402668e16
2 changed files with 38 additions and 27 deletions

View File

@@ -1,22 +1,46 @@
'use strict';
class MayanApp {
constructor (parameters) {
constructor (options) {
var self = this;
parameters = parameters || {
options = options || {
ajaxMenusOptions: []
}
this.ajaxSpinnerSeletor = '#ajax-spinner';
this.ajaxExecuting = false;
this.ajaxMenusOptions = parameters.ajaxMenusOptions;
this.ajaxMenusOptions = options.ajaxMenusOptions;
this.ajaxMenuHashes = {};
this.window = $(window);
}
// Class methods and variables
static MultiObjectFormProcess ($form, options) {
/*
* ajaxForm callback to add the external item checkboxes to the
* submitted form
*/
if ($form.hasClass('form-multi-object-action')) {
// Turn form data into an object
var formArray = $form.serializeArray().reduce(function (obj, item) {
obj[item.name] = item.value;
return obj;
}, {});
// Add all checked checkboxes to the form data
$('.form-multi-object-action-checkbox:checked').each(function() {
var $this = $(this);
formArray[$this.attr('name')] = $this.attr('value');
});
// Set the form data as the data to send
options.data = formArray;
}
}
static mayanNotificationBadge (options, data) {
// Callback to add the notifications count inside a badge markup
var notifications = data[options.attributeName];
@@ -40,28 +64,14 @@ class MayanApp {
}
}
static MultiObjectFormProcess ($form, options) {
/*
* ajaxForm callback to add the external item checkboxes to the
* submitted form
*/
if ($form.hasClass('form-multi-object-action')) {
// Turn form data into an object
var formArray = $form.serializeArray().reduce(function (obj, item) {
obj[item.name] = item.value;
return obj;
}, {});
// Add all checked checkboxes to the form data
$('.form-multi-object-action-checkbox:checked').each(function() {
var $this = $(this);
formArray[$this.attr('name')] = $this.attr('value');
});
// Set the form data as the data to send
options.data = formArray;
}
static setupNavbarState () {
var uri = new URI(window.location.hash);
var uriFragment = uri.fragment();
$('#accordion-sidebar > .panel-default > .collapse > .panel-body > ul > li > a').each(function (index, value) {
if (value.pathname === uriFragment) {
$(this).parents('.collapse').collapse('show');
}
});
}
static tagSelectionTemplate (tag, container) {
@@ -95,7 +105,7 @@ class MayanApp {
},
success: function(data) {
if (options.callback) {
// Conver the callback string to an actual function
// Convert the callback string to an actual function
var callbackFunction = window;
$.each(options.callback.split('.'), function (index, value) {
@@ -127,10 +137,10 @@ class MayanApp {
if ((menuHash === undefined) || (menuHash !== data.hex_hash)) {
$(options.menuSelector).html(data.html);
options.app.ajaxMenuHashes[data.name] = data.hex_hash;
if (options.callback !== undefined) {
options.callback();
}
options.app.ajaxMenuHashes[data.name] = data.hex_hash;
}
},
url: options.url,

View File

@@ -113,6 +113,7 @@
var app = new MayanApp({
ajaxMenusOptions: [
{
callback: MayanApp.setupNavbarState,
interval: 5000,
menuSelector: '#menu-sidebar',
name: 'menu_main',