Credentials add\/edit now works. Ask checkbox is functional.

This commit is contained in:
chouseknecht 2013-05-10 04:09:28 -04:00
parent fdceb46c12
commit 0ff66f668d
6 changed files with 93 additions and 10 deletions

View File

@ -218,3 +218,7 @@
height: 22px;
font-size: 10.5px;
}
.ask-checkbox {
margin-left: 10px;
}

View File

@ -190,12 +190,26 @@ function CredentialsAdd ($scope, $rootScope, $compile, $location, $log, $routePa
generator.reset();
};
// Password change
// Password change
scope.clearPWConfirm = function(fld) {
// If password value changes, make sure password_confirm must be re-entered
scope[fld] = '';
scope[form.name + '_form'][fld].$setValidity('awpassmatch', false);
}
// Respond to 'Ask at runtime?' checkbox
scope.ask = function(fld, associated) {
if (scope[fld + '_ask']) {
scope[fld] = 'ASK';
scope[associated] = '';
scope[form.name + '_form'][associated].$setValidity('awpassmatch', true);
}
else {
scope[fld] = '';
scope[associated] = '';
scope[form.name + '_form'][associated].$setValidity('awpassmatch', true);
}
}
}
CredentialsAdd.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'CredentialForm', 'GenerateForm',
@ -236,6 +250,21 @@ function CredentialsEdit ($scope, $rootScope, $compile, $location, $log, $routeP
list: TeamList,
field: 'team'
});
function setAskCheckboxes() {
for (var fld in form.fields) {
if (form.fields[fld].type == 'password' && form.fields[fld].ask && scope[fld] == 'ASK') {
// turn on 'ask' checkbox for password fields with value of 'ASK'
$("#" + fld + "-clear-btn").attr("disabled","disabled");
scope[fld + '_ask'] = true;
}
else {
scope[fld + '_ask'] = false;
$("#" + fld + "-clear-btn").removeAttr("disabled");
}
}
}
// After Credential is loaded, retrieve each related set and any lookups
scope.$on('credentialLoaded', function() {
@ -260,6 +289,7 @@ function CredentialsEdit ($scope, $rootScope, $compile, $location, $log, $routeP
master[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] =
scope[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField];
}
setAskCheckboxes();
}
var related = data.related;
for (var set in form.related) {
@ -288,7 +318,7 @@ function CredentialsEdit ($scope, $rootScope, $compile, $location, $log, $routeP
Rest.put(data)
.success( function(data, status, headers, config) {
var base = $location.path().replace(/^\//,'').split('/')[0];
(base == 'Credentials') ? ReturnToCaller() : ReturnToCaller(1);
(base == 'credentials') ? ReturnToCaller() : ReturnToCaller(1);
})
.error( function(data, status, headers, config) {
ProcessErrors(scope, data, status, form,
@ -302,6 +332,7 @@ function CredentialsEdit ($scope, $rootScope, $compile, $location, $log, $routeP
for (var fld in master) {
scope[fld] = master[fld];
}
setAskCheckboxes();
};
// Related set: Add button
@ -348,6 +379,28 @@ function CredentialsEdit ($scope, $rootScope, $compile, $location, $log, $routeP
scope[fld] = '';
scope[form.name + '_form'][fld].$setValidity('awpassmatch', false);
}
// Respond to 'Ask at runtime?' checkbox
scope.ask = function(fld, associated) {
if (scope[fld + '_ask']) {
$("#" + fld + "-clear-btn").attr("disabled","disabled");
scope[fld] = 'ASK';
scope[associated] = '';
scope[form.name + '_form'][associated].$setValidity('awpassmatch', true);
}
else {
$("#" + fld + "-clear-btn").removeAttr("disabled");
scope[fld] = '';
scope[associated] = '';
scope[form.name + '_form'][associated].$setValidity('awpassmatch', true);
}
}
scope.clear = function(fld, associated) {
scope[fld] = '';
scope[associated] = '';
scope[form.name + '_form'][associated].$setValidity('awpassmatch', true);
}
}

View File

@ -39,7 +39,10 @@ angular.module('CredentialFormDefinition', [])
type: 'password',
addRequired: false,
editRequired: false,
ngChange: "clearPWConfirm('ssh_password_confirm')"
ngChange: "clearPWConfirm('ssh_password_confirm')",
ask: true,
clear: true,
associated: 'ssh_password_confirm'
},
"ssh_password_confirm": {
label: 'Confirm SSH Password',
@ -61,7 +64,10 @@ angular.module('CredentialFormDefinition', [])
type: 'password',
addRequired: false,
editRequired: false,
ngChange: "clearPWConfirm('ssh_key_unlock_confirm')"
ngChange: "clearPWConfirm('ssh_key_unlock_confirm')",
associated: 'ssh_key_unlock_confirm',
ask: true,
clear: true
},
"ssh_key_unlock_confirm": {
label: 'Confirm Key Password',
@ -79,10 +85,13 @@ angular.module('CredentialFormDefinition', [])
},
"sudo_password": {
label: 'Sudo Password',
type: 'text',
type: 'password',
addRequired: false,
editRequired: false,
ngChange: "clearPWConfirm('sudo_password_confirm')"
ngChange: "clearPWConfirm('sudo_password_confirm')",
ask: true,
clear: true,
associated: 'sudo_password_confirm'
},
"sudo_password_confirm": {
label: 'Confirm Sudo Password',

View File

@ -41,9 +41,9 @@ angular.module('CredentialListDefinition', [])
actions: {
add: {
icon: 'icon-plus',
mode: 'select', // One of: edit, select, all
mode: 'all', // One of: edit, select, all
ngClick: 'addCredential()',
basePaths: ['credentials'], // base path must be in list, or action not available
basePaths: ['credentials'], // base path must be in list, or action not available
class: 'btn btn-mini btn-success',
awToolTip: 'Create a new credential'
}

View File

@ -99,6 +99,9 @@ angular.module('FormGenerator', ['GeneratorHelpers'])
if (this.form.fields[fld].awPassMatch) {
this.scope[this.form.name + '_form'][fld].$setValidity('awpassmatch', true);
}
if (this.form.fields[fld].ask) {
this.scope[fld + '_ask'] = false;
}
}
if (this.mode == 'add') {
this.applyDefaults();
@ -164,6 +167,7 @@ angular.module('FormGenerator', ['GeneratorHelpers'])
html += ">\n";
html += "<label class=\"control-label\" for=\"" + fld + '">' + field.label + '</label>' + "\n";
html += "<div class=\"controls\">\n";
html += (field.clear) ? "<div class=\"input-append\">\n" : "";
html += "<input ";
html += this.attr(field,'type');
html += "ng-model=\"" + fld + '" ';
@ -176,7 +180,19 @@ angular.module('FormGenerator', ['GeneratorHelpers'])
html += (field.readonly) ? "readonly " : "";
html += (field.awPassMatch) ? "awpassmatch=\"" + field.associated + "\" " : "";
html += (field.capitalize) ? "capitalize " : "";
html += "/><br />\n";
html += (field.ask) ? "ng-disabled=\"" + fld + "_ask\" " : "";
html += (field.associated && this.form.fields[field.associated].ask) ? "ng-disabled=\"" + field.associated + "_ask\" " : "";
html += "/>";
if (field.clear) {
html += " \n<button class=\"btn\" ng-click=\"clear('" + fld + "','" + field.associated + "')\" " +
"aw-tool-tip=\"Clear " + field.label + "\" id=\"" + fld + "-clear-btn\"><i class=\"icon-undo\"></i></button>\n";
html += "</div>\n";
}
if (field.ask) {
html += " \n<label class=\"checkbox inline ask-checkbox\"><input type=\"checkbox\" ng-model=\"" +
fld + "_ask\" ng-change=\"ask('" + fld + "','" + field.associated + "')\" /> Ask at runtime?</label>";
}
html += "<br />\n";
// Add error messages
if ( (options.mode == 'add' && field.addRequired) || (options.mode == 'edit' && field.editRequired) ) {
html += "<span class=\"error\" ng-show=\"" + this.form.name + '_form.' + fld + ".$dirty && " +

View File

@ -129,10 +129,11 @@ angular.module('ListGenerator', ['GeneratorHelpers',])
if (options.mode != 'lookup') {
//actions
base = $location.path().replace(/^\//,'').split('/')[0];
console.log('base: ' + base);
html += "<div class=\"text-right\">\n";
for (action in list.actions) {
if (list.actions[action].mode == 'all' || list.actions[action].mode == options.mode) {
if (list.basePaths && list.basePaths.indexOf(base) > -1) {
if ( (list.basePaths == undefined) || (list.basePaths && list.basePaths.indexOf(base) > -1) ) {
html += "<button " + this.attr(list.actions[action], 'ngClick') +
this.attr(list.actions[action], 'class');
html += (list.actions[action].awToolTip) ? this.attr(list.actions[action],'awToolTip') : "";