bansho/app/routing_view/routing_view.js
Vincent Fournier 63f3ad58d6 Improve jshint task and fix errors
Change-Id: I1b9c7d4a7040e3fee66388b9744b553a6fb1da6e
2015-05-20 15:46:08 -04:00

54 lines
1.8 KiB
JavaScript

/*global jQuery */
'use strict';
angular.module('bansho.view', ['ngRoute',
'bansho.config'
])
.value('viewsTemplate', {})
.config(['$routeProvider', function ($routeProvider) {
$routeProvider.when('/view', {
controller: 'ViewCtrl',
template: '<div ng-include="templateUrl">Loading...</div>'
})
.when('/login', {
templateUrl: 'components/authentication/authentication.html'
});
}])
.controller('ViewCtrl', ['$scope', '$rootScope', '$location', '$routeParams', '$window', '$timeout', 'viewsTemplate', 'loadConfig', 'authService', 'configManager',
function ($scope, $rootScope, $location, $routeParams, $window, $timeout, viewsTemplate, loadConfig, authService, configManager) {
var templateName,
templateUrl;
if (!$rootScope.isAuthenticated) {
$location.path('/login');
return;
}
if (jQuery.isEmptyObject(viewsTemplate)) {
loadConfig();
}
if (!!$routeParams.view) {
$scope.viewName = $routeParams.view;
} else {
$scope.viewName = $routeParams.view = 'dashboardConfig';
}
templateName = viewsTemplate[$scope.viewName];
$scope.templateUrl = 'templates/' + templateName + '/' + templateName + '.html';
}])
.service('loadConfig', ['configManager', 'viewsTemplate', function (configManager, viewsTemplate) {
return function () {
var viewsConfig = configManager.readConfig();
angular.forEach(viewsConfig, function (config, view) {
viewsTemplate[view] = config.template;
});
};
}]);