mirror of
https://github.com/ansible/awx.git
synced 2026-01-15 20:00:43 -03:30
autopopulate lookups if there is only one option for that lookup type
This commit is contained in:
parent
be7f27af0d
commit
bdcd2c5938
@ -63,6 +63,31 @@ export default
|
||||
$('input[name="' + form.fields[field].sourceModel + '_' + form.fields[field].sourceField + '"]').attr('data-url', watchUrl);
|
||||
$('input[name="' + form.fields[field].sourceModel + '_' + form.fields[field].sourceField + '"]').attr('data-source', field);
|
||||
|
||||
// Auto populate the field if there is only one result
|
||||
Rest.setUrl(defaultUrl);
|
||||
Rest.get()
|
||||
.success(function (data) {
|
||||
if (data.count === 1) {
|
||||
parent_scope[field] = data.results[0].id;
|
||||
if (parent_scope[form.name + '_form'] && form.fields[field] && form.fields[field].sourceModel) {
|
||||
parent_scope[form.fields[field].sourceModel + '_' + form.fields[field].sourceField] =
|
||||
data.results[0][form.fields[field].sourceField];
|
||||
if (parent_scope[form.name + '_form'][form.fields[field].sourceModel + '_' + form.fields[field].sourceField]) {
|
||||
parent_scope[form.name + '_form'][form.fields[field].sourceModel + '_' + form.fields[field].sourceField]
|
||||
.$setValidity('awlookup', true);
|
||||
}
|
||||
}
|
||||
if (parent_scope[form.name + '_form']) {
|
||||
parent_scope[form.name + '_form'].$setDirty();
|
||||
}
|
||||
}
|
||||
})
|
||||
.error(function (data, status) {
|
||||
ProcessErrors(parent_scope, data, status, form, { hdr: 'Error!',
|
||||
msg: 'Failed to launch adhoc command. POST returned status: ' +
|
||||
status });
|
||||
});
|
||||
|
||||
|
||||
parent_scope['lookUp' + name] = function () {
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user