--- /dev/null
+(function() {
+ angular
+ .module("pentila.nero.app")
+ .config(pentilaNeroConfiguration)
+ .run(pentilaNeroController);
+
+ /*
+ Service injection
+ */
+ pentilaNeroConfiguration.$inject = ["$routeProvider", "cfpLoadingBarProvider"];
+
+ function pentilaNeroConfiguration($routeProvider, cfpLoadingBarProvider) {
+ cfpLoadingBarProvider.includeSpinner = false;
+
+ var routesMap = {};
+
+ // configure our routes
+ addLeafToRoutes(JSONMenu.menu);
+
+ /**
+ Configure group routes
+ */
+ $routeProvider.when("/group/:groupName", {
+ templateUrl: function(urlParams) {
+ var url = "/group/" + urlParams.groupName;
+ url += "?p_p_id=menuPageGroupe_WAR_menuPageGroupeportlet";
+ url += "&p_p_lifecycle=0";
+ url += "&p_p_state=exclusive";
+ url += "&p_p_mode=view";
+ url += "&p_p_col_id=column-1&p_p_col_count=1";
+ url += "&display_p_p_id=" + urlParams.p_p_id;
+ url += "&jspPage=%2Fview.jsp";
+
+ /*for (var param in urlParams) {
+ if (param != "p_p_id" && param != "groupName") {
+ url += "&" + param + "=" + urlParams[param];
+ }
+ }*/
+
+ return url;
+ }
+ });
+
+ /**
+ Add each menu leaf to application routes
+ */
+ function addLeafToRoutes(menu) {
+ for(var i = 0; i < menu.length; i++) {
+ if (!menu[i].isExternalLink) {
+
+ if (menu[i].isLeaf) {
+ routesMap["#" + menu[i].route] = menu[i].templateUrl;
+ if(menu[i].isDefault) {
+ addRootRedirection(menu[i].route);
+ }
+
+ $routeProvider.when(menu[i].route, {
+ title: menu[i].label,
+ templateUrl: function(urlParams) {
+ var url = routesMap[location.hash.split("?")[0]];
+ for (var param in urlParams) {
+ url += "&" + param + "=" + urlParams[param];
+ }
+ return url;
+ }
+ //templateUrl: menu[i].templateUrl
+ });
+
+ }
+ else {
+ addLeafToRoutes(menu[i].menu);
+ }
+
+ }
+ }
+ }
+
+ /**
+ Redirect if no service is selected
+ */
+ function addRootRedirection(defaultRoute) {
+ $routeProvider.when('/', {
+ redirectTo: function() {
+ return defaultRoute;
+ }
+ });
+ }
+ }
+
+ pentilaNeroController.$inject = ["$rootScope", "$route", "cfpLoadingBar"];
+
+ function pentilaNeroController($rootScope, $route, cfpLoadingBar) {
+ var groupsTitle = getGroupsTitle(JSONMenu.menu);
+
+ function getGroupsTitle(menu) {
+ for (var i = 0; i < menu.length; i++) {
+ if (menu[i].isLeaf) {
+ if (menu[i].templateUrl.indexOf("accesAteliers_WAR_accesAteliersportlet") !== -1) {
+ return menu[i].label;
+ }
+ }
+ else {
+ var title = getGroupsTitle(menu[i].menu);
+ if (title !== undefined) {
+ return title;
+ }
+ }
+ }
+ return undefined;
+ }
+
+ $rootScope.$on('$routeChangeStart', function() {
+ cfpLoadingBar.start();
+ $('html, body').animate({
+ scrollTop: $('body').offset().top
+ },
+ 1000,
+ function() {}
+ );
+ });
+
+ $rootScope.$on('$routeChangeSuccess', function() {
+ cfpLoadingBar.complete();
+ if ($route.current.title != undefined) {
+ document.title = $route.current.title;
+ }
+ else {
+ // Case route is /group/groupName/...
+ document.title = groupsTitle;
+ }
+ });
+
+ $rootScope.$on('$routeChangeError', function() {
+ cfpLoadingBar.complete();
+ });
+ }
+})();