Files
FHC-Core/public/js/NavigationWidget.js
T
Paolo 3c7fc4bdbd - AjaxLib.css: better veil
- AjaxLib.js:
	- Renamed object FHC_Ajax_Client to FHC_AjaxClient
	- Removed REMOTE_CONTROLLER property from object data used as ajax call parameter
- Adapted FilterWidget.js to use AjaxLib.js
- Adapted NavigationWidget.js to use AjaxLib.js
- Introduced fhc_controller_id in method _printNavItem of NavigationWidget.js
- Adapted infocenterDetails.js and infocenterPersonDataset.js to use changed libraries
2018-05-22 18:08:54 +02:00

199 lines
4.6 KiB
JavaScript

/**
* FH-Complete
*
* @package
* @author
* @copyright Copyright (c) 2016 fhcomplete.org
* @license GPLv3
* @link https://fhcomplete.org
* @since Version 1.0.0
*/
/**
* FHC_NavigationWidget
*/
var FHC_NavigationWidget = {
//------------------------------------------------------------------------------------------------------------------
// Public methods
/**
* Renders the header menu (top horizontal menu)
*/
renderHeaderMenu: function() {
//
FHC_AjaxClient.ajaxCallGet(
'system/Navigation/header',
{
navigation_widget_called: FHC_NavigationWidget._getNavigationWidgetCalled()
},
{
successCallback: function(data, textStatus, jqXHR) {
if (data != null)
{
jQuery.each(data, function(i, e) {
$(".menu-header-items").append('<a class="navbar-brand" href="' + e + '">' + i + '</a>');
});
}
}
}
);
},
/**
* Renders the side left menu
*/
renderSideMenu: function() {
//
FHC_AjaxClient.ajaxCallGet(
'system/Navigation/menu',
{
navigation_widget_called: FHC_NavigationWidget._getNavigationWidgetCalled()
},
{
successCallback: function(data, textStatus, jqXHR) {
if (data != null)
{
var strMenu = '';
FHC_NavigationWidget._printCollapseIcon();
jQuery.each(data, function(i, e) {
strMenu += FHC_NavigationWidget._printNavItem(e);
});
$("#side-menu").html(strMenu);
$("#side-menu").metisMenu();
}
if (typeof sideMenuHook == 'function')
{
sideMenuHook();
}
}
}
);
},
//------------------------------------------------------------------------------------------------------------------
// Private methods
/**
*
*/
_printCollapseIcon: function() {
// Hiding/showing navigation menu - works only with sb admin 2 template!!
if(!$("#collapseicon").length)
$("#side-menu").parent().append('<div id="collapseicon" title="hide Menu" class="text-right" style="cursor: pointer; color: #337ab7"><i class="fa fa-angle-double-left fa-fw"></i></div>');
$("#collapseicon").click(function() {
$("#page-wrapper").css('margin-left', '0px');
$("#side-menu").hide();
$("#collapseicon").hide();
$("#collapseinicon").show();
});
$("#collapseinicon").click(function() {
$("#page-wrapper").css('margin-left', '250px');
$("#side-menu").show();
$("#collapseicon").show();
$("#collapseinicon").hide();
});
},
/**
*
*/
_printNavItem: function(item, depth = 1) {
strMenu = "";
var expanded = typeof item['expand'] != 'undefined' && item['expand'] === true ? ' active' : '';
strMenu += '<li class="' + expanded + '">';
if (typeof item['subscriptLinkClass'] != 'undefined' && typeof item['subscriptDescription'] != 'undefined')
{
strMenu += '<span>';
}
// Handle fhc_controller_id
var fhc_controller_id = FHC_AjaxClient.getUrlParameter('fhc_controller_id');
if (fhc_controller_id != null && fhc_controller_id != '' && item['link'] != '#')
{
if (item['link'].indexOf('?') != -1)
{
item['link'] += '&';
}
else
{
item['link'] += '?';
}
item['link'] += 'fhc_controller_id=' + fhc_controller_id;
}
strMenu += '<a href="' + item['link'] + '"' + expanded + '>';
if (item['icon'] != 'undefined')
{
strMenu += '<i class="fa fa-' + item['icon'] + ' fa-fw"></i> ';
}
strMenu += item['description'];
if (typeof item['children'] != 'undefined' && Object.keys(item['children']).length > 0)
{
strMenu += '<span class="fa arrow"></span>';
}
strMenu += '</a>';
if (typeof item['subscriptLinkClass'] != 'undefined' && typeof item['subscriptDescription'] != 'undefined')
{
strMenu += '<a class="' + item['subscriptLinkClass'] + ' menuSubscriptLink" value="' + item['subscriptLinkValue'] + '" href="#"> (' + item['subscriptDescription'] + ')</a>';
strMenu += '</span>';
}
if (typeof item['children'] != 'undefined' && Object.keys(item['children']).length > 0)
{
var level = '';
if (depth === 1)
{
level = 'second';
}
else if (depth > 1)
{
level = 'third';
}
strMenu += '<ul class="nav nav-' + level + '-level" ' + expanded + '>';
jQuery.each(item['children'], function(i, e) {
strMenu += FHC_NavigationWidget._printNavItem(e, ++depth);
});
strMenu += '</ul>';
}
strMenu += '</li>';
return strMenu;
},
/**
* Returns the URI of the caller
*/
_getNavigationWidgetCalled: function() {
return FHC_JS_DATA_STORAGE_OBJECT.called_path + "/" + FHC_JS_DATA_STORAGE_OBJECT.called_method;
}
};
/**
* When JQuery is up
*/
$(document).ready(function() {
FHC_NavigationWidget.renderHeaderMenu();
FHC_NavigationWidget.renderSideMenu();
});