Permissions CRUD now functional within Users tab.

This commit is contained in:
chouseknecht
2013-06-25 15:35:57 -04:00
parent 07d151b8cb
commit 9342e01468
10 changed files with 332 additions and 43 deletions

View File

@@ -1,3 +1,64 @@
function PermissionsList ($scope, $rootScope, $location, $log, $routeParams, Rest, Alert, PermissionList,
GenerateList, LoadBreadCrumbs, Prompt, SearchInit, PaginateInit, ReturnToCaller,
ClearScope, ProcessErrors, GetBasePath)
{
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
//scope.
var list = PermissionList;
var base = $location.path().replace(/^\//,'').split('/')[0];
var defaultUrl = GetBasePath(base);
defaultUrl += ($routeParams['user_id'] !== undefined) ? $routeParams['user_id'] : $routeParams['team_id'];
defaultUrl += '/permissions/';
var view = GenerateList;
var scope = view.inject(list, { mode: 'edit' }); // Inject our view
scope.selected = [];
SearchInit({ scope: scope, set: 'permissions', list: list, url: defaultUrl });
PaginateInit({ scope: scope, list: list, url: defaultUrl });
scope.search(list.iterator);
LoadBreadCrumbs();
scope.addPermission = function() {
$location.path($location.path() + '/add');
}
scope.editPermission = function(id) {
$location.path($location.path() + '/' + id);
}
scope.deletePermission = function(id, name) {
var action = function() {
var url = GetBasePath('base') + 'permissions/' + id + '/';
Rest.setUrl(url);
Rest.destroy()
.success( function(data, status, headers, config) {
$('#prompt-modal').modal('hide');
scope.search(list.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 });
});
};
Prompt({ hdr: 'Delete',
body: 'Are you sure you want to delete ' + name + '?',
action: action
});
}
}
PermissionsList.$inject = [ '$scope', '$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'PermissionList',
'GenerateList', 'LoadBreadCrumbs', 'Prompt', 'SearchInit', 'PaginateInit', 'ReturnToCaller',
'ClearScope', 'ProcessErrors', 'GetBasePath'
];
function PermissionsAdd ($scope, $rootScope, $compile, $location, $log, $routeParams, PermissionsForm,
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ClearScope,
GetBasePath, ReturnToCaller, InventoryList, ProjectList, LookUpInit)
@@ -8,7 +69,7 @@ function PermissionsAdd ($scope, $rootScope, $compile, $location, $log, $routePa
// Inject dynamic view
var form = PermissionsForm;
var generator = GenerateForm;
var id = $routeParams.user_id;
var id = ($routeParams.user_id !== undefined) ? $routeParams.user_id : $routeParams.team_id;
var base = $location.path().replace(/^\//,'').split('/')[0];
var defaultUrl = GetBasePath(base) + id + '/permissions';
var scope = generator.inject(form, {mode: 'add', related: false});
@@ -17,8 +78,8 @@ function PermissionsAdd ($scope, $rootScope, $compile, $location, $log, $routePa
generator.reset();
LoadBreadCrumbs();
scope.category = 'i';
master.category = 'i';
scope.category = 'Inventory';
master.category = 'Inventory';
LookUpInit({
scope: scope,
@@ -49,7 +110,7 @@ function PermissionsAdd ($scope, $rootScope, $compile, $location, $log, $routePa
ReturnToCaller(1);
})
.error( function(data, status, headers, config) {
ProcessErrors(scope, data, status, ProjectsForm,
ProcessErrors(scope, data, status, PermissionsForm,
{ hdr: 'Error!', msg: 'Failed to create new permission. Post returned status: ' + status });
});
};
@@ -64,9 +125,110 @@ function PermissionsAdd ($scope, $rootScope, $compile, $location, $log, $routePa
};
}
ProjectsAdd.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'PermissionForm',
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ClearScope', 'GetBasePath',
'ReturnToCaller', 'InventoryList', 'ProjectList', 'LookUpInit'
];
PermissionsAdd.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'PermissionsForm',
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ClearScope', 'GetBasePath',
'ReturnToCaller', 'InventoryList', 'ProjectList', 'LookUpInit'
];
function PermissionsEdit ($scope, $rootScope, $compile, $location, $log, $routeParams, PermissionsForm,
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ReturnToCaller,
ClearScope, Prompt, GetBasePath, InventoryList, ProjectList, LookUpInit)
{
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
//scope.
var generator = GenerateForm;
var form = PermissionsForm;
var scope = generator.inject(form, {mode: 'edit', related: true});
var base_id = ($routeParams.user_id !== undefined) ? $routeParams.user_id : $routeParams.team_id;
var base = $location.path().replace(/^\//,'').split('/')[0];
var id = $routeParams.permission_id;
var defaultUrl = GetBasePath('base') + 'permissions/' + id + '/';
generator.reset();
var master = {};
var relatedSets = {};
// Retrieve detail record and prepopulate the form
Rest.setUrl(defaultUrl);
Rest.get()
.success( function(data, status, headers, config) {
LoadBreadCrumbs({ path: '/users/' + base_id + '/permissions/' + id, title: data.name });
for (var fld in form.fields) {
if (data[fld]) {
if (form.fields[fld].sourceModel) {
var sourceModel = form.fields[fld].sourceModel;
var sourceField = form.fields[fld].sourceField;
scope[sourceModel + '_' + sourceField] = data.summary_fields[sourceModel][sourceField];
master[sourceModel + '_' + sourceField] = data.summary_fields[sourceModel][sourceField];
}
scope[fld] = data[fld];
master[fld] = scope[fld];
}
}
scope.category = 'Deploy';
if (data['permission_type'] != 'run' && data['permission_type'] != 'check' ) {
scope.category = 'Inventory';
}
master['category'] = scope.category;
LookUpInit({
scope: scope,
form: form,
current_item: data.inventory,
list: InventoryList,
field: 'inventory'
});
LookUpInit({
scope: scope,
form: form,
current_item: data.project,
list: ProjectList,
field: 'project'
});
})
.error( function(data, status, headers, config) {
ProcessErrors(scope, data, status, form,
{ hdr: 'Error!', msg: 'Failed to retrieve Permission: ' + id + '. GET status: ' + status });
});
// Save changes to the parent
scope.formSave = function() {
var data = {}
for (var fld in form.fields) {
data[fld] = scope[fld];
}
Rest.setUrl(defaultUrl);
Rest.put(data)
.success( function(data, status, headers, config) {
ReturnToCaller(1);
})
.error( function(data, status, headers, config) {
ProcessErrors(scope, data, status, form,
{ hdr: 'Error!', msg: 'Failed to update Permission: ' + $routeParams.id + '. PUT status: ' + status });
});
};
// Cancel
scope.formReset = function() {
generator.reset();
for (var fld in master) {
scope[fld] = master[fld];
}
};
}
PermissionsEdit.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'PermissionsForm',
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller',
'ClearScope', 'Prompt', 'GetBasePath', 'InventoryList', 'ProjectList', 'LookUpInit'
];