Rearrange query menu item-related angular code

pull/1524/head
Till Breuer 10 years ago
parent 1387d6ce58
commit 3b96778396
  1. 34
      app/assets/javascripts/angular/layout/menu-item-factory.js
  2. 36
      app/assets/javascripts/angular/layout/query-menu-item-directive.js

@ -47,38 +47,4 @@ angular.module('openproject.layout')
link: linkFn
};
};
}])
.factory('queryMenuItemFactory', [
'menuItemFactory',
'$stateParams',
'$animate',
'$timeout',
'QUERY_MENU_ITEM_TYPE',
function(menuItemFactory, $stateParams, $animate, $timeout, QUERY_MENU_ITEM_TYPE) {
return menuItemFactory({
itemType: 'query-menu-item',
container: '#main-menu-work-packages-wrapper ~ .menu-children',
linkFn: function(scope, element, attrs) {
scope.queryId = scope.objectId || attrs.objectId;
function setActiveState() {
element.toggleClass('selected', (scope.queryId || null) === $stateParams.query_id);
}
$timeout(setActiveState);
scope.$on('$stateChangeSuccess', setActiveState);
function removeItem() {
$animate.leave(element.parent(), function () {
scope.$destroy();
});
}
scope.$on('openproject.layout.removeMenuItem', function(event, itemData) {
if (itemData.itemType === QUERY_MENU_ITEM_TYPE && itemData.objectId === scope.queryId) {
removeItem();
}
});
}
});
}]);

@ -1,6 +1,40 @@
angular.module('openproject.layout')
.constant('QUERY_MENU_ITEM_TYPE', 'QueryMenuItem')
.constant('QUERY_MENU_ITEM_TYPE', 'query-menu-item')
.factory('queryMenuItemFactory', [
'menuItemFactory',
'$stateParams',
'$animate',
'$timeout',
'QUERY_MENU_ITEM_TYPE',
function(menuItemFactory, $stateParams, $animate, $timeout, QUERY_MENU_ITEM_TYPE) {
return menuItemFactory({
itemType: QUERY_MENU_ITEM_TYPE,
container: '#main-menu-work-packages-wrapper ~ .menu-children',
linkFn: function(scope, element, attrs) {
scope.queryId = scope.objectId || attrs.objectId;
function setActiveState() {
element.toggleClass('selected', (scope.queryId || null) === $stateParams.query_id);
}
$timeout(setActiveState);
scope.$on('$stateChangeSuccess', setActiveState);
function removeItem() {
$animate.leave(element.parent(), function () {
scope.$destroy();
});
}
scope.$on('openproject.layout.removeMenuItem', function(event, itemData) {
if (itemData.itemType === QUERY_MENU_ITEM_TYPE && itemData.objectId === scope.queryId) {
removeItem();
}
});
}
});
}])
.directive('queryMenuItem', [
'queryMenuItemFactory',

Loading…
Cancel
Save