Extract method refactoring

pull/1782/head
Hagen Schink 10 years ago
parent b0b97947c0
commit 8d75e1a2d7
  1. 38
      app/assets/javascripts/angular/services/work-package-service.js
  2. 7
      app/assets/javascripts/angular/services/work-packages-table-service.js
  3. 24
      app/assets/javascripts/angular/work_packages/work-package-context-menu.js

@ -37,7 +37,10 @@ angular.module('openproject.services')
'HALAPIResource',
'DEFAULT_FILTER_PARAMS',
'DEFAULT_PAGINATION_OPTIONS',
function($http, PathHelper, WorkPackagesHelper, HALAPIResource, DEFAULT_FILTER_PARAMS, DEFAULT_PAGINATION_OPTIONS) {
'$rootScope',
'$window',
'WorkPackagesTableService',
function($http, PathHelper, WorkPackagesHelper, HALAPIResource, DEFAULT_FILTER_PARAMS, DEFAULT_PAGINATION_OPTIONS, $rootScope, $window, WorkPackagesTableService) {
var workPackage;
var WorkPackageService = {
@ -179,13 +182,36 @@ angular.module('openproject.services')
});
},
performBulkDelete: function(workPackages) {
performBulkDelete: function(ids, defaultHandling) {
if (defaultHandling && !$window.confirm(I18n.t('js.text_work_packages_destroy_confirmation'))) {
return;
}
var params = {
'ids[]': workPackages.map(function(wp) {
return wp.id;
})
'ids[]': ids
};
return $http['delete'](PathHelper.workPackagesBulkDeletePath(), { params: params });
var promis = $http['delete'](PathHelper.workPackagesBulkDeletePath(), { params: params });
if (defaultHandling) {
promis.success(function(data, status) {
// TODO wire up to API and processs API response
$rootScope.$emit('flashMessage', {
isError: false,
text: I18n.t('js.work_packages.message_successful_bulk_delete')
});
WorkPackagesTableService.removeRowsById(ids);
})
.error(function(data, status) {
// TODO wire up to API and processs API response
$rootScope.$emit('flashMessage', {
isError: true,
text: I18n.t('js.work_packages.message_error_during_bulk_delete')
});
});
} else {
return promis;
}
}
};

@ -123,6 +123,13 @@ angular.module('openproject.workPackages.services')
WorkPackagesTableService.removeRow(row);
});
},
removeRowsById: function(ids) {
angular.forEach(this.getRows(), function(row) {
if (ids.indexOf(row.object.id) >= 0) {
WorkPackagesTableService.removeRow(row);
}
});
},
sortBy: function(columnName, direction) {
QueryService.getQuery().sortation.addSortElement({

@ -73,31 +73,9 @@ angular.module('openproject.workPackages')
};
function deleteSelectedWorkPackages() {
if (!deleteConfirmed()) return;
var rows = WorkPackagesTableHelper.getSelectedRows($scope.rows);
WorkPackageService.performBulkDelete(getSelectedWorkPackages())
.success(function(data, status) {
// TODO wire up to API and processs API response
$rootScope.$emit('flashMessage', {
isError: false,
text: I18n.t('js.work_packages.message_successful_bulk_delete')
});
WorkPackagesTableService.removeRows(rows);
})
.error(function(data, status) {
// TODO wire up to API and processs API response
$rootScope.$emit('flashMessage', {
isError: true,
text: I18n.t('js.work_packages.message_error_during_bulk_delete')
});
});
}
function deleteConfirmed() {
return $window.confirm(I18n.t('js.text_work_packages_destroy_confirmation'));
WorkPackageService.performBulkDelete(getSelectedWorkPackages().map(function(wp) { return wp.id }), true);
}
function getWorkPackagesFromSelectedRows() {

Loading…
Cancel
Save