mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 01:17:37 -02: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:
@@ -173,10 +173,12 @@ function InventoriesAdd ($scope, $rootScope, $compile, $location, $log, $routePa
|
|||||||
Rest.setUrl(defaultUrl);
|
Rest.setUrl(defaultUrl);
|
||||||
var data = {}
|
var data = {}
|
||||||
for (var fld in form.fields) {
|
for (var fld in form.fields) {
|
||||||
data[fld] = scope[fld];
|
if (form.fields[fld].realName) {
|
||||||
}
|
data[form.fields[fld].realName] = scope[fld];
|
||||||
if ($routeParams.inventory_id) {
|
}
|
||||||
data.inventory = $routeParams.inventory_id;
|
else {
|
||||||
|
data[fld] = scope[fld];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Rest.post(data)
|
Rest.post(data)
|
||||||
.success( function(data, status, headers, config) {
|
.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,
|
function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeParams, InventoryForm,
|
||||||
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit,
|
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit,
|
||||||
RelatedPaginateInit, ReturnToCaller, ClearScope, LookUpInit, Prompt,
|
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
|
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||||
//scope.
|
//scope.
|
||||||
@@ -236,8 +239,13 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP
|
|||||||
Rest.setUrl(defaultUrl + $routeParams.id + '/');
|
Rest.setUrl(defaultUrl + $routeParams.id + '/');
|
||||||
var data = {}
|
var data = {}
|
||||||
for (var fld in form.fields) {
|
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)
|
Rest.put(data)
|
||||||
.success( function(data, status, headers, config) {
|
.success( function(data, status, headers, config) {
|
||||||
var base = $location.path().replace(/^\//,'').split('/')[0];
|
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) {
|
.error( function(data, status, headers, config) {
|
||||||
$('#prompt-modal').modal('hide');
|
$('#prompt-modal').modal('hide');
|
||||||
ProcessErrors(scope, data, status, null,
|
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 });
|
RelatedSearchInit({ scope: scope, form: form, relatedSets: scope.relatedSets });
|
||||||
RelatedPaginateInit({ scope: scope, relatedSets: scope.relatedSets });
|
RelatedPaginateInit({ scope: scope, relatedSets: scope.relatedSets });
|
||||||
scope.search('host');
|
scope.search('host');
|
||||||
scope.$digest();
|
if (!scope.$$phase) {
|
||||||
|
scope.$digest();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
scope.addGroup = function() {
|
scope.addGroup = function() {
|
||||||
@@ -411,11 +421,16 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP
|
|||||||
scope.editGroup = function() {
|
scope.editGroup = function() {
|
||||||
GroupsEdit({ "inventory_id": id, group_id: scope.group_id });
|
GroupsEdit({ "inventory_id": id, group_id: scope.group_id });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scope.deleteGroup = function() {
|
||||||
|
GroupsDelete({ scope: scope });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
InventoriesEdit.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'InventoryForm',
|
InventoriesEdit.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'InventoryForm',
|
||||||
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit',
|
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit',
|
||||||
'RelatedPaginateInit', 'ReturnToCaller', 'ClearScope', 'LookUpInit', 'Prompt',
|
'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(
|
.value(
|
||||||
'InventoryForm', {
|
'InventoryForm', {
|
||||||
|
|
||||||
addTitle: 'Create Inventory', //Legend in add mode
|
addTitle: 'Create Inventory',
|
||||||
editTitle: '{{ name }}', //Legend in edit mode
|
editTitle: '{{ inventory_name }}',
|
||||||
name: 'inventory',
|
name: 'inventory',
|
||||||
well: true,
|
well: true,
|
||||||
collapse: true,
|
collapse: true,
|
||||||
@@ -19,14 +19,16 @@ angular.module('InventoryFormDefinition', [])
|
|||||||
collapseMode: 'edit',
|
collapseMode: 'edit',
|
||||||
|
|
||||||
fields: {
|
fields: {
|
||||||
name: {
|
inventory_name: {
|
||||||
|
realName: 'name',
|
||||||
label: 'Name',
|
label: 'Name',
|
||||||
type: 'text',
|
type: 'text',
|
||||||
addRequired: true,
|
addRequired: true,
|
||||||
editRequired: true,
|
editRequired: true,
|
||||||
capitalize: true
|
capitalize: false
|
||||||
},
|
},
|
||||||
description: {
|
inventory_description: {
|
||||||
|
realName: 'description',
|
||||||
label: 'Description',
|
label: 'Description',
|
||||||
type: 'text',
|
type: 'text',
|
||||||
addRequired: false,
|
addRequired: false,
|
||||||
|
|||||||
@@ -257,6 +257,7 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
|
|||||||
return function(params) {
|
return function(params) {
|
||||||
|
|
||||||
var group_id = params.group_id;
|
var group_id = params.group_id;
|
||||||
|
var inventory_id = $routeParams.id;
|
||||||
var generator = GenerateForm;
|
var generator = GenerateForm;
|
||||||
var form = GroupForm;
|
var form = GroupForm;
|
||||||
var defaultUrl = GetBasePath('groups') + group_id + '/';
|
var defaultUrl = GetBasePath('groups') + group_id + '/';
|
||||||
@@ -302,7 +303,6 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
|
|||||||
Rest.setUrl(defaultUrl);
|
Rest.setUrl(defaultUrl);
|
||||||
Rest.get()
|
Rest.get()
|
||||||
.success( function(data, status, headers, config) {
|
.success( function(data, status, headers, config) {
|
||||||
LoadBreadCrumbs();
|
|
||||||
for (var fld in form.fields) {
|
for (var fld in form.fields) {
|
||||||
if (data[fld]) {
|
if (data[fld]) {
|
||||||
scope[fld] = 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 };
|
relatedSets[set] = { url: related[set], iterator: form.related[set].iterator };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
scope.variable_url = data.related.variable_data;
|
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');
|
scope.$emit('groupLoaded');
|
||||||
})
|
})
|
||||||
.error( function(data, status, headers, config) {
|
.error( function(data, status, headers, config) {
|
||||||
@@ -333,13 +328,13 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
|
|||||||
try {
|
try {
|
||||||
// Make sure we have valid JSON
|
// Make sure we have valid JSON
|
||||||
var myjson = JSON.parse(scope.variables);
|
var myjson = JSON.parse(scope.variables);
|
||||||
|
|
||||||
var data = {}
|
var data = {}
|
||||||
for (var fld in form.fields) {
|
for (var fld in form.fields) {
|
||||||
data[fld] = scope[fld];
|
data[fld] = scope[fld];
|
||||||
}
|
}
|
||||||
|
data['inventory'] = inventory_id;
|
||||||
Rest.setUrl(defaultUrl);
|
Rest.setUrl(defaultUrl);
|
||||||
Rest.put(data)
|
Rest.put(data)
|
||||||
.success( function(data, status, headers, config) {
|
.success( function(data, status, headers, config) {
|
||||||
if (scope.variables) {
|
if (scope.variables) {
|
||||||
@@ -347,20 +342,18 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
|
|||||||
Rest.setUrl(GetBasePath('groups') + data.id + '/variable_data/');
|
Rest.setUrl(GetBasePath('groups') + data.id + '/variable_data/');
|
||||||
Rest.put({data: scope.variables})
|
Rest.put({data: scope.variables})
|
||||||
.success( function(data, status, headers, config) {
|
.success( function(data, status, headers, config) {
|
||||||
var base = $location.path().replace(/^\//,'').split('/')[0];
|
$('#form-modal').modal('hide');
|
||||||
(base == 'groups') ? ReturnToCaller() : ReturnToCaller(1);
|
|
||||||
})
|
})
|
||||||
.error( function(data, status, headers, config) {
|
.error( function(data, status, headers, config) {
|
||||||
ProcessErrors(scope, data, status, form,
|
ProcessErrors(scope, data, status, form,
|
||||||
{ hdr: 'Error!', msg: 'Failed to update group varaibles. PUT returned status: ' + status });
|
{ 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) {
|
.error( function(data, status, headers, config) {
|
||||||
ProcessErrors(scope, data, status, form,
|
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) {
|
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) {
|
.success( function(data, status, headers, config) {
|
||||||
LoadBreadCrumbs({ path: '/inventories/' + $routeParams.id, title: data.name });
|
LoadBreadCrumbs({ path: '/inventories/' + $routeParams.id, title: data.name });
|
||||||
for (var fld in form.fields) {
|
for (var fld in form.fields) {
|
||||||
if (data[fld]) {
|
if (form.fields[fld].realName) {
|
||||||
scope[fld] = data[fld];
|
if (data[form.fields[fld].realName]) {
|
||||||
scope.master[fld] = scope[fld];
|
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]) {
|
if (form.fields[fld].type == 'lookup' && data.summary_fields[form.fields[fld].sourceModel]) {
|
||||||
scope[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] =
|
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 += "<div class=\"inventory-buttons pull-right\">";
|
||||||
html += "<button ng-click=\"addGroup()\" ng-hide=\"groupAddHide\" id=\"inv-group-add\" " +
|
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>";
|
"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>";
|
"<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>";
|
"<i class=\"icon-remove\"></i> Delete Group</button>";
|
||||||
html += "</div>\n";
|
html += "</div>\n";
|
||||||
html += "<div id=\"tree-view\"></div>\n";
|
html += "<div id=\"tree-view\"></div>\n";
|
||||||
|
|||||||
@@ -55,9 +55,17 @@ angular.module('Utilities',[])
|
|||||||
else if (form) {
|
else if (form) {
|
||||||
var fieldErrors = false;
|
var fieldErrors = false;
|
||||||
for (var field in form.fields ) {
|
for (var field in form.fields ) {
|
||||||
if (data[field]) {
|
if (form.fields[field].realName) {
|
||||||
scope[field + '_api_error'] = data[field][0];
|
if (data[form.fields[field].realName]) {
|
||||||
fieldErrors = true;
|
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) {
|
if ( (!fieldErrors) && defaultMsg) {
|
||||||
|
|||||||
Reference in New Issue
Block a user