mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 17:37:37 -02:30
AC-1054 came up with a fix that allows auto-form-fill browser pluggins to work. Applied to User and Credential pages.
This commit is contained in:
@@ -215,7 +215,10 @@ function CredentialsAdd($scope, $rootScope, $compile, $location, $log, $routePar
|
|||||||
// Save
|
// Save
|
||||||
$scope.formSave = function () {
|
$scope.formSave = function () {
|
||||||
generator.clearApiErrors();
|
generator.clearApiErrors();
|
||||||
FormSave({ scope: $scope, mode: 'add' });
|
generator.checkAutoFill();
|
||||||
|
if ($scope[form.name + '_form'].$valid) {
|
||||||
|
FormSave({ scope: $scope, mode: 'add' });
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle Owner change
|
// Handle Owner change
|
||||||
@@ -420,7 +423,10 @@ function CredentialsEdit($scope, $rootScope, $compile, $location, $log, $routePa
|
|||||||
// Save changes to the parent
|
// Save changes to the parent
|
||||||
$scope.formSave = function () {
|
$scope.formSave = function () {
|
||||||
generator.clearApiErrors();
|
generator.clearApiErrors();
|
||||||
FormSave({ scope: $scope, mode: 'edit' });
|
generator.checkAutoFill({ scope: $scope });
|
||||||
|
if ($scope[form.name + '_form'].$valid) {
|
||||||
|
FormSave({ scope: $scope, mode: 'edit' });
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle Owner change
|
// Handle Owner change
|
||||||
|
|||||||
@@ -146,35 +146,38 @@ function UsersAdd($scope, $rootScope, $compile, $location, $log, $routeParams, U
|
|||||||
|
|
||||||
// Save
|
// Save
|
||||||
$scope.formSave = function () {
|
$scope.formSave = function () {
|
||||||
generator.clearApiErrors();
|
|
||||||
var fld, data = {};
|
var fld, data = {};
|
||||||
if ($scope.organization !== undefined && $scope.organization !== null && $scope.organization !== '') {
|
generator.clearApiErrors();
|
||||||
Rest.setUrl(defaultUrl + $scope.organization + '/users/');
|
generator.checkAutoFill();
|
||||||
for (fld in form.fields) {
|
if ($scope[form.name + '_form'].$valid) {
|
||||||
if (form.fields[fld].realName) {
|
if ($scope.organization !== undefined && $scope.organization !== null && $scope.organization !== '') {
|
||||||
data[form.fields[fld].realName] = $scope[fld];
|
Rest.setUrl(defaultUrl + $scope.organization + '/users/');
|
||||||
} else {
|
for (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];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
data.is_superuser = data.is_superuser || false;
|
||||||
|
Wait('start');
|
||||||
|
Rest.post(data)
|
||||||
|
.success(function (data) {
|
||||||
|
var base = $location.path().replace(/^\//, '').split('/')[0];
|
||||||
|
if (base === 'users') {
|
||||||
|
$rootScope.flashMessage = 'New user successfully created!';
|
||||||
|
$location.path('/users/' + data.id);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ReturnToCaller(1);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.error(function (data, status) {
|
||||||
|
ProcessErrors($scope, data, status, form, { hdr: 'Error!', msg: 'Failed to add new user. POST returned status: ' + status });
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$scope.organization_name_api_error = 'A value is required';
|
||||||
}
|
}
|
||||||
data.is_superuser = data.is_superuser || false;
|
|
||||||
Wait('start');
|
|
||||||
Rest.post(data)
|
|
||||||
.success(function (data) {
|
|
||||||
var base = $location.path().replace(/^\//, '').split('/')[0];
|
|
||||||
if (base === 'users') {
|
|
||||||
$rootScope.flashMessage = 'New user successfully created!';
|
|
||||||
$location.path('/users/' + data.id);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ReturnToCaller(1);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.error(function (data, status) {
|
|
||||||
ProcessErrors($scope, data, status, form, { hdr: 'Error!', msg: 'Failed to add new user. POST returned status: ' + status });
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
$scope.organization_name_api_error = 'A value is required';
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -289,34 +292,37 @@ function UsersEdit($scope, $rootScope, $compile, $location, $log, $routeParams,
|
|||||||
$scope.formSave = function () {
|
$scope.formSave = function () {
|
||||||
var data = {}, fld;
|
var data = {}, fld;
|
||||||
generator.clearApiErrors();
|
generator.clearApiErrors();
|
||||||
|
generator.checkAutoFill();
|
||||||
$rootScope.flashMessage = null;
|
$rootScope.flashMessage = null;
|
||||||
Rest.setUrl(defaultUrl + id + '/');
|
if ($scope[form.name + '_form'].$valid) {
|
||||||
for (fld in form.fields) {
|
Rest.setUrl(defaultUrl + id + '/');
|
||||||
if (form.fields[fld].realName) {
|
for (fld in form.fields) {
|
||||||
data[form.fields[fld].realName] = $scope[fld];
|
if (form.fields[fld].realName) {
|
||||||
} else {
|
data[form.fields[fld].realName] = $scope[fld];
|
||||||
data[fld] = $scope[fld];
|
} else {
|
||||||
|
data[fld] = $scope[fld];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data.is_superuser = data.is_superuser || false;
|
||||||
|
|
||||||
|
Wait('start');
|
||||||
|
Rest.put(data)
|
||||||
|
.success(function () {
|
||||||
|
Wait('stop');
|
||||||
|
var base = $location.path().replace(/^\//, '').split('/')[0];
|
||||||
|
if (base === 'users') {
|
||||||
|
ReturnToCaller();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ReturnToCaller(1);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.error(function (data, status) {
|
||||||
|
ProcessErrors($scope, data, status, form, { hdr: 'Error!', msg: 'Failed to update users: ' + $routeParams.id +
|
||||||
|
'. PUT status: ' + status });
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
data.is_superuser = data.is_superuser || false;
|
|
||||||
|
|
||||||
Wait('start');
|
|
||||||
Rest.put(data)
|
|
||||||
.success(function () {
|
|
||||||
Wait('stop');
|
|
||||||
var base = $location.path().replace(/^\//, '').split('/')[0];
|
|
||||||
if (base === 'users') {
|
|
||||||
ReturnToCaller();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ReturnToCaller(1);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.error(function (data, status) {
|
|
||||||
ProcessErrors($scope, data, status, form, { hdr: 'Error!', msg: 'Failed to update users: ' + $routeParams.id +
|
|
||||||
'. PUT status: ' + status });
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.showActivity = function () {
|
$scope.showActivity = function () {
|
||||||
|
|||||||
@@ -647,7 +647,6 @@ angular.module('Utilities', ['RestServices', 'Utilities'])
|
|||||||
var form = params.form,
|
var form = params.form,
|
||||||
scope = params.scope,
|
scope = params.scope,
|
||||||
fld;
|
fld;
|
||||||
console.log('here');
|
|
||||||
for (fld in form.fields) {
|
for (fld in form.fields) {
|
||||||
if (scope[form.name + '_form'][fld]) {
|
if (scope[form.name + '_form'][fld]) {
|
||||||
console.log(fld + ' valid: ' + scope[form.name + '_form'][fld].$valid);
|
console.log(fld + ' valid: ' + scope[form.name + '_form'][fld].$valid);
|
||||||
|
|||||||
@@ -691,3 +691,21 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Job
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
|
/*
|
||||||
|
.directive('awWatch', [ function() {
|
||||||
|
return {
|
||||||
|
require: 'ngModel',
|
||||||
|
link: function(scope, element, attrs, ngModel) {
|
||||||
|
$(element).change(function() {
|
||||||
|
console.log('here');
|
||||||
|
//var newVal = element.val();
|
||||||
|
//if (newVal && ngModel.$pristine && ngModel.$viewValue !== newVal) {
|
||||||
|
// console.log('setting value');
|
||||||
|
// return ngModel.$setViewValue(newVal);
|
||||||
|
//}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}]);
|
||||||
|
*/
|
||||||
@@ -275,6 +275,21 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies', 'Utilities'])
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
checkAutoFill: function(params) {
|
||||||
|
var fld, model, newVal, type,
|
||||||
|
scope = (params && params.scope) ? params.scope : this.scope;
|
||||||
|
for (fld in this.form.fields) {
|
||||||
|
if (this.form.fields[fld].type === 'text' || this.form.fields[fld].type === 'textarea') {
|
||||||
|
type = (this.form.fields[fld].type === 'text') ? 'input' : 'textarea';
|
||||||
|
model = scope[this.form.name + '_form'][fld];
|
||||||
|
newVal = $(type + '[name="' + fld + '"]').val();
|
||||||
|
if (newVal && model && model.$viewValue !== newVal) {
|
||||||
|
model.$setViewValue(newVal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
addListeners: function () {
|
addListeners: function () {
|
||||||
|
|
||||||
if (this.modal) {
|
if (this.modal) {
|
||||||
@@ -583,7 +598,7 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies', 'Utilities'])
|
|||||||
html += (field.awValidUrl) ? "aw-valid-url " : "";
|
html += (field.awValidUrl) ? "aw-valid-url " : "";
|
||||||
html += (field.associated && this.form.fields[field.associated].ask) ? "ng-disabled=\"" + field.associated + "_ask\" " : "";
|
html += (field.associated && this.form.fields[field.associated].ask) ? "ng-disabled=\"" + field.associated + "_ask\" " : "";
|
||||||
html += (field.awMultiselect) ? "aw-multiselect=\"" + field.awMultiselect + "\" " : "";
|
html += (field.awMultiselect) ? "aw-multiselect=\"" + field.awMultiselect + "\" " : "";
|
||||||
html += " >\n";
|
html += ">\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (field.clear) {
|
if (field.clear) {
|
||||||
@@ -705,7 +720,7 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies', 'Utilities'])
|
|||||||
html += (options.mode === 'edit' && field.editRequired) ? "required " : "";
|
html += (options.mode === 'edit' && field.editRequired) ? "required " : "";
|
||||||
html += (options.mode === 'add' && field.addRequired) ? "required " : "";
|
html += (options.mode === 'add' && field.addRequired) ? "required " : "";
|
||||||
html += (field.readonly || field.showonly) ? "readonly " : "";
|
html += (field.readonly || field.showonly) ? "readonly " : "";
|
||||||
html += "></textarea>\n";
|
html += "aw-watch ></textarea>\n";
|
||||||
|
|
||||||
// Add error messages
|
// Add error messages
|
||||||
if ((options.mode === 'add' && field.addRequired) || (options.mode === 'edit' && field.editRequired)) {
|
if ((options.mode === 'add' && field.addRequired) || (options.mode === 'edit' && field.editRequired)) {
|
||||||
@@ -1270,13 +1285,14 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies', 'Utilities'])
|
|||||||
}
|
}
|
||||||
if (button.ngDisabled) {
|
if (button.ngDisabled) {
|
||||||
if (btn !== 'reset') {
|
if (btn !== 'reset') {
|
||||||
html += "ng-disabled=\"" + this.form.name + "_form.$pristine || " + this.form.name + "_form.$invalid";
|
//html += "ng-disabled=\"" + this.form.name + "_form.$pristine || " + this.form.name + "_form.$invalid";
|
||||||
html += (this.form.allowReadonly) ? " || " + this.form.name + "ReadOnly == true" : "";
|
html += "ng-disabled=\"" + this.form.name + "_form.$invalid";
|
||||||
|
//html += (this.form.allowReadonly) ? " || " + this.form.name + "ReadOnly == true" : "";
|
||||||
html += "\" ";
|
html += "\" ";
|
||||||
} else {
|
} else {
|
||||||
html += "ng-disabled=\"" + this.form.name + "_form.$pristine";
|
//html += "ng-disabled=\"" + this.form.name + "_form.$pristine";
|
||||||
html += (this.form.allowReadonly) ? " || " + this.form.name + "ReadOnly == true" : "";
|
//html += (this.form.allowReadonly) ? " || " + this.form.name + "ReadOnly == true" : "";
|
||||||
html += "\" ";
|
//html += "\" ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
html += ">";
|
html += ">";
|
||||||
|
|||||||
Reference in New Issue
Block a user