Refactor permitted params extraction

pull/1782/head
Hagen Schink 10 years ago
parent 5aee2218b1
commit 579528d6ea
  1. 13
      app/assets/javascripts/angular/helpers/work-package-context-menu-helper.js
  2. 7
      app/assets/javascripts/angular/work_packages/work-package-context-menu.js

@ -28,13 +28,12 @@
angular.module('openproject.workPackages.helpers')
.constant('PERMITTED_CONTEXT_MENU_ACTIONS', ['edit', 'watch', 'log_time', 'duplicate', 'move', 'copy', 'delete'])
.constant('PERMITTED_BULK_ACTIONS', ['edit', 'watch', 'move', 'copy', 'delete'])
.constant('PERMITTED_BULK_ACTIONS', ['edit', 'watch', 'move', 'copy', 'delete'])
.service('WorkPackageContextMenuHelper', ['PERMITTED_CONTEXT_MENU_ACTIONS', 'PERMITTED_BULK_ACTIONS', 'WorkPackagesTableService', 'UrlParamsHelper', function(PERMITTED_CONTEXT_MENU_ACTIONS, PERMITTED_BULK_ACTIONS, WorkPackagesTableService, UrlParamsHelper) {
function getPermittedActionLinks(workPackage) {
.service('WorkPackageContextMenuHelper', ['PERMITTED_BULK_ACTIONS', 'WorkPackagesTableService', 'UrlParamsHelper', function(PERMITTED_BULK_ACTIONS, WorkPackagesTableService, UrlParamsHelper) {
function getPermittedActionLinks(workPackage, permittedActionConstansts) {
var linksToPermittedActions = {};
var permittedActions = getIntersection([workPackage._actions, PERMITTED_CONTEXT_MENU_ACTIONS]);
var permittedActions = getIntersection([workPackage._actions, permittedActionConstansts]);
angular.forEach(permittedActions, function(permittedAction) {
linksToPermittedActions[permittedAction] = workPackage._links[permittedAction];
@ -89,9 +88,9 @@ angular.module('openproject.workPackages.helpers')
}
var WorkPackageContextMenuHelper = {
getPermittedActions: function(workPackages) {
getPermittedActions: function(workPackages, permittedActionConstansts) {
if (workPackages.length === 1) {
return getPermittedActionLinks(workPackages[0]);
return getPermittedActionLinks(workPackages[0], permittedActionConstansts);
} else if (workPackages.length > 1) {
return getIntersectOfPermittedActions(workPackages);
}

@ -28,6 +28,8 @@
angular.module('openproject.workPackages')
.constant('PERMITTED_CONTEXT_MENU_ACTIONS', ['edit', 'watch', 'log_time', 'duplicate', 'move', 'copy', 'delete'])
.factory('WorkPackageContextMenu', [
'ngContextMenu',
function(ngContextMenu) {
@ -48,7 +50,8 @@ angular.module('openproject.workPackages')
'WorkPackagesTableService',
'I18n',
'$window',
function($scope, $rootScope, WorkPackagesTableHelper, WorkPackageContextMenuHelper, WorkPackageService, WorkPackagesTableService, I18n, $window) {
'PERMITTED_CONTEXT_MENU_ACTIONS',
function($scope, $rootScope, WorkPackagesTableHelper, WorkPackageContextMenuHelper, WorkPackageService, WorkPackagesTableService, I18n, $window, PERMITTED_CONTEXT_MENU_ACTIONS) {
$scope.I18n = I18n;
@ -60,7 +63,7 @@ angular.module('openproject.workPackages')
}
$scope.row.checked = true;
$scope.permittedActions = WorkPackageContextMenuHelper.getPermittedActions(getSelectedWorkPackages());
$scope.permittedActions = WorkPackageContextMenuHelper.getPermittedActions(getSelectedWorkPackages(), PERMITTED_CONTEXT_MENU_ACTIONS);
});

Loading…
Cancel
Save