mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 17:37:37 -02:30
autopopulate lookups if there is only one option for that lookup type
This commit is contained in:
@@ -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-url', watchUrl);
|
||||||
$('input[name="' + form.fields[field].sourceModel + '_' + form.fields[field].sourceField + '"]').attr('data-source', field);
|
$('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 () {
|
parent_scope['lookUp' + name] = function () {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user