mirror of
https://github.com/ansible/awx.git
synced 2024-11-02 01:21:21 +03:00
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:
parent
4889681df3
commit
3b95fbd30b
@ -215,7 +215,10 @@ function CredentialsAdd($scope, $rootScope, $compile, $location, $log, $routePar
|
||||
// Save
|
||||
$scope.formSave = function () {
|
||||
generator.clearApiErrors();
|
||||
FormSave({ scope: $scope, mode: 'add' });
|
||||
generator.checkAutoFill();
|
||||
if ($scope[form.name + '_form'].$valid) {
|
||||
FormSave({ scope: $scope, mode: 'add' });
|
||||
}
|
||||
};
|
||||
|
||||
// Handle Owner change
|
||||
@ -420,7 +423,10 @@ function CredentialsEdit($scope, $rootScope, $compile, $location, $log, $routePa
|
||||
// Save changes to the parent
|
||||
$scope.formSave = function () {
|
||||
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
|
||||
|
@ -146,35 +146,38 @@ function UsersAdd($scope, $rootScope, $compile, $location, $log, $routeParams, U
|
||||
|
||||
// Save
|
||||
$scope.formSave = function () {
|
||||
generator.clearApiErrors();
|
||||
var fld, data = {};
|
||||
if ($scope.organization !== undefined && $scope.organization !== null && $scope.organization !== '') {
|
||||
Rest.setUrl(defaultUrl + $scope.organization + '/users/');
|
||||
for (fld in form.fields) {
|
||||
if (form.fields[fld].realName) {
|
||||
data[form.fields[fld].realName] = $scope[fld];
|
||||
} else {
|
||||
data[fld] = $scope[fld];
|
||||
generator.clearApiErrors();
|
||||
generator.checkAutoFill();
|
||||
if ($scope[form.name + '_form'].$valid) {
|
||||
if ($scope.organization !== undefined && $scope.organization !== null && $scope.organization !== '') {
|
||||
Rest.setUrl(defaultUrl + $scope.organization + '/users/');
|
||||
for (fld in form.fields) {
|
||||
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 () {
|
||||
var data = {}, fld;
|
||||
generator.clearApiErrors();
|
||||
generator.checkAutoFill();
|
||||
$rootScope.flashMessage = null;
|
||||
Rest.setUrl(defaultUrl + id + '/');
|
||||
for (fld in form.fields) {
|
||||
if (form.fields[fld].realName) {
|
||||
data[form.fields[fld].realName] = $scope[fld];
|
||||
} else {
|
||||
data[fld] = $scope[fld];
|
||||
if ($scope[form.name + '_form'].$valid) {
|
||||
Rest.setUrl(defaultUrl + id + '/');
|
||||
for (fld in form.fields) {
|
||||
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.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 () {
|
||||
|
@ -647,7 +647,6 @@ angular.module('Utilities', ['RestServices', 'Utilities'])
|
||||
var form = params.form,
|
||||
scope = params.scope,
|
||||
fld;
|
||||
console.log('here');
|
||||
for (fld in form.fields) {
|
||||
if (scope[form.name + '_form'][fld]) {
|
||||
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 () {
|
||||
|
||||
if (this.modal) {
|
||||
@ -583,7 +598,7 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies', 'Utilities'])
|
||||
html += (field.awValidUrl) ? "aw-valid-url " : "";
|
||||
html += (field.associated && this.form.fields[field.associated].ask) ? "ng-disabled=\"" + field.associated + "_ask\" " : "";
|
||||
html += (field.awMultiselect) ? "aw-multiselect=\"" + field.awMultiselect + "\" " : "";
|
||||
html += " >\n";
|
||||
html += ">\n";
|
||||
}
|
||||
|
||||
if (field.clear) {
|
||||
@ -705,7 +720,7 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies', 'Utilities'])
|
||||
html += (options.mode === 'edit' && field.editRequired) ? "required " : "";
|
||||
html += (options.mode === 'add' && field.addRequired) ? "required " : "";
|
||||
html += (field.readonly || field.showonly) ? "readonly " : "";
|
||||
html += "></textarea>\n";
|
||||
html += "aw-watch ></textarea>\n";
|
||||
|
||||
// Add error messages
|
||||
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 (btn !== 'reset') {
|
||||
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.$pristine || " + this.form.name + "_form.$invalid";
|
||||
html += "ng-disabled=\"" + this.form.name + "_form.$invalid";
|
||||
//html += (this.form.allowReadonly) ? " || " + this.form.name + "ReadOnly == true" : "";
|
||||
html += "\" ";
|
||||
} else {
|
||||
html += "ng-disabled=\"" + this.form.name + "_form.$pristine";
|
||||
html += (this.form.allowReadonly) ? " || " + this.form.name + "ReadOnly == true" : "";
|
||||
html += "\" ";
|
||||
//html += "ng-disabled=\"" + this.form.name + "_form.$pristine";
|
||||
//html += (this.form.allowReadonly) ? " || " + this.form.name + "ReadOnly == true" : "";
|
||||
//html += "\" ";
|
||||
}
|
||||
}
|
||||
html += ">";
|
||||
|
Loading…
Reference in New Issue
Block a user