mirror of
https://github.com/ansible/awx.git
synced 2026-04-14 06:29:25 -02:30
Ran all controller files through jsbeautifier.org and applied jsHint.
This commit is contained in:
@@ -3,353 +3,383 @@
|
||||
*
|
||||
*
|
||||
* Teams.js
|
||||
*
|
||||
*
|
||||
* Controller functions for the Team model.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
'use strict';
|
||||
|
||||
function TeamsList ($scope, $rootScope, $location, $log, $routeParams, Rest, Alert, TeamList,
|
||||
GenerateList, LoadBreadCrumbs, Prompt, SearchInit, PaginateInit, ReturnToCaller,
|
||||
ClearScope, ProcessErrors, SetTeamListeners, GetBasePath, SelectionInit, Wait, Stream)
|
||||
{
|
||||
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||
//scope.
|
||||
var list = TeamList;
|
||||
var defaultUrl = GetBasePath('teams');
|
||||
var view = GenerateList;
|
||||
var paths = $location.path().replace(/^\//,'').split('/');
|
||||
var mode = (paths[0] == 'teams') ? 'edit' : 'select'; // if base path 'teams', we're here to add/edit teams
|
||||
var scope = view.inject(list, { mode: mode }); // Inject our view
|
||||
scope.selected = [];
|
||||
function TeamsList($scope, $rootScope, $location, $log, $routeParams, Rest, Alert, TeamList, GenerateList, LoadBreadCrumbs,
|
||||
Prompt, SearchInit, PaginateInit, ReturnToCaller, ClearScope, ProcessErrors, SetTeamListeners, GetBasePath, SelectionInit, Wait,
|
||||
Stream) {
|
||||
|
||||
var url = GetBasePath('base') + $location.path() + '/';
|
||||
SelectionInit({ scope: scope, list: list, url: url, returnToCaller: 1 });
|
||||
|
||||
if (scope.removePostRefresh) {
|
||||
scope.removePostRefresh();
|
||||
}
|
||||
scope.removePostRefresh = scope.$on('PostRefresh', function() {
|
||||
// After a refresh, populate the organization name on each row
|
||||
if (scope.teams) {
|
||||
for ( var i=0; i < scope.teams.length; i++) {
|
||||
scope.teams[i].organization_name = scope.teams[i].summary_fields.organization.name;
|
||||
}
|
||||
}
|
||||
});
|
||||
ClearScope('htmlTemplate');
|
||||
|
||||
SearchInit({ scope: scope, set: 'teams', list: list, url: defaultUrl });
|
||||
PaginateInit({ scope: scope, list: list, url: defaultUrl });
|
||||
var list = TeamList,
|
||||
defaultUrl = GetBasePath('teams'),
|
||||
view = GenerateList,
|
||||
paths = $location.path().replace(/^\//, '').split('/'),
|
||||
mode = (paths[0] === 'teams') ? 'edit' : 'select', // if base path 'teams', we're here to add/edit teams
|
||||
scope = view.inject(list, { mode: mode }),
|
||||
url;
|
||||
|
||||
scope.selected = [];
|
||||
|
||||
url = GetBasePath('base') + $location.path() + '/';
|
||||
SelectionInit({
|
||||
scope: scope,
|
||||
list: list,
|
||||
url: url,
|
||||
returnToCaller: 1
|
||||
});
|
||||
|
||||
if (scope.removePostRefresh) {
|
||||
scope.removePostRefresh();
|
||||
}
|
||||
scope.removePostRefresh = scope.$on('PostRefresh', function () {
|
||||
// After a refresh, populate the organization name on each row
|
||||
var i;
|
||||
if (scope.teams) {
|
||||
for (i = 0; i < scope.teams.length; i++) {
|
||||
scope.teams[i].organization_name = scope.teams[i].summary_fields.organization.name;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
SearchInit({
|
||||
scope: scope,
|
||||
set: 'teams',
|
||||
list: list,
|
||||
url: defaultUrl
|
||||
});
|
||||
PaginateInit({
|
||||
scope: scope,
|
||||
list: list,
|
||||
url: defaultUrl
|
||||
});
|
||||
scope.search(list.iterator);
|
||||
|
||||
LoadBreadCrumbs();
|
||||
|
||||
scope.showActivity = function() { Stream({ scope: scope }); }
|
||||
|
||||
scope.addTeam = function() {
|
||||
$location.path($location.path() + '/add');
|
||||
}
|
||||
scope.showActivity = function () {
|
||||
Stream({
|
||||
scope: scope
|
||||
});
|
||||
};
|
||||
|
||||
scope.editTeam = function(id) {
|
||||
$location.path($location.path() + '/' + id);
|
||||
}
|
||||
|
||||
scope.deleteTeam = function(id, name) {
|
||||
|
||||
var action = function() {
|
||||
Wait('start');
|
||||
var url = defaultUrl + id + '/';
|
||||
Rest.setUrl(url);
|
||||
Rest.destroy()
|
||||
.success( function(data, status, headers, config) {
|
||||
Wait('stop');
|
||||
$('#prompt-modal').modal('hide');
|
||||
scope.search(list.iterator);
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
Wait('stop');
|
||||
$('#prompt-modal').modal('hide');
|
||||
ProcessErrors(scope, data, status, null,
|
||||
{ hdr: 'Error!', msg: 'Call to ' + url + ' failed. DELETE returned status: ' + status });
|
||||
});
|
||||
};
|
||||
scope.addTeam = function () {
|
||||
$location.path($location.path() + '/add');
|
||||
};
|
||||
|
||||
Prompt({ hdr: 'Delete',
|
||||
body: 'Are you sure you want to delete ' + name + '?',
|
||||
action: action
|
||||
scope.editTeam = function (id) {
|
||||
$location.path($location.path() + '/' + id);
|
||||
};
|
||||
|
||||
scope.deleteTeam = function (id, name) {
|
||||
|
||||
var action = function () {
|
||||
Wait('start');
|
||||
var url = defaultUrl + id + '/';
|
||||
Rest.setUrl(url);
|
||||
Rest.destroy()
|
||||
.success(function () {
|
||||
Wait('stop');
|
||||
$('#prompt-modal').modal('hide');
|
||||
scope.search(list.iterator);
|
||||
})
|
||||
.error(function (data, status) {
|
||||
Wait('stop');
|
||||
$('#prompt-modal').modal('hide');
|
||||
ProcessErrors(scope, data, status, null, {
|
||||
hdr: 'Error!',
|
||||
msg: 'Call to ' + url + ' failed. DELETE returned status: ' + status
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
scope.lookupOrganization = function(organization_id) {
|
||||
Rest.setUrl(GetBasePath('organizations') + organization_id + '/');
|
||||
Rest.get()
|
||||
.success( function(data, status, headers, config) {
|
||||
return data.name;
|
||||
});
|
||||
}
|
||||
*/
|
||||
|
||||
};
|
||||
|
||||
Prompt({
|
||||
hdr: 'Delete',
|
||||
body: 'Are you sure you want to delete ' + name + '?',
|
||||
action: action
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
TeamsList.$inject = [ '$scope', '$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'TeamList', 'GenerateList',
|
||||
'LoadBreadCrumbs', 'Prompt', 'SearchInit', 'PaginateInit', 'ReturnToCaller', 'ClearScope', 'ProcessErrors',
|
||||
'SetTeamListeners', 'GetBasePath', 'SelectionInit', 'Wait', 'Stream' ];
|
||||
TeamsList.$inject = ['$scope', '$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'TeamList', 'GenerateList',
|
||||
'LoadBreadCrumbs', 'Prompt', 'SearchInit', 'PaginateInit', 'ReturnToCaller', 'ClearScope', 'ProcessErrors',
|
||||
'SetTeamListeners', 'GetBasePath', 'SelectionInit', 'Wait', 'Stream'
|
||||
];
|
||||
|
||||
|
||||
function TeamsAdd ($scope, $rootScope, $compile, $location, $log, $routeParams, TeamForm, GenerateForm,
|
||||
Rest, Alert, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope, GenerateList,
|
||||
OrganizationList, SearchInit, PaginateInit, GetBasePath, LookUpInit, Wait)
|
||||
{
|
||||
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||
//scope.
|
||||
function TeamsAdd($scope, $rootScope, $compile, $location, $log, $routeParams, TeamForm, GenerateForm,
|
||||
Rest, Alert, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope, GenerateList,
|
||||
OrganizationList, SearchInit, PaginateInit, GetBasePath, LookUpInit, Wait) {
|
||||
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||
//scope.
|
||||
|
||||
// Inject dynamic view
|
||||
var defaultUrl = GetBasePath('teams');
|
||||
var form = TeamForm;
|
||||
var generator = GenerateForm;
|
||||
var scope = generator.inject(form, {mode: 'add', related: false});
|
||||
$rootScope.flashMessage = null;
|
||||
generator.reset();
|
||||
LoadBreadCrumbs();
|
||||
|
||||
LookUpInit({
|
||||
scope: scope,
|
||||
form: form,
|
||||
current_item: null,
|
||||
list: OrganizationList,
|
||||
field: 'organization'
|
||||
});
|
||||
|
||||
// Save
|
||||
scope.formSave = function() {
|
||||
generator.clearApiErrors();
|
||||
Wait('start');
|
||||
Rest.setUrl(defaultUrl);
|
||||
var data = {}
|
||||
for (var fld in form.fields) {
|
||||
data[fld] = scope[fld];
|
||||
}
|
||||
Rest.post(data)
|
||||
.success( function(data, status, headers, config) {
|
||||
Wait('stop');
|
||||
$rootScope.flashMessage = "New team successfully created!";
|
||||
$location.path('/teams/' + data.id);
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
Wait('stop');
|
||||
ProcessErrors(scope, data, status, form,
|
||||
{ hdr: 'Error!', msg: 'Failed to add new team. Post returned status: ' + status });
|
||||
});
|
||||
};
|
||||
// Inject dynamic view
|
||||
var defaultUrl = GetBasePath('teams'),
|
||||
form = TeamForm,
|
||||
generator = GenerateForm,
|
||||
scope = generator.inject(form, { mode: 'add', related: false });
|
||||
|
||||
$rootScope.flashMessage = null;
|
||||
generator.reset();
|
||||
LoadBreadCrumbs();
|
||||
|
||||
// Reset
|
||||
scope.formReset = function() {
|
||||
// Defaults
|
||||
generator.reset();
|
||||
};
|
||||
LookUpInit({
|
||||
scope: scope,
|
||||
form: form,
|
||||
current_item: null,
|
||||
list: OrganizationList,
|
||||
field: 'organization'
|
||||
});
|
||||
|
||||
// Save
|
||||
scope.formSave = function () {
|
||||
var fld, data;
|
||||
generator.clearApiErrors();
|
||||
Wait('start');
|
||||
Rest.setUrl(defaultUrl);
|
||||
data = {};
|
||||
for (fld in form.fields) {
|
||||
data[fld] = scope[fld];
|
||||
}
|
||||
Rest.post(data)
|
||||
.success(function (data) {
|
||||
Wait('stop');
|
||||
$rootScope.flashMessage = "New team successfully created!";
|
||||
$location.path('/teams/' + data.id);
|
||||
})
|
||||
.error(function (data, status) {
|
||||
Wait('stop');
|
||||
ProcessErrors(scope, data, status, form, { hdr: 'Error!', msg: 'Failed to add new team. Post returned status: ' +
|
||||
status });
|
||||
});
|
||||
};
|
||||
|
||||
// Reset
|
||||
scope.formReset = function () {
|
||||
// Defaults
|
||||
generator.reset();
|
||||
};
|
||||
}
|
||||
|
||||
TeamsAdd.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'TeamForm', 'GenerateForm',
|
||||
'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope', 'GenerateList',
|
||||
'OrganizationList', 'SearchInit', 'PaginateInit', 'GetBasePath', 'LookUpInit', 'Wait'];
|
||||
TeamsAdd.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'TeamForm', 'GenerateForm',
|
||||
'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope', 'GenerateList',
|
||||
'OrganizationList', 'SearchInit', 'PaginateInit', 'GetBasePath', 'LookUpInit', 'Wait'
|
||||
];
|
||||
|
||||
|
||||
function TeamsEdit ($scope, $rootScope, $compile, $location, $log, $routeParams, TeamForm,
|
||||
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit,
|
||||
RelatedPaginateInit, ReturnToCaller, ClearScope, LookUpInit, Prompt,
|
||||
GetBasePath, CheckAccess, OrganizationList, Wait, Stream)
|
||||
{
|
||||
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||
//scope.
|
||||
function TeamsEdit($scope, $rootScope, $compile, $location, $log, $routeParams, TeamForm,
|
||||
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit,
|
||||
RelatedPaginateInit, ReturnToCaller, ClearScope, LookUpInit, Prompt,
|
||||
GetBasePath, CheckAccess, OrganizationList, Wait, Stream) {
|
||||
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||
//scope.
|
||||
|
||||
var defaultUrl=GetBasePath('teams');
|
||||
var generator = GenerateForm;
|
||||
var form = TeamForm;
|
||||
var scope = generator.inject(form, {mode: 'edit', related: true});
|
||||
generator.reset();
|
||||
|
||||
var base = $location.path().replace(/^\//,'').split('/')[0];
|
||||
var master = {};
|
||||
var id = $routeParams.team_id;
|
||||
var relatedSets = {};
|
||||
var defaultUrl = GetBasePath('teams'),
|
||||
generator = GenerateForm,
|
||||
form = TeamForm,
|
||||
scope = generator.inject(form, { mode: 'edit', related: true }),
|
||||
base = $location.path().replace(/^\//, '').split('/')[0],
|
||||
master = {},
|
||||
id = $routeParams.team_id,
|
||||
relatedSets = {};
|
||||
|
||||
scope.PermissionAddAllowed = false;
|
||||
|
||||
// Retrieve each related set and any lookups
|
||||
if (scope.teamLoadedRemove) {
|
||||
scope.teamLoadedRemove();
|
||||
}
|
||||
scope.teamLoadedRemove = scope.$on('teamLoaded', function() {
|
||||
CheckAccess({ scope: scope });
|
||||
Rest.setUrl(scope['organization_url']);
|
||||
Rest.get()
|
||||
.success( function(data, status, headers, config) {
|
||||
scope['organization_name'] = data.name;
|
||||
master['organization_name'] = data.name;
|
||||
Wait('stop');
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, null,
|
||||
{ hdr: 'Error!', msg: 'Failed to retrieve organization: ' + scope.orgnization_url + '. GET status: ' + status });
|
||||
});
|
||||
for (var set in relatedSets) {
|
||||
scope.search(relatedSets[set].iterator);
|
||||
}
|
||||
});
|
||||
generator.reset();
|
||||
|
||||
// Retrieve detail record and prepopulate the form
|
||||
Wait('start');
|
||||
Rest.setUrl(defaultUrl + ':id/');
|
||||
Rest.get({ params: {id: id} })
|
||||
.success( function(data, status, headers, config) {
|
||||
LoadBreadCrumbs({ path: '/teams/' + id, title: data.name });
|
||||
for (var fld in form.fields) {
|
||||
if (data[fld]) {
|
||||
scope[fld] = data[fld];
|
||||
master[fld] = scope[fld];
|
||||
}
|
||||
}
|
||||
var related = data.related;
|
||||
for (var set in form.related) {
|
||||
if (related[set]) {
|
||||
relatedSets[set] = { url: related[set], iterator: form.related[set].iterator };
|
||||
}
|
||||
}
|
||||
// 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 });
|
||||
scope.PermissionAddAllowed = false;
|
||||
|
||||
LookUpInit({
|
||||
scope: scope,
|
||||
form: form,
|
||||
current_item: data['organization'],
|
||||
list: OrganizationList,
|
||||
field: 'organization'
|
||||
});
|
||||
// Retrieve each related set and any lookups
|
||||
if (scope.teamLoadedRemove) {
|
||||
scope.teamLoadedRemove();
|
||||
}
|
||||
scope.teamLoadedRemove = scope.$on('teamLoaded', function () {
|
||||
CheckAccess({ scope: scope });
|
||||
Rest.setUrl(scope.organization_url);
|
||||
Rest.get()
|
||||
.success(function (data) {
|
||||
scope.organization_name = data.name;
|
||||
master.organization_name = data.name;
|
||||
Wait('stop');
|
||||
})
|
||||
.error(function (data, status) {
|
||||
ProcessErrors(scope, data, status, null, { hdr: 'Error!', msg: 'Failed to retrieve organization: ' +
|
||||
scope.orgnization_url + '. GET status: ' + status });
|
||||
});
|
||||
for (var set in relatedSets) {
|
||||
scope.search(relatedSets[set].iterator);
|
||||
}
|
||||
});
|
||||
|
||||
scope['organization_url'] = data.related.organization;
|
||||
scope.$emit('teamLoaded');
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, form,
|
||||
{ hdr: 'Error!', msg: 'Failed to retrieve team: ' + $routeParams.team_id + '. GET status: ' + status });
|
||||
});
|
||||
// Retrieve detail record and prepopulate the form
|
||||
Wait('start');
|
||||
Rest.setUrl(defaultUrl + ':id/');
|
||||
Rest.get({
|
||||
params: {
|
||||
id: id
|
||||
}
|
||||
})
|
||||
.success(function (data) {
|
||||
var fld, related, set;
|
||||
LoadBreadCrumbs({ path: '/teams/' + id, title: data.name });
|
||||
for (fld in form.fields) {
|
||||
if (data[fld]) {
|
||||
scope[fld] = data[fld];
|
||||
master[fld] = scope[fld];
|
||||
}
|
||||
}
|
||||
related = data.related;
|
||||
for (set in form.related) {
|
||||
if (related[set]) {
|
||||
relatedSets[set] = {
|
||||
url: related[set],
|
||||
iterator: form.related[set].iterator
|
||||
};
|
||||
}
|
||||
}
|
||||
// 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
|
||||
});
|
||||
|
||||
scope.showActivity = function() { Stream({ scope: scope }); }
|
||||
|
||||
// Save changes to the parent
|
||||
scope.formSave = function() {
|
||||
generator.clearApiErrors();
|
||||
Wait('start');
|
||||
$rootScope.flashMessage = null;
|
||||
Rest.setUrl(defaultUrl + $routeParams.team_id +'/');
|
||||
var data = {}
|
||||
for (var fld in form.fields) {
|
||||
data[fld] = scope[fld];
|
||||
}
|
||||
Rest.put(data)
|
||||
.success( function(data, status, headers, config) {
|
||||
Wait('stop');
|
||||
var base = $location.path().replace(/^\//,'').split('/')[0];
|
||||
(base == 'teams') ? ReturnToCaller() : ReturnToCaller(1);
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
Wait('stop');
|
||||
ProcessErrors(scope, data, status, form,
|
||||
{ hdr: 'Error!', msg: 'Failed to update team: ' + $routeParams.team_id + '. PUT status: ' + status });
|
||||
});
|
||||
};
|
||||
LookUpInit({
|
||||
scope: scope,
|
||||
form: form,
|
||||
current_item: data.organization,
|
||||
list: OrganizationList,
|
||||
field: 'organization'
|
||||
});
|
||||
|
||||
// Cancel
|
||||
scope.formReset = function() {
|
||||
$rootScope.flashMessage = null;
|
||||
generator.reset();
|
||||
for (var fld in master) {
|
||||
scope[fld] = master[fld];
|
||||
}
|
||||
};
|
||||
scope.organization_url = data.related.organization;
|
||||
scope.$emit('teamLoaded');
|
||||
})
|
||||
.error(function (data, status) {
|
||||
ProcessErrors(scope, data, status, form, { hdr: 'Error!', msg: 'Failed to retrieve team: ' + $routeParams.team_id +
|
||||
'. GET status: ' + status });
|
||||
});
|
||||
|
||||
// Related set: Add button
|
||||
scope.add = function(set) {
|
||||
$rootScope.flashMessage = null;
|
||||
if (set == 'permissions') {
|
||||
if (scope.PermissionAddAllowed) {
|
||||
$location.path('/' + base + '/' + $routeParams.team_id + '/' + set + '/add');
|
||||
}
|
||||
else {
|
||||
Alert('Access Denied', 'You do not have access to this function. Please contact your system administrator.');
|
||||
}
|
||||
}
|
||||
else {
|
||||
$location.path('/' + base + '/' + $routeParams.team_id + '/' + set);
|
||||
}
|
||||
};
|
||||
scope.showActivity = function () {
|
||||
Stream({
|
||||
scope: scope
|
||||
});
|
||||
};
|
||||
|
||||
// Related set: Edit button
|
||||
scope.edit = function(set, id, name) {
|
||||
$rootScope.flashMessage = null;
|
||||
if (set == 'permissions') {
|
||||
$location.path('/' + base + '/' + $routeParams.team_id + '/' + set + '/' + id);
|
||||
}
|
||||
else {
|
||||
$location.path('/' + set + '/' + id);
|
||||
}
|
||||
};
|
||||
// Save changes to the parent
|
||||
scope.formSave = function () {
|
||||
var data = {}, fld;
|
||||
generator.clearApiErrors();
|
||||
Wait('start');
|
||||
$rootScope.flashMessage = null;
|
||||
Rest.setUrl(defaultUrl + $routeParams.team_id + '/');
|
||||
for (fld in form.fields) {
|
||||
data[fld] = scope[fld];
|
||||
}
|
||||
Rest.put(data)
|
||||
.success(function () {
|
||||
Wait('stop');
|
||||
var base = $location.path().replace(/^\//, '').split('/')[0];
|
||||
if (base === 'teams') {
|
||||
ReturnToCaller();
|
||||
}
|
||||
ReturnToCaller(1);
|
||||
})
|
||||
.error(function (data, status) {
|
||||
Wait('stop');
|
||||
ProcessErrors(scope, data, status, form, { hdr: 'Error!',
|
||||
msg: 'Failed to update team: ' + $routeParams.team_id + '. PUT status: ' + status });
|
||||
});
|
||||
};
|
||||
|
||||
// Related set: Delete button
|
||||
scope['delete'] = function(set, itm_id, name, title) {
|
||||
$rootScope.flashMessage = null;
|
||||
|
||||
var action = function() {
|
||||
var url;
|
||||
if (set == 'permissions') {
|
||||
if (scope.PermissionAddAllowed) {
|
||||
url = GetBasePath('base') + 'permissions/' + itm_id + '/';
|
||||
Rest.setUrl(url);
|
||||
Rest.destroy()
|
||||
.success( function(data, status, headers, config) {
|
||||
$('#prompt-modal').modal('hide');
|
||||
scope.search(form.related[set].iterator);
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
$('#prompt-modal').modal('hide');
|
||||
ProcessErrors(scope, data, status, null,
|
||||
{ hdr: 'Error!', msg: 'Call to ' + url + ' failed. DELETE returned status: ' + status });
|
||||
// Cancel
|
||||
scope.formReset = function () {
|
||||
$rootScope.flashMessage = null;
|
||||
generator.reset();
|
||||
for (var fld in master) {
|
||||
scope[fld] = master[fld];
|
||||
}
|
||||
};
|
||||
|
||||
// Related set: Add button
|
||||
scope.add = function (set) {
|
||||
$rootScope.flashMessage = null;
|
||||
if (set === 'permissions') {
|
||||
if (scope.PermissionAddAllowed) {
|
||||
$location.path('/' + base + '/' + $routeParams.team_id + '/' + set + '/add');
|
||||
} else {
|
||||
Alert('Access Denied', 'You do not have access to this function. Please contact your system administrator.');
|
||||
}
|
||||
} else {
|
||||
$location.path('/' + base + '/' + $routeParams.team_id + '/' + set);
|
||||
}
|
||||
};
|
||||
|
||||
// Related set: Edit button
|
||||
scope.edit = function (set, id) {
|
||||
$rootScope.flashMessage = null;
|
||||
if (set === 'permissions') {
|
||||
$location.path('/' + base + '/' + $routeParams.team_id + '/' + set + '/' + id);
|
||||
} else {
|
||||
$location.path('/' + set + '/' + id);
|
||||
}
|
||||
};
|
||||
|
||||
// Related set: Delete button
|
||||
scope['delete'] = function (set, itm_id, name, title) {
|
||||
$rootScope.flashMessage = null;
|
||||
|
||||
var action = function () {
|
||||
var url;
|
||||
if (set === 'permissions') {
|
||||
if (scope.PermissionAddAllowed) {
|
||||
url = GetBasePath('base') + 'permissions/' + itm_id + '/';
|
||||
Rest.setUrl(url);
|
||||
Rest.destroy()
|
||||
.success(function () {
|
||||
$('#prompt-modal').modal('hide');
|
||||
scope.search(form.related[set].iterator);
|
||||
})
|
||||
.error(function (data, status) {
|
||||
$('#prompt-modal').modal('hide');
|
||||
ProcessErrors(scope, data, status, null, { hdr: 'Error!', msg: 'Call to ' + url +
|
||||
' failed. DELETE returned status: ' + status });
|
||||
});
|
||||
}
|
||||
else {
|
||||
Alert('Access Denied', 'You do not have access to this function. Please contact your system administrator.');
|
||||
}
|
||||
}
|
||||
else {
|
||||
var url = defaultUrl + $routeParams.team_id + '/' + set + '/';
|
||||
Rest.setUrl(url);
|
||||
Rest.post({ id: itm_id, disassociate: 1 })
|
||||
.success( function(data, status, headers, config) {
|
||||
$('#prompt-modal').modal('hide');
|
||||
scope.search(form.related[set].iterator);
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
$('#prompt-modal').modal('hide');
|
||||
ProcessErrors(scope, data, status, null,
|
||||
{ hdr: 'Error!', msg: 'Call to ' + url + ' failed. POST returned status: ' + status });
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Prompt({ hdr: 'Delete',
|
||||
body: 'Are you sure you want to remove ' + name + ' from ' + scope.name + ' ' + title + '?',
|
||||
action: action
|
||||
});
|
||||
}
|
||||
} else {
|
||||
Alert('Access Denied', 'You do not have access to this function. Please contact your system administrator.');
|
||||
}
|
||||
} else {
|
||||
url = defaultUrl + $routeParams.team_id + '/' + set + '/';
|
||||
Rest.setUrl(url);
|
||||
Rest.post({ id: itm_id, disassociate: 1 })
|
||||
.success(function () {
|
||||
$('#prompt-modal').modal('hide');
|
||||
scope.search(form.related[set].iterator);
|
||||
})
|
||||
.error(function (data, status) {
|
||||
$('#prompt-modal').modal('hide');
|
||||
ProcessErrors(scope, data, status, null, { hdr: 'Error!', msg: 'Call to ' + url +
|
||||
' failed. POST returned status: ' + status });
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Prompt({
|
||||
hdr: 'Delete',
|
||||
body: 'Are you sure you want to remove ' + name + ' from ' + scope.name + ' ' + title + '?',
|
||||
action: action
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
TeamsEdit.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'TeamForm',
|
||||
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit',
|
||||
'RelatedPaginateInit', 'ReturnToCaller', 'ClearScope', 'LookUpInit', 'Prompt',
|
||||
'GetBasePath', 'CheckAccess', 'OrganizationList', 'Wait', 'Stream'
|
||||
];
|
||||
|
||||
TeamsEdit.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'TeamForm',
|
||||
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit', 'RelatedPaginateInit',
|
||||
'ReturnToCaller', 'ClearScope', 'LookUpInit', 'Prompt', 'GetBasePath', 'CheckAccess', 'OrganizationList', 'Wait', 'Stream'
|
||||
];
|
||||
Reference in New Issue
Block a user