pip-webui
Version:
HTML5 UI for LOB applications
119 lines (104 loc) • 4.04 kB
JavaScript
/**
* @file Page template for help components
* @copyright Digital Living Software Corp. 2014-2016
*/
(function (angular, _) {
'use strict';
angular.module('pipHelp.Page', ['pipState', 'pipHelp.Service', 'pipAppBar', 'pipSelected', 'pipTranslate',
'pipHelp.Templates'])
.config(config)
.controller('pipHelpPageController', HelpPageController);
function config(pipStateProvider) {
pipStateProvider.state('help', {
url: '/help',
auth: false,
controller: 'pipHelpPageController',
templateUrl: 'help_page/help_page.html'
});
}
/**
* @ngdoc controller
* @name pipHelp.Page.pipHelpPageController
*
* @description
* The controller is used for the root Help component.
* It manages available tabs provide navigation through those ones.
*
* {@link https://github.com/pip-webui/pip-webui-help/blob/master/src/help_page/help_page.js#L40 View source}
*
*
* @param {Object} $rootScope Root scope object
* @param {Object} $scope Scope for the current controller
* @param {Object} $state UI Router service
* @param {Object} pipAppBar Service provides an interface to manage on application bar header.
* @param {Object} pipHelp Service to manage this component behaviour
*/
function HelpPageController($rootScope, $scope, $state, pipAppBar, pipHelp) {
$scope.tabs = _.filter(pipHelp.getTabs(), function (tab) {
if (tab.visible && (tab.access !== angular.noop ? tab.access($rootScope.$user, tab) : true)) {
return tab;
}
});
$scope.selected = {};
if ($state.current.name !== 'help') {
initSelect($state.current.name);
} else {
initSelect(pipHelp.getDefaultTab().state);
}
appHeader();
$scope.onNavigationSelect = onNavigationSelect;
$scope.onDropdownSelect = onDropdownSelect;
/**
* @ngdoc method
* @name pipHelp.Page.pipHelpPageController#onDropdownSelect
* @methodOf pipHelp.Page.pipHelpPageController
*
* @description
* It redirects to a passed state.
*
* {@link https://github.com/pip-webui/pip-webui-help/blob/master/src/help_page/help_page.js#L72 View source}
*
* @param {Object} state State configuration object
*/
function onDropdownSelect(state) {
onNavigationSelect(state.state);
}
/**
* Config appBar due to this page
*/
function appHeader() {
pipAppBar.showMenuNavIcon();
pipAppBar.showTitleText('Help');
pipAppBar.showShadowSm();
pipAppBar.showLocalActions(null, []);
}
/**
* @ngdoc method
* @name pipHelp.Page.pipHelpPageController#onNavigationSelect
* @methodOf pipHelp.Page.pipHelpPageController
*
* @description
* It redirects to a passed state.
*
* {@link https://github.com/pip-webui/pip-webui-help/blob/master/src/help_page/help_page.js#L98 View source}
*
* @param {string} state Name of the target state.
*/
function onNavigationSelect(state) {
initSelect(state);
if ($scope.selected.tab) {
$state.go(state);
}
}
/**
* Set selected item for highlighting in the nav menu
*/
function initSelect(state) {
$scope.selected.tab = _.find($scope.tabs, function (tab) {
return tab.state === state;
});
$scope.selected.tabIndex = _.indexOf($scope.tabs, $scope.selected.tab);
$scope.selected.tabId = state;
}
}
})(window.angular, window._);