mirror of
https://github.com/ansible/awx.git
synced 2026-01-15 11:50:42 -03:30
Inventory add/edit/delete group buttons now working. Inventory detail form now maintains values independently so common fields such as Name and Description do not get overridden by Group Add/Edit modal dialog.
This commit is contained in:
parent
b19e1dd97a
commit
eca7b3888f
@ -173,10 +173,12 @@ function InventoriesAdd ($scope, $rootScope, $compile, $location, $log, $routePa
|
||||
Rest.setUrl(defaultUrl);
|
||||
var data = {}
|
||||
for (var fld in form.fields) {
|
||||
data[fld] = scope[fld];
|
||||
}
|
||||
if ($routeParams.inventory_id) {
|
||||
data.inventory = $routeParams.inventory_id;
|
||||
if (form.fields[fld].realName) {
|
||||
data[form.fields[fld].realName] = scope[fld];
|
||||
}
|
||||
else {
|
||||
data[fld] = scope[fld];
|
||||
}
|
||||
}
|
||||
Rest.post(data)
|
||||
.success( function(data, status, headers, config) {
|
||||
@ -203,7 +205,8 @@ InventoriesAdd.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$lo
|
||||
function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeParams, InventoryForm,
|
||||
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit,
|
||||
RelatedPaginateInit, ReturnToCaller, ClearScope, LookUpInit, Prompt,
|
||||
OrganizationList, TreeInit, GetBasePath, GroupsList, GroupsEdit, LoadInventory)
|
||||
OrganizationList, TreeInit, GetBasePath, GroupsList, GroupsEdit, LoadInventory,
|
||||
GroupsDelete)
|
||||
{
|
||||
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||
//scope.
|
||||
@ -236,8 +239,13 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP
|
||||
Rest.setUrl(defaultUrl + $routeParams.id + '/');
|
||||
var data = {}
|
||||
for (var fld in form.fields) {
|
||||
data[fld] = scope[fld];
|
||||
}
|
||||
if (form.fields[fld].realName) {
|
||||
data[form.fields[fld].realName] = scope[fld];
|
||||
}
|
||||
else {
|
||||
data[fld] = scope[fld];
|
||||
}
|
||||
}
|
||||
Rest.put(data)
|
||||
.success( function(data, status, headers, config) {
|
||||
var base = $location.path().replace(/^\//,'').split('/')[0];
|
||||
@ -284,7 +292,7 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP
|
||||
.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 });
|
||||
{ hdr: 'Error!', msg: 'Call to ' + url + ' failed. POST returned status: ' + status });
|
||||
});
|
||||
};
|
||||
|
||||
@ -401,7 +409,9 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP
|
||||
RelatedSearchInit({ scope: scope, form: form, relatedSets: scope.relatedSets });
|
||||
RelatedPaginateInit({ scope: scope, relatedSets: scope.relatedSets });
|
||||
scope.search('host');
|
||||
scope.$digest();
|
||||
if (!scope.$$phase) {
|
||||
scope.$digest();
|
||||
}
|
||||
});
|
||||
|
||||
scope.addGroup = function() {
|
||||
@ -411,11 +421,16 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP
|
||||
scope.editGroup = function() {
|
||||
GroupsEdit({ "inventory_id": id, group_id: scope.group_id });
|
||||
}
|
||||
|
||||
scope.deleteGroup = function() {
|
||||
GroupsDelete({ scope: scope });
|
||||
}
|
||||
}
|
||||
|
||||
InventoriesEdit.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'InventoryForm',
|
||||
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit',
|
||||
'RelatedPaginateInit', 'ReturnToCaller', 'ClearScope', 'LookUpInit', 'Prompt',
|
||||
'OrganizationList', 'TreeInit', 'GetBasePath', 'GroupsList', 'GroupsEdit', 'LoadInventory'
|
||||
'OrganizationList', 'TreeInit', 'GetBasePath', 'GroupsList', 'GroupsEdit', 'LoadInventory',
|
||||
'GroupsDelete'
|
||||
];
|
||||
|
||||
@ -10,8 +10,8 @@ angular.module('InventoryFormDefinition', [])
|
||||
.value(
|
||||
'InventoryForm', {
|
||||
|
||||
addTitle: 'Create Inventory', //Legend in add mode
|
||||
editTitle: '{{ name }}', //Legend in edit mode
|
||||
addTitle: 'Create Inventory',
|
||||
editTitle: '{{ inventory_name }}',
|
||||
name: 'inventory',
|
||||
well: true,
|
||||
collapse: true,
|
||||
@ -19,14 +19,16 @@ angular.module('InventoryFormDefinition', [])
|
||||
collapseMode: 'edit',
|
||||
|
||||
fields: {
|
||||
name: {
|
||||
inventory_name: {
|
||||
realName: 'name',
|
||||
label: 'Name',
|
||||
type: 'text',
|
||||
addRequired: true,
|
||||
editRequired: true,
|
||||
capitalize: true
|
||||
capitalize: false
|
||||
},
|
||||
description: {
|
||||
inventory_description: {
|
||||
realName: 'description',
|
||||
label: 'Description',
|
||||
type: 'text',
|
||||
addRequired: false,
|
||||
|
||||
@ -257,6 +257,7 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
|
||||
return function(params) {
|
||||
|
||||
var group_id = params.group_id;
|
||||
var inventory_id = $routeParams.id;
|
||||
var generator = GenerateForm;
|
||||
var form = GroupForm;
|
||||
var defaultUrl = GetBasePath('groups') + group_id + '/';
|
||||
@ -302,7 +303,6 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
|
||||
Rest.setUrl(defaultUrl);
|
||||
Rest.get()
|
||||
.success( function(data, status, headers, config) {
|
||||
LoadBreadCrumbs();
|
||||
for (var fld in form.fields) {
|
||||
if (data[fld]) {
|
||||
scope[fld] = data[fld];
|
||||
@ -315,12 +315,7 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
|
||||
relatedSets[set] = { url: related[set], iterator: form.related[set].iterator };
|
||||
}
|
||||
}
|
||||
|
||||
scope.variable_url = data.related.variable_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.$emit('groupLoaded');
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
@ -333,13 +328,13 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
|
||||
try {
|
||||
// Make sure we have valid JSON
|
||||
var myjson = JSON.parse(scope.variables);
|
||||
|
||||
|
||||
var data = {}
|
||||
for (var fld in form.fields) {
|
||||
data[fld] = scope[fld];
|
||||
}
|
||||
|
||||
Rest.setUrl(defaultUrl);
|
||||
data['inventory'] = inventory_id;
|
||||
Rest.setUrl(defaultUrl);
|
||||
Rest.put(data)
|
||||
.success( function(data, status, headers, config) {
|
||||
if (scope.variables) {
|
||||
@ -347,20 +342,18 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
|
||||
Rest.setUrl(GetBasePath('groups') + data.id + '/variable_data/');
|
||||
Rest.put({data: scope.variables})
|
||||
.success( function(data, status, headers, config) {
|
||||
var base = $location.path().replace(/^\//,'').split('/')[0];
|
||||
(base == 'groups') ? ReturnToCaller() : ReturnToCaller(1);
|
||||
$('#form-modal').modal('hide');
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, form,
|
||||
{ hdr: 'Error!', msg: 'Failed to update group varaibles. PUT returned status: ' + status });
|
||||
});
|
||||
}
|
||||
$('#form-modal').modal('hide');
|
||||
|
||||
$('#form-modal').modal('hide');
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, form,
|
||||
{ hdr: 'Error!', msg: 'Failed to update group: ' + id + '. PUT status: ' + status });
|
||||
{ hdr: 'Error!', msg: 'Failed to update group: ' + group_id + '. PUT status: ' + status });
|
||||
});
|
||||
}
|
||||
catch(err) {
|
||||
@ -376,6 +369,44 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
|
||||
}
|
||||
}
|
||||
}
|
||||
}])
|
||||
|
||||
|
||||
.factory('GroupsDelete', ['$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'GroupForm', 'GenerateForm',
|
||||
'Prompt', 'ProcessErrors', 'GetBasePath',
|
||||
function($rootScope, $location, $log, $routeParams, Rest, Alert, GroupForm, GenerateForm, Prompt, ProcessErrors,
|
||||
GetBasePath) {
|
||||
return function(params) {
|
||||
var scope = params.scope;
|
||||
var obj = $('#tree-view li[group_id="' + scope.group_id + '"]');
|
||||
var action_to_take = function() {
|
||||
var url = GetBasePath('inventory') + $routeParams.id + '/groups/';
|
||||
Rest.setUrl(url);
|
||||
Rest.post({ id: scope.group_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
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
||||
|
||||
|
||||
|
||||
@ -208,9 +208,17 @@ angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationLi
|
||||
.success( function(data, status, headers, config) {
|
||||
LoadBreadCrumbs({ path: '/inventories/' + $routeParams.id, title: data.name });
|
||||
for (var fld in form.fields) {
|
||||
if (data[fld]) {
|
||||
scope[fld] = data[fld];
|
||||
scope.master[fld] = scope[fld];
|
||||
if (form.fields[fld].realName) {
|
||||
if (data[form.fields[fld].realName]) {
|
||||
scope[fld] = data[form.fields[fld].realName];
|
||||
scope.master[fld] = scope[fld];
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (data[fld]) {
|
||||
scope[fld] = data[fld];
|
||||
scope.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] =
|
||||
|
||||
@ -643,9 +643,9 @@ angular.module('FormGenerator', ['GeneratorHelpers'])
|
||||
html += "<div class=\"inventory-buttons pull-right\">";
|
||||
html += "<button ng-click=\"addGroup()\" ng-hide=\"groupAddHide\" id=\"inv-group-add\" " +
|
||||
"class=\"btn btn-mini btn-success\"><i class=\"icon-plus\"></i> Add Group</button>";
|
||||
html += "<button ng-hide=\"groupEditHide\" id=\"inv-group-edit\" class=\"btn btn-mini btn-success\">" +
|
||||
html += "<button ng-click=\"editGroup()\" ng-hide=\"groupEditHide\" id=\"inv-group-edit\" class=\"btn btn-mini btn-success\">" +
|
||||
"<i class=\"icon-edit\"></i> Edit Group</button>";
|
||||
html += "<button ng-hide=\"groupDeleteHide\" id=\"inv-group-delete\" class=\"btn btn-mini btn-danger\">" +
|
||||
html += "<button ng-click=\"deleteGroup()\" ng-hide=\"groupDeleteHide\" id=\"inv-group-delete\" class=\"btn btn-mini btn-danger\">" +
|
||||
"<i class=\"icon-remove\"></i> Delete Group</button>";
|
||||
html += "</div>\n";
|
||||
html += "<div id=\"tree-view\"></div>\n";
|
||||
|
||||
@ -55,9 +55,17 @@ angular.module('Utilities',[])
|
||||
else if (form) {
|
||||
var fieldErrors = false;
|
||||
for (var field in form.fields ) {
|
||||
if (data[field]) {
|
||||
scope[field + '_api_error'] = data[field][0];
|
||||
fieldErrors = true;
|
||||
if (form.fields[field].realName) {
|
||||
if (data[form.fields[field].realName]) {
|
||||
scope[field + '_api_error'] = data[form.fields[field]][0];
|
||||
fieldErrors = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (data[field]) {
|
||||
scope[field + '_api_error'] = data[field][0];
|
||||
fieldErrors = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( (!fieldErrors) && defaultMsg) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user