diff --git a/awx/ui/static/js/controllers/Credentials.js b/awx/ui/static/js/controllers/Credentials.js index 7a61ed52e5..075d770730 100644 --- a/awx/ui/static/js/controllers/Credentials.js +++ b/awx/ui/static/js/controllers/Credentials.js @@ -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 diff --git a/awx/ui/static/js/controllers/Users.js b/awx/ui/static/js/controllers/Users.js index cce503405f..ae3ab243c8 100644 --- a/awx/ui/static/js/controllers/Users.js +++ b/awx/ui/static/js/controllers/Users.js @@ -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 () { diff --git a/awx/ui/static/lib/ansible/Utilities.js b/awx/ui/static/lib/ansible/Utilities.js index e606f7b079..8767ca5359 100644 --- a/awx/ui/static/lib/ansible/Utilities.js +++ b/awx/ui/static/lib/ansible/Utilities.js @@ -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); diff --git a/awx/ui/static/lib/ansible/directives.js b/awx/ui/static/lib/ansible/directives.js index d3b934de74..fc199d2624 100644 --- a/awx/ui/static/lib/ansible/directives.js +++ b/awx/ui/static/lib/ansible/directives.js @@ -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); + //} + }); + } + }; + }]); + */ \ No newline at end of file diff --git a/awx/ui/static/lib/ansible/form-generator.js b/awx/ui/static/lib/ansible/form-generator.js index 8e76522ce0..53547b6a78 100644 --- a/awx/ui/static/lib/ansible/form-generator.js +++ b/awx/ui/static/lib/ansible/form-generator.js @@ -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 += ">\n"; + html += "aw-watch >\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 += ">";