Group and Host variables working.

This commit is contained in:
chouseknecht 2013-05-21 16:13:20 -04:00
parent c238a85581
commit 53212da149
5 changed files with 178 additions and 111 deletions

View File

@ -166,25 +166,45 @@ function GroupsAdd ($scope, $rootScope, $compile, $location, $log, $routeParams,
// Save
scope.formSave = function() {
Rest.setUrl(defaultUrl);
var data = {}
for (var fld in form.fields) {
data[fld] = scope[fld];
}
if ($routeParams.inventory_id) {
data['inventory'] = $routeParams.inventory_id;
}
try {
// Make sure we have valid JSON
var myjson = JSON.parse(scope.variables);
var data = {}
for (var fld in form.fields) {
if (fld != 'variables') {
data[fld] = scope[fld];
}
}
Rest.post(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 add new group. Post returned status: ' + status });
});
};
if ($routeParams.inventory_id) {
data['inventory'] = $routeParams.inventory_id;
}
Rest.setUrl(defaultUrl);
Rest.post(data)
.success( function(data, status, headers, config) {
if (scope.variables) {
Rest.setUrl(data.related.variable_data);
Rest.put({data: scope.variables})
.success( function(data, status, headers, config) {
ReturnToCaller(1);
})
.error( function(data, status, headers, config) {
ProcessErrors(scope, data, status, form,
{ hdr: 'Error!', msg: 'Failed to add group varaibles. PUT returned status: ' + status });
});
}
})
.error( function(data, status, headers, config) {
ProcessErrors(scope, data, status, form,
{ hdr: 'Error!', msg: 'Failed to add new group. Post returned status: ' + status });
});
}
catch(err) {
Alert("Error", "Error parsing group variables. Expecting valid JSON. Parser returned " + err);
}
}
// Cancel
scope.formReset = function() {
@ -222,6 +242,26 @@ function GroupsEdit ($scope, $rootScope, $compile, $location, $log, $routeParams
for (var set in relatedSets) {
scope.search(relatedSets[set].iterator);
}
if (scope.variable_url) {
Rest.setUrl(scope.variable_url);
Rest.get()
.success( function(data, status, headers, config) {
if ($.isEmptyObject(data.data)) {
scope.variables = "\{\}";
}
else {
scope.variables = data.data;
}
})
.error( function(data, status, headers, config) {
scope.variables = null;
ProcessErrors(scope, data, status, form,
{ hdr: 'Error!', msg: 'Failed to retrieve host variables. GET returned status: ' + status });
});
}
else {
scope.variables = "\{\}";
}
});
// Retrieve detail record and prepopulate the form
@ -241,6 +281,9 @@ function GroupsEdit ($scope, $rootScope, $compile, $location, $log, $routeParams
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 });
@ -253,21 +296,42 @@ function GroupsEdit ($scope, $rootScope, $compile, $location, $log, $routeParams
// Save changes to the parent
scope.formSave = function() {
Rest.setUrl(defaultUrl);
var data = {}
for (var fld in form.fields) {
data[fld] = scope[fld];
}
Rest.put(data)
.success( function(data, status, headers, config) {
var base = $location.path().replace(/^\//,'').split('/')[0];
(base == 'groups') ? ReturnToCaller() : ReturnToCaller(1);
})
.error( function(data, status, headers, config) {
ProcessErrors(scope, data, status, form,
{ hdr: 'Error!', msg: 'Failed to update group: ' + id + '. PUT status: ' + status });
});
};
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);
Rest.put(data)
.success( function(data, status, headers, config) {
if (scope.variables) {
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);
})
.error( function(data, status, headers, config) {
ProcessErrors(scope, data, status, form,
{ hdr: 'Error!', msg: 'Failed to update group varaibles. PUT returned status: ' + status });
});
}
var base = $location.path().replace(/^\//,'').split('/')[0];
(base == 'groups') ? ReturnToCaller() : ReturnToCaller(1);
})
.error( function(data, status, headers, config) {
ProcessErrors(scope, data, status, form,
{ hdr: 'Error!', msg: 'Failed to update group: ' + id + '. PUT status: ' + status });
});
}
catch(err) {
Alert("Error", "Error parsing group variables. Expecting valid JSON. Parser returned " + err);
}
};
// Cancel
scope.formReset = function() {

View File

@ -175,27 +175,35 @@ function HostsAdd ($scope, $rootScope, $compile, $location, $log, $routeParams,
if ($routeParams.inventory_id) {
data['inventory'] = $routeParams.inventory_id;
}
Rest.post(data)
.success( function(data, status, headers, config) {
if (scope.variables) {
Rest.setUrl(GetBasePath('hosts') + data.id + '/variable_data/');
Rest.post({data: scope.variables})
.success( function(data, status, headers, config) {
ReturnToCaller(1);
})
.error( function(data, status, headers, config) {
ProcessErrors(scope, data, status, form,
{ hdr: 'Error!', msg: 'Failed to add host varaibles. POST returned status: ' + status });
});
}
else {
ReturnToCaller(1);
}
})
.error( function(data, status, headers, config) {
ProcessErrors(scope, data, status, form,
{ hdr: 'Error!', msg: 'Failed to add new host. POST returned status: ' + status });
});
try {
// Make sure we have valid JSON
var myjson = JSON.parse(scope.variables);
Rest.post(data)
.success( function(data, status, headers, config) {
if (scope.variables) {
Rest.setUrl(data.related.variable_data);
Rest.put({data: scope.variables})
.success( function(data, status, headers, config) {
ReturnToCaller(1);
})
.error( function(data, status, headers, config) {
ProcessErrors(scope, data, status, form,
{ hdr: 'Error!', msg: 'Failed to add host varaibles. POST returned status: ' + status });
});
}
else {
ReturnToCaller(1);
}
})
.error( function(data, status, headers, config) {
ProcessErrors(scope, data, status, form,
{ hdr: 'Error!', msg: 'Failed to add new host. POST returned status: ' + status });
});
}
catch(err) {
Alert("Error", "Error parsing host variables. Expecting valid JSON. Parser returned " + err);
}
};
// Cancel
@ -236,7 +244,12 @@ function HostsEdit ($scope, $rootScope, $compile, $location, $log, $routeParams,
Rest.setUrl(scope.variable_url);
Rest.get()
.success( function(data, status, headers, config) {
scope.variables = data.data;
if ($.isEmptyObject(data.data)) {
scope.variables = "\{\}";
}
else {
scope.variables = data.data;
}
})
.error( function(data, status, headers, config) {
scope.variables = null;
@ -245,7 +258,7 @@ function HostsEdit ($scope, $rootScope, $compile, $location, $log, $routeParams,
});
}
else {
scope.variables = null;
scope.variables = "\{\}";
}
});
@ -283,28 +296,37 @@ function HostsEdit ($scope, $rootScope, $compile, $location, $log, $routeParams,
var data = {}
for (var fld in form.fields) {
data[fld] = scope[fld];
}
Rest.put(data)
.success( function(data, status, headers, config) {
if (scope.variables) {
Rest.setUrl(GetBasePath('hosts') + data.id + '/variable_data/');
Rest.put({data: scope.variables})
.success( function(data, status, headers, config) {
(base == 'hosts') ? ReturnToCaller() : ReturnToCaller(1);
})
.error( function(data, status, headers, config) {
ProcessErrors(scope, data, status, form,
{ hdr: 'Error!', msg: 'Failed to update host varaibles. PUT returned status: ' + status });
});
}
else {
(base == 'hosts') ? ReturnToCaller() : ReturnToCaller(1);
}
})
.error( function(data, status, headers, config) {
ProcessErrors(scope, data, status, form,
{ hdr: 'Error!', msg: 'Failed to update host: ' + id + '. PUT status: ' + status });
});
}
try {
// Make sure we have valid JSON
var myjson = JSON.parse(scope.variables);
Rest.put(data)
.success( function(data, status, headers, config) {
if (scope.variables) {
Rest.setUrl(GetBasePath('hosts') + data.id + '/variable_data/');
Rest.put({data: scope.variables})
.success( function(data, status, headers, config) {
(base == 'hosts') ? ReturnToCaller() : ReturnToCaller(1);
})
.error( function(data, status, headers, config) {
ProcessErrors(scope, data, status, form,
{ hdr: 'Error!', msg: 'Failed to update host varaibles. PUT returned status: ' + status });
});
}
else {
(base == 'hosts') ? ReturnToCaller() : ReturnToCaller(1);
}
})
.error( function(data, status, headers, config) {
ProcessErrors(scope, data, status, form,
{ hdr: 'Error!', msg: 'Failed to update host: ' + id + '. PUT status: ' + status });
});
}
catch(err) {
Alert("Error", "Error parsing host variables. Expecting valid JSON. Parser returned " + err);
}
};
// Cancel

View File

@ -378,12 +378,6 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP
show: true
});
}
},
vairables: {
label: 'Host Variables',
separator_before: true,
"_disabled": true,
action: function(obj) { }
}
}
}
@ -392,17 +386,7 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP
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 {
@ -459,14 +443,8 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP
show: true
});
},
"_disabled": (nodeType == 'all-hosts-group') ? true : false
},
variables: {
label: 'Group variables',
action: function(obj) { },
"_disabled": true,
separator_before: true
}
"_disabled": (nodeType == 'all-hosts-group') ? true : false
}
}
}
}

View File

@ -27,14 +27,16 @@ angular.module('GroupFormDefinition', [])
type: 'text',
addRequired: false,
editRequired: false
},
variables: {
label: 'Variables',
type: 'textarea',
addRequired: false,
editRequird: false,
rows: 10,
class: 'span12',
default: "\{\}"
}
// ,
// inventory: {
// label: 'Inventory',
// type: 'hidden',
// includeOnEdit: true,
// includeOnAdd: true
// }
},
buttons: { //for now always generates <button> tags

View File

@ -39,7 +39,8 @@ angular.module('HostFormDefinition', [])
addRequired: false,
editRequird: false,
rows: 10,
class: 'span12'
class: 'span12',
default: "\{\}"
}
},