Latest UI Inventory updates

This commit is contained in:
chouseknecht
2013-05-14 01:52:04 -04:00
parent fe5a454441
commit 2612ebd792
22 changed files with 682 additions and 433 deletions

View File

@@ -12,7 +12,7 @@
function InventoriesList ($scope, $rootScope, $location, $log, $routeParams, Rest, Alert, InventoryList,
GenerateList, LoadBreadCrumbs, Prompt, SearchInit, PaginateInit, ReturnToCaller,
ClearScope, ProcessErrors, SetListeners)
ClearScope, ProcessErrors)
{
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
//scope.
@@ -24,7 +24,6 @@ function InventoriesList ($scope, $rootScope, $location, $log, $routeParams, Res
var scope = view.inject(InventoryList, { mode: mode }); // Inject our view
scope.selected = [];
SetListeners({ scope: scope, set: 'inventories', iterator: list.iterator });
SearchInit({ scope: scope, set: 'inventories', list: list, url: defaultUrl });
PaginateInit({ scope: scope, list: list, url: defaultUrl });
scope.search(list.iterator);
@@ -86,13 +85,6 @@ function InventoriesList ($scope, $rootScope, $location, $log, $routeParams, Res
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) {
@@ -141,13 +133,12 @@ function InventoriesList ($scope, $rootScope, $location, $log, $routeParams, Res
}
InventoriesList.$inject = [ '$scope', '$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'InventoryList', 'GenerateList',
'LoadBreadCrumbs', 'Prompt', 'SearchInit', 'PaginateInit', 'ReturnToCaller', 'ClearScope', 'ProcessErrors',
'SetListeners' ];
'LoadBreadCrumbs', 'Prompt', 'SearchInit', 'PaginateInit', 'ReturnToCaller', 'ClearScope', 'ProcessErrors' ];
function InventoriesAdd ($scope, $rootScope, $compile, $location, $log, $routeParams, InventoryForm,
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope,
GenerateList, OrganizationList, SearchInit, PaginateInit, LookUpOrganizationInit)
GenerateList, OrganizationList, SearchInit, PaginateInit, LookUpInit)
{
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
//scope.
@@ -159,7 +150,14 @@ function InventoriesAdd ($scope, $rootScope, $compile, $location, $log, $routePa
var scope = generator.inject(form, {mode: 'add', related: false});
generator.reset();
LoadBreadCrumbs();
LookUpOrganizationInit({ scope: scope });
LookUpInit({
scope: scope,
form: form,
current_item: ($routeParams.organization_id) ? $routeParams.organization_id : null,
list: OrganizationList,
field: 'organization'
});
// Save
scope.formSave = function() {
@@ -187,44 +185,32 @@ function InventoriesAdd ($scope, $rootScope, $compile, $location, $log, $routePa
InventoriesAdd.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'InventoryForm', 'GenerateForm',
'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope', 'GenerateList',
'OrganizationList', 'SearchInit', 'PaginateInit', 'LookUpOrganizationInit' ];
'OrganizationList', 'SearchInit', 'PaginateInit', 'LookUpInit' ];
function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeParams, InventoryForm,
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit,
RelatedPaginateInit, ReturnToCaller, ClearScope, LookUpOrganizationInit, Prompt,
TreeInit)
RelatedPaginateInit, ReturnToCaller, ClearScope, LookUpInit, Prompt,
OrganizationList, TreeInit, GetBasePath)
{
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
//scope.
var defaultUrl='/api/v1/inventories/';
var generator = GenerateForm;
var form = InventoryForm;
var defaultUrl=GetBasePath('inventory');
var scope = generator.inject(form, {mode: 'edit', related: true});
generator.reset();
var base = $location.path().replace(/^\//,'').split('/')[0];
var master = {};
var id = $routeParams.id;
var relatedSets = {};
LookUpOrganizationInit({ scope: scope });
// After inventory is loaded, retrieve each related set and any lookups
scope.$on('inventoryLoaded', function() {
Rest.setUrl(scope['organization_url']);
Rest.get()
.success( function(data, status, headers, config) {
scope['organization_name'] = data.name;
master['organization_name'] = data.name;
})
.error( function(data, status, headers, config) {
ProcessErrors(scope, data, status, null,
{ hdr: 'Error!', msg: 'Failed to retrieve: ' + scope.orgnization_url + '. GET status: ' + status });
});
for (var set in relatedSets) {
scope.search(relatedSets[set].iterator);
}
}
});
// Retrieve detail record and prepopulate the form
@@ -237,7 +223,22 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP
scope[fld] = data[fld];
master[fld] = scope[fld];
}
if (form.fields[fld].type == 'lookup' && data.summary_fields[form.fields[fld].sourceModel]) {
scope[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] =
data.summary_fields[form.fields[fld].sourceModel][form.fields[fld].sourceField];
master[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] =
scope[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField];
}
}
LookUpInit({
scope: scope,
form: form,
current_item: data.organization,
list: OrganizationList,
field: 'organization'
});
var related = data.related;
for (var set in form.related) {
if (related[set]) {
@@ -246,12 +247,11 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP
}
// Load the tree view
TreeInit(related.groups);
TreeInit({ scope: scope, inventory: data });
// 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['organization_url'] = data.related.organization;
scope.$emit('inventoryLoaded');
})
.error( function(data, status, headers, config) {
@@ -261,7 +261,7 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP
// Save changes to the parent
scope.formSave = function() {
Rest.setUrl(defaultUrl + $routeParams.id);
Rest.setUrl(defaultUrl + $routeParams.id + '/');
var data = {}
for (var fld in form.fields) {
data[fld] = scope[fld];
@@ -321,12 +321,142 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP
action: action
});
};
function changePath(path) {
// For reasons unknown, calling $location.path(<new path>) from inside
// treeController fails to work. This is the work-around.
window.location = '/#' + path;
};
scope.treeController = function($node) {
if ($($node).attr('type') == 'host') {
return {
edit: {
label: 'Edit Host',
action: function(obj) { changePath($location.path() + '/hosts/' + $(obj).attr('id')); }
},
delete: {
label: 'Delete Host',
action: function(obj) {
var action_to_take = function() {
var url = defaultUrl + $routeParams.id + '/hosts/';
Rest.setUrl(url);
Rest.post({ id: $(obj).attr('id'), disassociate: 1 })
.success( function(data, status, headers, config) {
$('#prompt-modal').modal('hide');
$('#tree-view').jstree("delete_node",obj);
})
.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 });
});
};
//Force binds to work. Not working usual way.
$('#prompt-header').text('Delete');
$('#prompt-body').text('Are you sure you want to delete host ' + $(obj).attr('name') + '?');
$('#prompt-action-btn').addClass('btn-danger');
scope.promptAction = action_to_take; // for some reason this binds?
$('#prompt-modal').modal({
backdrop: 'static',
keyboard: true,
show: true
});
}
},
vairables: {
label: 'Host Variables',
separator_before: true,
"_disabled": true,
action: function(obj) { }
}
}
}
else if ($($node).attr('type') == 'inventory') {
return {
addGroup: {
label: 'Add Group',
action: function() { changePath($location.path() + '/groups'); }
},
addHost: {
label: 'Add Host',
action: function() { changePath($location.path() + '/hosts'); }
},
variables: {
label: 'Inventory variables',
action: function(obj) { },
"_disabled": true,
separator_before: true
}
}
}
else {
return {
addGroup: {
label: 'Add Subgroup',
action: function(obj) {
LoadBreadCrumbs({ path: '/groups/' + $(obj).attr('id'), title: $(obj).attr('name') });
changePath($location.path() + '/groups/' + $(obj).attr('id') + '/children');
}
},
addHost: {
label: 'Add Host',
action: function(obj) {
LoadBreadCrumbs({ path: '/groups/' + $(obj).attr('id'), title: $(obj).attr('name') });
changePath($location.path() + '/groups/' + $(obj).attr('id') + '/hosts');
}
},
edit: {
label: 'Edit Group',
action: function(obj) { changePath($location.path() + '/groups/' + $(obj).attr('id')); },
separator_before: true
},
delete: {
label: 'Delete Group',
action: function(obj) {
var action_to_take = function() {
var url = defaultUrl + $routeParams.id + '/groups/';
Rest.setUrl(url);
Rest.post({ id: $(obj).attr('id'), disassociate: 1 })
.success( function(data, status, headers, config) {
$('#prompt-modal').modal('hide');
$('#tree-view').jstree("delete_node",obj);
})
.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 });
});
};
//Force binds to work. Not working usual way.
var parent = $.jstree._reference('#tree-view')._get_parent(obj);
$('#prompt-header').text('Delete Group');
$('#prompt-body').text('Are you sure you want to remove group ' + $(obj).attr('name') +
' from ' + $(parent).attr('name') + '?');
$('#prompt-action-btn').addClass('btn-danger');
scope.promptAction = action_to_take; // for some reason this binds?
$('#prompt-modal').modal({
backdrop: 'static',
keyboard: true,
show: true
});
}
},
variables: {
label: 'Group variables',
action: function(obj) { },
"_disabled": true,
separator_before: true
}
}
}
}
}
InventoriesEdit.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'InventoryForm',
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit',
'RelatedPaginateInit', 'ReturnToCaller', 'ClearScope', 'LookUpOrganizationInit', 'Prompt',
'TreeInit' ];
'RelatedPaginateInit', 'ReturnToCaller', 'ClearScope', 'LookUpInit', 'Prompt',
'OrganizationList', 'TreeInit', 'GetBasePath'];