Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
adding submenus functionality to the menu service
Browse files Browse the repository at this point in the history
When having few modules like Articles, Blog, Services, etc... it's good to add the 'New Whatever' or other functionalities within a submenu structure.
  • Loading branch information
netusco committed May 9, 2014
1 parent fca7e9e commit 7adb7f3
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion public/modules/core/services/menus.client.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,49 @@ angular.module('core').service('Menus', [
};

// Add menu item object
this.addMenuItem = function(menuId, menuItemTitle, menuItemURL, menuItemUIRoute, isPublic, roles) {
this.addMenuItem = function(menuId, menuItemTitle, menuItemURL, menuClass, menuItemUIRoute, isPublic, roles) {
// Validate that the menu exists
this.validateMenuExistance(menuId);

// Push new menu item
this.menus[menuId].items.push({
class: (menuClass === 'dropdown') ? menuClass : '',
title: menuItemTitle,
link: menuItemURL,
uiRoute: menuItemUIRoute || ('/' + menuItemURL),
isPublic: isPublic || this.menus[menuId].isPublic,
roles: roles || this.defaultRoles,
subitems: [],
shouldRender: shouldRender
});

// Return the menu object
return this.menus[menuId];
};

// Add submenu item object
this.addSubMenuItem = function(menuId, rootMenuItemURL, menuItemTitle, menuItemURL, menuItemUIRoute, isPublic, roles) {
// Validate that the menu exists
this.validateMenuExistance(menuId);

// Search for menu item
for (var itemIndex in this.menus[menuId].items) {
if (this.menus[menuId].items[itemIndex].link === rootMenuItemURL) {
// Push new submenu item
this.menus[menuId].items[itemIndex].subitems.push({
title: menuItemTitle,
link: menuItemURL,
uiRoute: menuItemUIRoute || ('/' + menuItemURL),
isPublic: isPublic || this.menus[menuId].isPublic,
roles: roles || this.defaultRoles,
shouldRender: shouldRender
});
}
}

// Return the menu object
return this.menus[menuId];
};

// Remove existing menu object by menu id
this.removeMenuItem = function(menuId, menuItemURL) {
Expand All @@ -107,6 +133,24 @@ angular.module('core').service('Menus', [
// Return the menu object
return this.menus[menuId];
};

// Remove existing menu object by menu id
this.removeSubMenuItem = function(menuId, submenuItemURL) {
// Validate that the menu exists
this.validateMenuExistance(menuId);

// Search for menu item to remove
for (var itemIndex in this.menus[menuId].items) {
for (var subitemIndex in this.menus[menuId].items[itemIndex].subitems) {
if (this.menus[menuId].items[itemIndex].subitems[subitemIndex].link === menuItemURL) {
this.menus[menuId].items[itemIndex].subitems.splice(subitemIndex, 1);
}
}
}

// Return the menu object
return this.menus[menuId];
};

//Adding the topbar menu
this.addMenu('topbar');
Expand Down

0 comments on commit 7adb7f3

Please sign in to comment.