OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openproject/app/assets/javascripts/angular/layout/menu-item-factory.js

51 lines
1.2 KiB

angular.module('openproject.layout')
.factory('menuItemFactory', [
'$rootScope',
'$compile',
'$http',
'$templateCache',
'$animate',
function($rootScope, $compile, $http, $templateCache, $animate) {
return function(options) {
if (!options.container) {
throw new Error('Container must be specified menu item to have exacly one of either `template` or `templateUrl`');
}
var templateUrl = '/templates/layout/menu_item.html',
type = options.type,
container = angular.element(options.container),
linkFn = options.linkFn,
scope;
function generateMenuItem(title, path, objectId) {
var menuItem;
scope = $rootScope.$new(true);
scope.type = type;
scope.title = title;
scope.path = path;
scope.objectId = objectId;
$http.get(templateUrl, {
cache: $templateCache
}).then(function (response) {
menuItem = angular.element(response.data);
if (linkFn) linkFn(scope, menuItem.children('a'), {});
$compile(menuItem)(scope);
$animate.enter(menuItem, container);
});
}
return {
generateMenuItem: generateMenuItem,
link: linkFn
};
};
}]);