AC-234 create organizaions via Projects Tab

This commit is contained in:
chouseknecht 2013-07-19 10:32:09 -04:00
parent eef7814d66
commit 22e1a1ae72

View File

@ -10,9 +10,9 @@
'use strict';
function OrganizationsList ($scope, $rootScope, $location, $log, Rest, Alert, LoadBreadCrumbs, Prompt,
function OrganizationsList ($routeParams, $scope, $rootScope, $location, $log, Rest, Alert, LoadBreadCrumbs, Prompt,
GenerateList, OrganizationList, SearchInit, PaginateInit, ClearScope, ProcessErrors,
GetBasePath)
GetBasePath, SelectionInit)
{
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
//scope.
@ -28,6 +28,8 @@ function OrganizationsList ($scope, $rootScope, $location, $log, Rest, Alert, Lo
LoadBreadCrumbs();
SelectionInit({ scope: scope, list: list });
// Initialize search and paginate pieces and load data
SearchInit({ scope: scope, set: list.name, list: list, url: defaultUrl });
PaginateInit({ scope: scope, list: list, url: defaultUrl });
@ -65,11 +67,65 @@ function OrganizationsList ($scope, $rootScope, $location, $log, Rest, Alert, Lo
action: action
});
}
scope.finishSelection = function() {
var url;
url = GetBasePath('projects') + $routeParams.project_id + '/organizations/';
scope.queue = [];
scope.$on('callFinished', function() {
// We call the API for each selected row. We need to hang out until all the api
// calls are finished.
if (scope.queue.length == scope.selected.length) {
// All the api calls finished
scope.selected = [];
var errors = 0;
for (var i=0; i < scope.queue.length; i++) {
if (scope.queue[i].result == 'error') {
errors++;
}
}
if (errors > 0) {
Alert('Error', 'There was an error while adding one or more of the selected organizations.');
}
else {
ReturnToCaller(1);
}
}
});
if (scope.selected.length > 0 ) {
var org;
for (var i=0; i < scope.selected.length; i++) {
org = null;
for (var j=0; j < scope.organizations.length; j++) {
if (scope.organizations[j].id == scope.selected[i]) {
org = scope.organizations[j];
}
}
if (org !== null) {
Rest.setUrl(url);
Rest.post(org)
.success( function(data, status, headers, config) {
scope.queue.push({ result: 'success', data: data, status: status });
scope.$emit('callFinished');
})
.error( function(data, status, headers, config) {
scope.queue.push({ result: 'error', data: data, status: status, headers: headers });
scope.$emit('callFinished');
});
}
}
}
else {
ReturnToCaller();
}
}
}
OrganizationsList.$inject=[ '$scope', '$rootScope', '$location', '$log', 'Rest', 'Alert', 'LoadBreadCrumbs', 'Prompt',
OrganizationsList.$inject=[ '$routeParams', '$scope', '$rootScope', '$location', '$log', 'Rest', 'Alert', 'LoadBreadCrumbs', 'Prompt',
'GenerateList', 'OrganizationList', 'SearchInit', 'PaginateInit', 'ClearScope', 'ProcessErrors',
'GetBasePath' ];
'GetBasePath', 'SelectionInit' ];
function OrganizationsAdd ($scope, $rootScope, $compile, $location, $log, $routeParams, OrganizationForm,