mirror of
https://github.com/ansible/awx.git
synced 2026-01-19 13:41:28 -03:30
AC-229 making multi-select across pages work
This commit is contained in:
parent
9af163691a
commit
419e18d1f8
@ -12,104 +12,24 @@
|
||||
|
||||
function AdminsList ($scope, $rootScope, $location, $log, $routeParams, Rest,
|
||||
Alert, AdminList, GenerateList, LoadBreadCrumbs, Prompt, SearchInit, PaginateInit,
|
||||
ReturnToCaller,GetBasePath)
|
||||
ReturnToCaller,GetBasePath, SelectionInit)
|
||||
{
|
||||
var list = AdminList;
|
||||
var defaultUrl = GetBasePath('organizations') + $routeParams.organization_id + '/users/' ;
|
||||
var view = GenerateList;
|
||||
var mode = 'select';
|
||||
var scope = view.inject(AdminList, { mode: mode }); // Inject our view
|
||||
scope.selected = [];
|
||||
|
||||
if (scope.PostRefreshRemove) {
|
||||
scope.PostRefreshRemove();
|
||||
}
|
||||
scope.PostRefreshRemove = scope.$on('PostRefresh', function() {
|
||||
$("tr.success").each(function(index) {
|
||||
// Make sure no rows have a green background
|
||||
var ngc = $(this).attr('ng-class');
|
||||
scope[ngc] = "";
|
||||
});
|
||||
});
|
||||
|
||||
var url = GetBasePath('organizations') + $routeParams.organization_id + '/admins/';
|
||||
SelectionInit({ scope: scope, list: list, url: url, returnToCaller: 1 });
|
||||
|
||||
SearchInit({ scope: scope, set: 'admins', list: list, url: defaultUrl });
|
||||
PaginateInit({ scope: scope, list: list, url: defaultUrl });
|
||||
scope.search(list.iterator);
|
||||
|
||||
LoadBreadCrumbs();
|
||||
|
||||
scope.finishSelection = function() {
|
||||
var url = GetBasePath('organizations') + $routeParams.organization_id + '/admins/'
|
||||
Rest.setUrl(url);
|
||||
scope.queue = [];
|
||||
|
||||
scope.$on('callFinished', function() {
|
||||
// We call the API for each selected user. We need to hang out until all the api
|
||||
// calls are finished.
|
||||
if (scope.queue.length == scope.selected.length) {
|
||||
// All the api calls finished
|
||||
$('input[type="checkbox"]').prop("checked",false);
|
||||
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 users.');
|
||||
}
|
||||
else {
|
||||
ReturnToCaller(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (scope.selected.length > 0 ) {
|
||||
var user;
|
||||
for (var i=0; i < scope.selected.length; i++) {
|
||||
user = null;
|
||||
for (var j=0; j < scope.admins.length; j++) {
|
||||
if (scope.admins[j].id == scope.selected[i]) {
|
||||
user = scope.admins[j];
|
||||
}
|
||||
}
|
||||
if (user !== null) {
|
||||
Rest.post(user)
|
||||
.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(1);
|
||||
}
|
||||
}
|
||||
|
||||
scope.toggle_admin = function(id) {
|
||||
if (scope[list.iterator + "_" + id + "_class"] == "success") {
|
||||
scope[list.iterator + "_" + id + "_class"] = "";
|
||||
document.getElementById('check_' + id).checked = false;
|
||||
if (scope.selected.indexOf(id) > -1) {
|
||||
scope.selected.splice(scope.selected.indexOf(id),1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
scope[list.iterator + "_" + id + "_class"] = "success";
|
||||
document.getElementById('check_' + id).checked = true;
|
||||
if (scope.selected.indexOf(id) == -1) {
|
||||
scope.selected.push(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AdminsList.$inject = [ '$scope', '$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'AdminList', 'GenerateList',
|
||||
'LoadBreadCrumbs', 'Prompt', 'SearchInit', 'PaginateInit', 'ReturnToCaller', 'GetBasePath'];
|
||||
'LoadBreadCrumbs', 'Prompt', 'SearchInit', 'PaginateInit', 'ReturnToCaller', 'GetBasePath', 'SelectionInit'];
|
||||
|
||||
|
||||
@ -24,7 +24,10 @@ function CredentialsList ($scope, $rootScope, $location, $log, $routeParams, Res
|
||||
var scope = view.inject(list, { mode: mode }); // Inject our view
|
||||
scope.selected = [];
|
||||
|
||||
SelectionInit({ scope: scope, list: list });
|
||||
var url = GetBasePath(base);
|
||||
url += (base == 'users') ? $routeParams.user_id + '/credentials/' : $routeParams.team_id + '/credentials/';
|
||||
|
||||
SelectionInit({ scope: scope, list: list, url: url, returnToCaller: 1 });
|
||||
|
||||
SearchInit({ scope: scope, set: 'credentials', list: list, url: defaultUrl });
|
||||
PaginateInit({ scope: scope, list: list, url: defaultUrl });
|
||||
@ -62,60 +65,6 @@ function CredentialsList ($scope, $rootScope, $location, $log, $routeParams, Res
|
||||
action: action
|
||||
});
|
||||
}
|
||||
|
||||
scope.finishSelection = function() {
|
||||
var url = GetBasePath(base);
|
||||
url += (base == 'users') ? $routeParams.user_id + '/credentials/' : $routeParams.team_id + '/credentials/';
|
||||
Rest.setUrl(url);
|
||||
scope.queue = [];
|
||||
|
||||
scope.$on('callFinished', function() {
|
||||
// We call the API for each selected user. We need to hang out until all the api
|
||||
// calls are finished.
|
||||
if (scope.queue.length == scope.selected.length) {
|
||||
// All the api calls finished
|
||||
$('input[type="checkbox"]').prop("checked",false);
|
||||
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 Credentials.');
|
||||
}
|
||||
else {
|
||||
ReturnToCaller(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (scope.selected.length > 0 ) {
|
||||
var credential = null;
|
||||
for (var i=0; i < scope.selected.length; i++) {
|
||||
for (var j=0; j < scope.credentials.length; j++) {
|
||||
if (scope.credentials[j].id == scope.selected[i]) {
|
||||
credential = scope.credentials[j];
|
||||
}
|
||||
}
|
||||
if (credential !== null) {
|
||||
Rest.post(credential)
|
||||
.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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CredentialsList.$inject = [ '$scope', '$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'CredentialList', 'GenerateList',
|
||||
|
||||
@ -22,20 +22,9 @@ function InventoriesList ($scope, $rootScope, $location, $log, $routeParams, Res
|
||||
var paths = $location.path().replace(/^\//,'').split('/');
|
||||
var mode = (paths[0] == 'inventories') ? 'edit' : 'select'; // if base path 'users', we're here to add/edit users
|
||||
var scope = view.inject(InventoryList, { mode: mode }); // Inject our view
|
||||
scope.selected = [];
|
||||
|
||||
$rootScope.flashMessage = null;
|
||||
|
||||
if (scope.PostRefreshRemove) {
|
||||
scope.PostRefreshRemove();
|
||||
}
|
||||
scope.PostRefreshRemove = scope.$on('PostRefresh', function() {
|
||||
$("tr.success").each(function(index) {
|
||||
// Make sure no rows have a green background
|
||||
var ngc = $(this).attr('ng-class');
|
||||
scope[ngc] = "";
|
||||
});
|
||||
});
|
||||
|
||||
SearchInit({ scope: scope, set: 'inventories', list: list, url: defaultUrl });
|
||||
PaginateInit({ scope: scope, list: list, url: defaultUrl });
|
||||
scope.search(list.iterator);
|
||||
@ -81,75 +70,6 @@ function InventoriesList ($scope, $rootScope, $location, $log, $routeParams, Res
|
||||
});
|
||||
}
|
||||
|
||||
scope.finishSelection = function() {
|
||||
Rest.setUrl('/api/v1' + $location.path() + '/'); // We're assuming the path matches the api path.
|
||||
// Will this always be true??
|
||||
scope.queue = [];
|
||||
|
||||
scope.$on('callFinished', function() {
|
||||
// We call the API for each selected user. We need to hang out until all the api
|
||||
// calls are finished.
|
||||
if (scope.queue.length == scope.selected.length) {
|
||||
// All the api calls finished
|
||||
$('input[type="checkbox"]').prop("checked",false);
|
||||
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 inventories.');
|
||||
}
|
||||
else {
|
||||
ReturnToCaller(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (scope.selected.length > 0 ) {
|
||||
var inventory = null;
|
||||
for (var i=0; i < scope.selected.length; i++) {
|
||||
for (var j=0; j < scope.inventories.length; j++) {
|
||||
if (scope.inventories[j].id == scope.selected[i]) {
|
||||
inventory = scope.inventories[j];
|
||||
}
|
||||
}
|
||||
if (inventory !== null) {
|
||||
Rest.post(inventory)
|
||||
.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();
|
||||
}
|
||||
}
|
||||
|
||||
scope.toggle_inventory = function(id) {
|
||||
if (scope[list.iterator + "_" + id + "_class"] == "success") {
|
||||
scope[list.iterator + "_" + id + "_class"] = "";
|
||||
document.getElementById('check_' + id).checked = false;
|
||||
if (scope.selected.indexOf(id) > -1) {
|
||||
scope.selected.splice(scope.selected.indexOf(id),1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
scope[list.iterator + "_" + id + "_class"] = "success";
|
||||
document.getElementById('check_' + id).checked = true;
|
||||
if (scope.selected.indexOf(id) == -1) {
|
||||
scope.selected.push(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Failed jobs link. Go to the jobs tabs, find all jobs for the inventory and sort by status
|
||||
scope.viewJobs = function(id) {
|
||||
|
||||
@ -24,7 +24,6 @@ function JobTemplatesList ($scope, $rootScope, $location, $log, $routeParams, Re
|
||||
var mode = (base == 'job_templates') ? 'edit' : 'select';
|
||||
var scope = view.inject(list, { mode: mode });
|
||||
$rootScope.flashMessage = null;
|
||||
scope.selected = [];
|
||||
|
||||
SearchInit({ scope: scope, set: 'job_templates', list: list, url: defaultUrl });
|
||||
PaginateInit({ scope: scope, list: list, url: defaultUrl });
|
||||
@ -62,61 +61,6 @@ function JobTemplatesList ($scope, $rootScope, $location, $log, $routeParams, Re
|
||||
});
|
||||
}
|
||||
|
||||
scope.finishSelection = function() {
|
||||
Rest.setUrl(defaultUrl);
|
||||
scope.queue = [];
|
||||
|
||||
if (scope.callFinishedRemove) {
|
||||
scope.callFinishedRemove();
|
||||
}
|
||||
scope.callFinishedRemove = scope.$on('callFinished', function() {
|
||||
// We call the API for each selected user. We need to hang out until all the api
|
||||
// calls are finished.
|
||||
if (scope.queue.length == scope.selected.length) {
|
||||
// All the api calls finished
|
||||
$('input[type="checkbox"]').prop("checked",false);
|
||||
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 templates.');
|
||||
}
|
||||
else {
|
||||
ReturnToCaller(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (scope.selected.length > 0 ) {
|
||||
var template = null;
|
||||
for (var i=0; i < scope.selected.length; i++) {
|
||||
for (var j=0; j < scope.job_templates.length; j++) {
|
||||
if (scope.job_templates[j].id == scope.selected[i]) {
|
||||
template = scope.job_templates[j];
|
||||
}
|
||||
}
|
||||
if (template !== null) {
|
||||
Rest.post(template)
|
||||
.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(1);
|
||||
}
|
||||
}
|
||||
|
||||
scope.submitJob = function(id) {
|
||||
SubmitJob({ scope: scope, id: id });
|
||||
}
|
||||
|
||||
@ -28,15 +28,14 @@ function OrganizationsList ($routeParams, $scope, $rootScope, $location, $log, R
|
||||
|
||||
LoadBreadCrumbs();
|
||||
|
||||
SelectionInit({ scope: scope, list: list });
|
||||
var url = GetBasePath('projects') + $routeParams.project_id + '/organizations/';
|
||||
SelectionInit({ scope: scope, list: list, url: url, returnToCaller: 1 });
|
||||
|
||||
// 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 });
|
||||
scope.search(list.iterator);
|
||||
|
||||
//getData();
|
||||
|
||||
scope.addOrganization = function() {
|
||||
$location.path($location.path() + '/add');
|
||||
}
|
||||
@ -67,60 +66,6 @@ function OrganizationsList ($routeParams, $scope, $rootScope, $location, $log, R
|
||||
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=[ '$routeParams', '$scope', '$rootScope', '$location', '$log', 'Rest', 'Alert', 'LoadBreadCrumbs', 'Prompt',
|
||||
|
||||
@ -22,10 +22,10 @@ function ProjectsList ($scope, $rootScope, $location, $log, $routeParams, Rest,
|
||||
var base = $location.path().replace(/^\//,'').split('/')[0];
|
||||
var mode = (base == 'projects') ? 'edit' : 'select';
|
||||
var scope = view.inject(list, { mode: mode });
|
||||
scope.selected = [];
|
||||
$rootScope.flashMessage = null;
|
||||
|
||||
SelectionInit({ scope: scope, list: list });
|
||||
|
||||
var url = (base == 'teams') ? GetBasePath('teams') + $routeParams.team_id + '/projects/' : defaultUrl;
|
||||
SelectionInit({ scope: scope, list: list, url: url, returnToCaller: 1 });
|
||||
|
||||
SearchInit({ scope: scope, set: 'projects', list: list, url: defaultUrl });
|
||||
PaginateInit({ scope: scope, list: list, url: defaultUrl });
|
||||
@ -63,62 +63,6 @@ function ProjectsList ($scope, $rootScope, $location, $log, $routeParams, Rest,
|
||||
action: action
|
||||
});
|
||||
}
|
||||
|
||||
scope.finishSelection = function() {
|
||||
var url = (base == 'teams') ? GetBasePath('teams') + $routeParams.team_id + '/projects/' : defaultUrl;
|
||||
Rest.setUrl(url);
|
||||
scope.queue = [];
|
||||
|
||||
if (scope.callFinishedRemove) {
|
||||
scope.callFinishedRemove();
|
||||
}
|
||||
scope.callFinishedRemoved = scope.$on('callFinished', function() {
|
||||
// We call the API for each selected user. We need to hang out until all the api
|
||||
// calls are finished.
|
||||
if (scope.queue.length == scope.selected.length) {
|
||||
// All the api calls finished
|
||||
$('input[type="checkbox"]').prop("checked",false);
|
||||
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 Pojects.');
|
||||
}
|
||||
else {
|
||||
ReturnToCaller(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (scope.selected.length > 0 ) {
|
||||
var project = null;
|
||||
for (var i=0; i < scope.selected.length; i++) {
|
||||
for (var j=0; j < scope.projects.length; j++) {
|
||||
if (scope.projects[j].id == scope.selected[i]) {
|
||||
project = scope.projects[j];
|
||||
}
|
||||
}
|
||||
if (project !== null) {
|
||||
Rest.post(project)
|
||||
.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(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ProjectsList.$inject = [ '$scope', '$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'ProjectList', 'GenerateList',
|
||||
|
||||
@ -24,7 +24,8 @@ function TeamsList ($scope, $rootScope, $location, $log, $routeParams, Rest, Ale
|
||||
var scope = view.inject(list, { mode: mode }); // Inject our view
|
||||
scope.selected = [];
|
||||
|
||||
SelectionInit({ scope: scope, list: list });
|
||||
var url = GetBasePath('base') + $location.path() + '/';
|
||||
SelectionInit({ scope: scope, list: list, url: url, returnToCaller: 1 });
|
||||
|
||||
if (scope.PostRefreshRemove) {
|
||||
scope.PostRefreshRemove();
|
||||
@ -36,7 +37,6 @@ function TeamsList ($scope, $rootScope, $location, $log, $routeParams, Rest, Ale
|
||||
}
|
||||
});
|
||||
|
||||
//SetTeamListeners({ scope: scope, set: 'teams', iterator: list.iterator });
|
||||
SearchInit({ scope: scope, set: 'teams', list: list, url: defaultUrl });
|
||||
PaginateInit({ scope: scope, list: list, url: defaultUrl });
|
||||
scope.search(list.iterator);
|
||||
@ -74,6 +74,7 @@ function TeamsList ($scope, $rootScope, $location, $log, $routeParams, Rest, Ale
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
scope.lookupOrganization = function(organization_id) {
|
||||
Rest.setUrl(GetBasePath('organizations') + organization_id + '/');
|
||||
Rest.get()
|
||||
@ -81,66 +82,8 @@ function TeamsList ($scope, $rootScope, $location, $log, $routeParams, Rest, Ale
|
||||
return data.name;
|
||||
});
|
||||
}
|
||||
|
||||
scope.finishSelection = function() {
|
||||
Rest.setUrl(GetBasePath('base') + $location.path() + '/'); // We're assuming the path matches the api path.
|
||||
// Will this always be true??
|
||||
scope.queue = [];
|
||||
|
||||
scope.$on('callFinished', function() {
|
||||
// We call the API for each selected user. We need to hang out until all the api
|
||||
// calls are finished.
|
||||
if (scope.queue.length == scope.selected.length) {
|
||||
// All the api calls finished
|
||||
$('input[type="checkbox"]').prop("checked",false);
|
||||
scope.selected = [];
|
||||
var errors = 0;
|
||||
for (var i=0; i < scope.queue.length; i++) {
|
||||
if (scope.queue[i].result == 'error') {
|
||||
errors++;
|
||||
// there is no way to know which user raised the error. no data comes
|
||||
// back from the api call.
|
||||
// $('td.username-column').each(function(index) {
|
||||
// if ($(this).text() == scope.queue[i].username) {
|
||||
// $(this).addClass("error");
|
||||
// }
|
||||
// });
|
||||
}
|
||||
}
|
||||
if (errors > 0) {
|
||||
Alert('Error', 'There was an error while adding one or more of the selected teams.');
|
||||
}
|
||||
else {
|
||||
ReturnToCaller(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (scope.selected.length > 0 ) {
|
||||
var team = null;
|
||||
for (var i=0; i < scope.selected.length; i++) {
|
||||
for (var j=0; j < scope.teams.length; j++) {
|
||||
if (scope.teams[j].id == scope.selected[i]) {
|
||||
team = scope.teams[j];
|
||||
}
|
||||
}
|
||||
if (team !== null) {
|
||||
Rest.post(team)
|
||||
.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();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
TeamsList.$inject = [ '$scope', '$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'TeamList', 'GenerateList',
|
||||
@ -150,8 +93,7 @@ TeamsList.$inject = [ '$scope', '$rootScope', '$location', '$log', '$routeParams
|
||||
|
||||
function TeamsAdd ($scope, $rootScope, $compile, $location, $log, $routeParams, TeamForm,
|
||||
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope,
|
||||
GenerateList, OrganizationList, SearchInit, PaginateInit, TeamLookUpOrganizationInit,
|
||||
GetBasePath)
|
||||
GenerateList, OrganizationList, SearchInit, PaginateInit, GetBasePath, LookUpInit)
|
||||
{
|
||||
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||
//scope.
|
||||
@ -164,7 +106,14 @@ function TeamsAdd ($scope, $rootScope, $compile, $location, $log, $routeParams,
|
||||
$rootScope.flashMessage = null;
|
||||
generator.reset();
|
||||
LoadBreadCrumbs();
|
||||
TeamLookUpOrganizationInit({ scope: scope });
|
||||
|
||||
LookUpInit({
|
||||
scope: scope,
|
||||
form: form,
|
||||
current_item: null,
|
||||
list: OrganizationList,
|
||||
field: 'organization'
|
||||
});
|
||||
|
||||
// Save
|
||||
scope.formSave = function() {
|
||||
@ -193,13 +142,14 @@ function TeamsAdd ($scope, $rootScope, $compile, $location, $log, $routeParams,
|
||||
|
||||
TeamsAdd.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'TeamForm', 'GenerateForm',
|
||||
'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope', 'GenerateList',
|
||||
'OrganizationList', 'SearchInit', 'PaginateInit', 'TeamLookUpOrganizationInit', 'GetBasePath'];
|
||||
'OrganizationList', 'SearchInit', 'PaginateInit', 'TeamLookUpOrganizationInit', 'GetBasePath',
|
||||
'LookUpInit' ];
|
||||
|
||||
|
||||
function TeamsEdit ($scope, $rootScope, $compile, $location, $log, $routeParams, TeamForm,
|
||||
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit,
|
||||
RelatedPaginateInit, ReturnToCaller, ClearScope, TeamLookUpOrganizationInit, Prompt,
|
||||
GetBasePath, CheckAccess)
|
||||
RelatedPaginateInit, ReturnToCaller, ClearScope, LookUpInit, Prompt,
|
||||
GetBasePath, CheckAccess, OrganizationList)
|
||||
{
|
||||
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||
//scope.
|
||||
@ -215,8 +165,6 @@ function TeamsEdit ($scope, $rootScope, $compile, $location, $log, $routeParams,
|
||||
var id = $routeParams.team_id;
|
||||
var relatedSets = {};
|
||||
|
||||
TeamLookUpOrganizationInit({ scope: scope });
|
||||
|
||||
// Retrieve each related set and any lookups
|
||||
if (scope.teamLoadedRemove) {
|
||||
scope.teamLoadedRemove();
|
||||
@ -257,6 +205,15 @@ function TeamsEdit ($scope, $rootScope, $compile, $location, $log, $routeParams,
|
||||
// Initialize related search functions. Doing it here to make sure relatedSets object is populated.
|
||||
RelatedSearchInit({ scope: scope, form: form, relatedSets: relatedSets });
|
||||
RelatedPaginateInit({ scope: scope, relatedSets: relatedSets });
|
||||
|
||||
LookUpInit({
|
||||
scope: scope,
|
||||
form: form,
|
||||
current_item: data['organization'],
|
||||
list: OrganizationList,
|
||||
field: 'organization'
|
||||
});
|
||||
|
||||
scope['organization_url'] = data.related.organization;
|
||||
scope.$emit('teamLoaded');
|
||||
})
|
||||
@ -367,7 +324,7 @@ function TeamsEdit ($scope, $rootScope, $compile, $location, $log, $routeParams,
|
||||
|
||||
TeamsEdit.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'TeamForm',
|
||||
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit',
|
||||
'RelatedPaginateInit', 'ReturnToCaller', 'ClearScope', 'TeamLookUpOrganizationInit', 'Prompt',
|
||||
'GetBasePath', 'CheckAccess'
|
||||
'RelatedPaginateInit', 'ReturnToCaller', 'ClearScope', 'LookUpInit', 'Prompt',
|
||||
'GetBasePath', 'CheckAccess', 'OrganizationList'
|
||||
];
|
||||
|
||||
|
||||
@ -31,8 +31,10 @@ function UsersList ($scope, $rootScope, $location, $log, $routeParams, Rest,
|
||||
scope.search(list.iterator);
|
||||
|
||||
LoadBreadCrumbs();
|
||||
|
||||
SelectionInit({ scope: scope, list: list });
|
||||
|
||||
var url = (base == 'organizations') ? GetBasePath('organizations') + $routeParams.organization_id + '/users/' :
|
||||
GetBasePath('teams') + $routeParams.team_id + '/users/';
|
||||
SelectionInit({ scope: scope, list: list, url: url, returnToCaller: 1 });
|
||||
|
||||
scope.addUser = function() {
|
||||
$location.path($location.path() + '/add');
|
||||
@ -64,65 +66,6 @@ function UsersList ($scope, $rootScope, $location, $log, $routeParams, Rest,
|
||||
action: action
|
||||
});
|
||||
}
|
||||
|
||||
scope.finishSelection = function() {
|
||||
var url;
|
||||
if (base == 'organizations') {
|
||||
url = GetBasePath('organizations') + $routeParams.organization_id + '/users/';
|
||||
}
|
||||
else {
|
||||
url = GetBasePath('teams') + $routeParams.team_id + '/users/';
|
||||
}
|
||||
scope.queue = [];
|
||||
scope.$on('callFinished', function() {
|
||||
// We call the API for each selected user. 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 users.');
|
||||
}
|
||||
else {
|
||||
ReturnToCaller(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (scope.selected.length > 0 ) {
|
||||
var user;
|
||||
for (var i=0; i < scope.selected.length; i++) {
|
||||
user = null;
|
||||
for (var j=0; j < scope.users.length; j++) {
|
||||
if (scope.users[j].id == scope.selected[i]) {
|
||||
user = scope.users[j];
|
||||
}
|
||||
}
|
||||
if (user !== null) {
|
||||
Rest.setUrl(url);
|
||||
Rest.post(user)
|
||||
.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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
UsersList.$inject = [ '$scope', '$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'UserList', 'GenerateList',
|
||||
|
||||
@ -41,7 +41,9 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
|
||||
$('#form-modal .btn-none').removeClass('btn-none').addClass('btn-success');
|
||||
$('#form-modal').modal({ backdrop: 'static', keyboard: false });
|
||||
|
||||
SelectionInit({ scope: scope, list: list });
|
||||
var url = (group_id) ? GetBasePath('groups') + group_id + '/children/' :
|
||||
GetBasePath('inventory') + inventory_id + '/groups/';
|
||||
SelectionInit({ scope: scope, list: list, url: url });
|
||||
|
||||
if (scope.PostRefreshRemove) {
|
||||
scope.PostRefreshRemove();
|
||||
@ -62,63 +64,12 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
|
||||
scope.$digest();
|
||||
}
|
||||
|
||||
scope.formModalAction = function() {
|
||||
var url = (group_id) ? GetBasePath('groups') + group_id + '/children/' :
|
||||
GetBasePath('inventory') + inventory_id + '/groups/';
|
||||
Rest.setUrl(url);
|
||||
scope.queue = [];
|
||||
|
||||
if (scope.callFinishedRemove) {
|
||||
scope.callFinishedRemove();
|
||||
}
|
||||
scope.callFinishedRemove = scope.$on('callFinished', function() {
|
||||
// We call the API for each selected item. We need to hang out until all the api
|
||||
// calls are finished.
|
||||
if (scope.queue.length == scope.selected.length) {
|
||||
// All the api calls finished
|
||||
$('input[type="checkbox"]').prop("checked",false);
|
||||
scope.selected = [];
|
||||
var errors = 0;
|
||||
for (var i=0; i < scope.queue.length; i++) {
|
||||
if (scope.queue[i].result == 'error') {
|
||||
ProcessErrors(scope, scope.queue[i].data, scope.queue[i].status, null,
|
||||
{ hdr: 'Group: ' + scope.queue[i].value.name, msg: 'Failed to add group. POST returned status: ' + scope.queue[i].status });
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors == 0) {
|
||||
$('#form-modal').modal('hide');
|
||||
RefreshTree({ scope: scope });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (scope.selected.length > 0 ) {
|
||||
var group;
|
||||
for (var i=0; i < scope.selected.length; i++) {
|
||||
group = null;
|
||||
for (var j=0; j < scope.groups.length; j++) {
|
||||
if (scope.groups[j].id == scope.selected[i]) {
|
||||
group = scope.groups[j];
|
||||
}
|
||||
}
|
||||
if (group !== null) {
|
||||
Rest.post(group)
|
||||
.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, value: group });
|
||||
scope.$emit('callFinished');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$('#form-modal').modal('hide');
|
||||
}
|
||||
}
|
||||
if (scope.removeModalClosed) {
|
||||
scope.removeModalClosed();
|
||||
}
|
||||
scope.removeModalClosed = scope.$on('modalClosed', function() {
|
||||
RefreshTree({ scope: scope });
|
||||
});
|
||||
|
||||
scope.createGroup = function() {
|
||||
$('#form-modal').modal('hide');
|
||||
|
||||
@ -10,13 +10,14 @@
|
||||
angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'HostListDefinition',
|
||||
'SearchHelper', 'PaginateHelper', 'ListGenerator', 'AuthService', 'HostsHelper',
|
||||
'InventoryHelper', 'RelatedSearchHelper','RelatedPaginateHelper',
|
||||
'InventoryFormDefinition'
|
||||
'InventoryFormDefinition', 'SelectionHelper'
|
||||
])
|
||||
|
||||
.factory('HostsList', ['$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'HostList', 'GenerateList',
|
||||
'Prompt', 'SearchInit', 'PaginateInit', 'ProcessErrors', 'GetBasePath', 'HostsAdd', 'HostsReload',
|
||||
'Prompt', 'SearchInit', 'PaginateInit', 'ProcessErrors', 'GetBasePath', 'HostsAdd', 'HostsReload', 'SearchInit',
|
||||
'SelectionInit',
|
||||
function($rootScope, $location, $log, $routeParams, Rest, Alert, HostList, GenerateList, LoadBreadCrumbs, SearchInit,
|
||||
PaginateInit, ProcessErrors, GetBasePath, HostsAdd, HostsReload) {
|
||||
PaginateInit, ProcessErrors, GetBasePath, HostsAdd, HostsReload, SearchInit, SelectionInit) {
|
||||
return function(params) {
|
||||
|
||||
var inventory_id = params.inventory_id;
|
||||
@ -40,11 +41,14 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
|
||||
scope.formModalActionLabel = 'Select';
|
||||
scope.formModalHeader = 'Select Hosts';
|
||||
scope.formModalCancelShow = true;
|
||||
|
||||
SelectionInit({ scope: scope, list: list, url: GetBasePath('groups') + group_id + '/hosts/' });
|
||||
|
||||
if (scope.removeHostsReload) {
|
||||
scope.removeHostsReload();
|
||||
if (scope.removeModalClosed) {
|
||||
scope.removeModalClosed();
|
||||
}
|
||||
scope.removeHostsReload = scope.$on('hostsReload', function() {
|
||||
scope.removeModalClosed = scope.$on('modalClosed', function() {
|
||||
// if the modal cloased, assume something got changed and reload the host list
|
||||
HostsReload(params);
|
||||
});
|
||||
|
||||
@ -52,19 +56,6 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
|
||||
$('#form-modal .btn-none').removeClass('btn-none').addClass('btn-success');
|
||||
$('#form-modal').modal({ backdrop: 'static', keyboard: false });
|
||||
|
||||
scope.selected = [];
|
||||
|
||||
if (scope.PostRefreshRemove) {
|
||||
scope.PostRefreshRemove();
|
||||
}
|
||||
scope.PostRefreshRemove = scope.$on('PostRefresh', function() {
|
||||
$("tr.success").each(function(index) {
|
||||
// Make sure no rows have a green background
|
||||
var ngc = $(this).attr('ng-class');
|
||||
scope[ngc] = "";
|
||||
});
|
||||
});
|
||||
|
||||
SearchInit({ scope: scope, set: 'subhosts', list: list, url: defaultUrl });
|
||||
PaginateInit({ scope: scope, list: list, url: defaultUrl, mode: 'lookup' });
|
||||
scope.search(list.iterator);
|
||||
@ -73,80 +64,6 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
|
||||
scope.$digest();
|
||||
}
|
||||
|
||||
scope.formModalAction = function() {
|
||||
var url = GetBasePath('groups') + group_id + '/hosts/';
|
||||
Rest.setUrl(url);
|
||||
scope.queue = [];
|
||||
|
||||
if (scope.callFinishedRemove) {
|
||||
scope.callFinishedRemove();
|
||||
}
|
||||
scope.callFinishedRemove = scope.$on('callFinished', function() {
|
||||
// We call the API for each selected item. We need to hang out until all the api
|
||||
// calls are finished.
|
||||
if (scope.queue.length == scope.selected.length) {
|
||||
// All the api calls finished
|
||||
$('input[type="checkbox"]').prop("checked",false);
|
||||
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 hosts.');
|
||||
}
|
||||
$('#form-modal').modal('hide');
|
||||
scope.$emit('hostsReload');
|
||||
}
|
||||
});
|
||||
|
||||
if (scope.selected.length > 0 ) {
|
||||
var host;
|
||||
for (var i=0; i < scope.selected.length; i++) {
|
||||
host = null;
|
||||
for (var j=0; j < scope.subhosts.length; j++) {
|
||||
if (scope.subhosts[j].id == scope.selected[i]) {
|
||||
host = scope.subhosts[j];
|
||||
}
|
||||
}
|
||||
if (host !== null) {
|
||||
Rest.post(host)
|
||||
.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 {
|
||||
$('#form-modal').modal('hide');
|
||||
scope.$emit('hostsReload');
|
||||
}
|
||||
}
|
||||
|
||||
scope.toggle_subhost = function(id) {
|
||||
if (scope[list.iterator + "_" + id + "_class"] == "success") {
|
||||
scope[list.iterator + "_" + id + "_class"] = "";
|
||||
document.getElementById('check_' + id).checked = false;
|
||||
if (scope.selected.indexOf(id) > -1) {
|
||||
scope.selected.splice(scope.selected.indexOf(id),1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
scope[list.iterator + "_" + id + "_class"] = "success";
|
||||
document.getElementById('check_' + id).checked = true;
|
||||
if (scope.selected.indexOf(id) == -1) {
|
||||
scope.selected.push(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
scope.createHost = function() {
|
||||
$('#form-modal').modal('hide');
|
||||
HostsAdd({ scope: params.scope, inventory_id: inventory_id, group_id: group_id });
|
||||
@ -197,6 +114,12 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
|
||||
|
||||
// Save
|
||||
scope.formModalAction = function() {
|
||||
|
||||
function finished() {
|
||||
$('#form-modal').modal('hide');
|
||||
scope.$emit('hostsReload');
|
||||
}
|
||||
|
||||
try {
|
||||
// Make sure we have valid variable data
|
||||
if (scope.parseType == 'json') {
|
||||
@ -226,7 +149,7 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
|
||||
Rest.setUrl(data.related.variable_data);
|
||||
Rest.put(json_data)
|
||||
.success( function(data, status, headers, config) {
|
||||
$('#form-modal').modal('hide');
|
||||
finished();
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, form,
|
||||
@ -234,8 +157,7 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
|
||||
});
|
||||
}
|
||||
else {
|
||||
$('#form-modal').modal('hide');
|
||||
scope.$emit('hostsReload');
|
||||
finished();
|
||||
}
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
@ -351,6 +273,12 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
|
||||
|
||||
// Save changes to the parent
|
||||
scope.formModalAction = function() {
|
||||
|
||||
function finished() {
|
||||
$('#form-modal').modal('hide');
|
||||
scope.$emit('hostsReload');
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
// Make sure we have valid variable data
|
||||
@ -379,8 +307,7 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
|
||||
Rest.setUrl(GetBasePath('hosts') + data.id + '/variable_data/');
|
||||
Rest.put(json_data)
|
||||
.success( function(data, status, headers, config) {
|
||||
$('#form-modal').modal('hide');
|
||||
scope.$emit('hostsReload');
|
||||
finished();
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, form,
|
||||
@ -388,8 +315,7 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
|
||||
});
|
||||
}
|
||||
else {
|
||||
$('#form-modal').modal('hide');
|
||||
scope.$emit('hostsReload');
|
||||
finished();
|
||||
}
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
@ -422,7 +348,7 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
|
||||
// Delete the selected host. Disassociates it from the group.
|
||||
|
||||
var scope = params.scope;
|
||||
var group_id = params.group_id;
|
||||
var group_id = scope.group_id;
|
||||
var inventory_id = params.inventory_id;
|
||||
var host_id = params.host_id;
|
||||
var host_name = params.host_name;
|
||||
@ -475,7 +401,7 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
|
||||
return function(params) {
|
||||
// Rerfresh the Hosts view on right side of page
|
||||
scope = params.scope;
|
||||
var url = (scope.group_id !== null) ? GetBasePath('groups') + scope.group_id + '/hosts/' :
|
||||
var url = (scope.group_id !== null) ? GetBasePath('groups') + scope.group_id + '/all_hosts/' :
|
||||
GetBasePath('inventory') + params.inventory_id + '/hosts/';
|
||||
var relatedSets = { hosts: { url: url, iterator: 'host' } };
|
||||
RelatedSearchInit({ scope: params.scope, form: InventoryForm, relatedSets: relatedSets });
|
||||
|
||||
@ -72,6 +72,7 @@ angular.module('LookUpHelper', [ 'RestServices', 'Utilities', 'SearchHelper', 'P
|
||||
}
|
||||
|
||||
listScope['toggle_' + list.iterator] = function(id) {
|
||||
console.log('here!');
|
||||
for (var i=0; i < scope[list.name].length; i++) {
|
||||
if (listScope[list.name][i]['id'] == id) {
|
||||
listScope[list.name][i]['checked'] = '1';
|
||||
|
||||
@ -10,12 +10,16 @@
|
||||
* })
|
||||
*/
|
||||
|
||||
angular.module('SelectionHelper', [])
|
||||
.factory('SelectionInit', [ function() {
|
||||
angular.module('SelectionHelper', ['Utilities', 'RestServices'])
|
||||
|
||||
.factory('SelectionInit', [ 'Rest', 'Alert', 'ProcessErrors', 'ReturnToCaller',
|
||||
function(Rest, Alert, ProcessErrors, ReturnToCaller) {
|
||||
return function(params) {
|
||||
|
||||
var scope = params.scope; // form scope
|
||||
var list = params.list; // list object
|
||||
var scope = params.scope; // current scope
|
||||
var list = params.list; // list object
|
||||
var target_url = params.url; // URL to POST selected objects
|
||||
var returnToCaller = params.returnToCaller;
|
||||
|
||||
scope.selected = []; //array of selected row IDs
|
||||
|
||||
@ -27,30 +31,96 @@ angular.module('SelectionHelper', [])
|
||||
// select the row
|
||||
scope[list.name][i]['checked'] = '1';
|
||||
scope[list.name][i]['success_class'] = 'success';
|
||||
if (scope.selected.indexOf(id) == -1) {
|
||||
// add id to the array
|
||||
scope.selected.push(id);
|
||||
// add selected object to the array
|
||||
var found = false;
|
||||
for (var j=0; j < scope.selected.length; j++) {
|
||||
if (scope.selected[j].id == id) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
scope.selected.push(scope[list.name][i]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// unselect the row
|
||||
scope[list.name][i]['checked'] = '0';
|
||||
scope[list.name][i]['success_class'] = '';
|
||||
if (scope.selected.indexOf(id) > -1) {
|
||||
// remove id from the array
|
||||
scope.selected.splice(scope.selected.indexOf(id),1);
|
||||
// remove selected object from the array
|
||||
for (var j=0; j < scope.selected.length; j++) {
|
||||
if (scope.selected[j].id == id) {
|
||||
scope.selected.splice(j,1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
scope.finishSelection = function() {
|
||||
Rest.setUrl(target_url);
|
||||
scope.queue = [];
|
||||
|
||||
function finished() {
|
||||
scope.selected = [];
|
||||
if (returnToCaller !== undefined) {
|
||||
ReturnToCaller(returnToCaller);
|
||||
}
|
||||
else {
|
||||
$('#form-modal').modal('hide');
|
||||
scope.$emit('modalClosed');
|
||||
}
|
||||
}
|
||||
|
||||
if (scope.callFinishedRemove) {
|
||||
scope.callFinishedRemove();
|
||||
}
|
||||
scope.callFinishedRemove = scope.$on('callFinished', function() {
|
||||
// We call the API for each selected item. We need to hang out until all the api
|
||||
// calls are finished.
|
||||
if (scope.queue.length == scope.selected.length) {
|
||||
var errors = 0;
|
||||
for (var i=0; i < scope.queue.length; i++) {
|
||||
if (scope.queue[i].result == 'error') {
|
||||
ProcessErrors(scope, scope.queue[i].data, scope.queue[i].status, null,
|
||||
{ hdr: 'POST Failure', msg: 'Failed to add ' + list.iterator +
|
||||
'. POST returned status: ' + scope.queue[i].status });
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors == 0) {
|
||||
finished();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (scope.selected.length > 0 ) {
|
||||
for (var j=0; j < scope.selected.length; j++) {
|
||||
Rest.post(scope.selected[j])
|
||||
.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 {
|
||||
finished();
|
||||
}
|
||||
}
|
||||
|
||||
scope.formModalAction = scope.finishSelection;
|
||||
|
||||
// Initialize our data set after a refresh
|
||||
if (scope.SelectPostRefreshRemove) {
|
||||
scope.SelectPostRefreshRemove();
|
||||
}
|
||||
scope.SelectPostRefreshRemove = scope.$on('PostRefresh', function() {
|
||||
scope.selected = [];
|
||||
for (var i=0; i < scope[list.name].length; i++) {
|
||||
scope[list.name][i]['checked'] = '0';
|
||||
scope[list.name][i]['success_class'] = '';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user