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; height: 22px;
font-size: 10.5px; 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(); generator.reset();
}; };
// Password change // Password change
scope.clearPWConfirm = function(fld) { scope.clearPWConfirm = function(fld) {
// If password value changes, make sure password_confirm must be re-entered // If password value changes, make sure password_confirm must be re-entered
scope[fld] = ''; scope[fld] = '';
scope[form.name + '_form'][fld].$setValidity('awpassmatch', false); 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', CredentialsAdd.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'CredentialForm', 'GenerateForm',
@@ -237,6 +251,21 @@ function CredentialsEdit ($scope, $rootScope, $compile, $location, $log, $routeP
field: 'team' 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 // After Credential is loaded, retrieve each related set and any lookups
scope.$on('credentialLoaded', function() { scope.$on('credentialLoaded', function() {
for (var set in relatedSets) { for (var set in relatedSets) {
@@ -260,6 +289,7 @@ function CredentialsEdit ($scope, $rootScope, $compile, $location, $log, $routeP
master[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] = master[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] =
scope[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField]; scope[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField];
} }
setAskCheckboxes();
} }
var related = data.related; var related = data.related;
for (var set in form.related) { for (var set in form.related) {
@@ -288,7 +318,7 @@ function CredentialsEdit ($scope, $rootScope, $compile, $location, $log, $routeP
Rest.put(data) Rest.put(data)
.success( function(data, status, headers, config) { .success( function(data, status, headers, config) {
var base = $location.path().replace(/^\//,'').split('/')[0]; var base = $location.path().replace(/^\//,'').split('/')[0];
(base == 'Credentials') ? ReturnToCaller() : ReturnToCaller(1); (base == 'credentials') ? ReturnToCaller() : ReturnToCaller(1);
}) })
.error( function(data, status, headers, config) { .error( function(data, status, headers, config) {
ProcessErrors(scope, data, status, form, ProcessErrors(scope, data, status, form,
@@ -302,6 +332,7 @@ function CredentialsEdit ($scope, $rootScope, $compile, $location, $log, $routeP
for (var fld in master) { for (var fld in master) {
scope[fld] = master[fld]; scope[fld] = master[fld];
} }
setAskCheckboxes();
}; };
// Related set: Add button // Related set: Add button
@@ -349,6 +380,28 @@ function CredentialsEdit ($scope, $rootScope, $compile, $location, $log, $routeP
scope[form.name + '_form'][fld].$setValidity('awpassmatch', false); 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);
}
} }
CredentialsEdit.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'CredentialForm', CredentialsEdit.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'CredentialForm',

View File

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

View File

@@ -41,9 +41,9 @@ angular.module('CredentialListDefinition', [])
actions: { actions: {
add: { add: {
icon: 'icon-plus', icon: 'icon-plus',
mode: 'select', // One of: edit, select, all mode: 'all', // One of: edit, select, all
ngClick: 'addCredential()', 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', class: 'btn btn-mini btn-success',
awToolTip: 'Create a new credential' awToolTip: 'Create a new credential'
} }

View File

@@ -99,6 +99,9 @@ angular.module('FormGenerator', ['GeneratorHelpers'])
if (this.form.fields[fld].awPassMatch) { if (this.form.fields[fld].awPassMatch) {
this.scope[this.form.name + '_form'][fld].$setValidity('awpassmatch', true); 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') { if (this.mode == 'add') {
this.applyDefaults(); this.applyDefaults();
@@ -164,6 +167,7 @@ angular.module('FormGenerator', ['GeneratorHelpers'])
html += ">\n"; html += ">\n";
html += "<label class=\"control-label\" for=\"" + fld + '">' + field.label + '</label>' + "\n"; html += "<label class=\"control-label\" for=\"" + fld + '">' + field.label + '</label>' + "\n";
html += "<div class=\"controls\">\n"; html += "<div class=\"controls\">\n";
html += (field.clear) ? "<div class=\"input-append\">\n" : "";
html += "<input "; html += "<input ";
html += this.attr(field,'type'); html += this.attr(field,'type');
html += "ng-model=\"" + fld + '" '; html += "ng-model=\"" + fld + '" ';
@@ -176,7 +180,19 @@ angular.module('FormGenerator', ['GeneratorHelpers'])
html += (field.readonly) ? "readonly " : ""; html += (field.readonly) ? "readonly " : "";
html += (field.awPassMatch) ? "awpassmatch=\"" + field.associated + "\" " : ""; html += (field.awPassMatch) ? "awpassmatch=\"" + field.associated + "\" " : "";
html += (field.capitalize) ? "capitalize " : ""; 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 // 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) ) {
html += "<span class=\"error\" ng-show=\"" + this.form.name + '_form.' + fld + ".$dirty && " + 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') { if (options.mode != 'lookup') {
//actions //actions
base = $location.path().replace(/^\//,'').split('/')[0]; base = $location.path().replace(/^\//,'').split('/')[0];
console.log('base: ' + base);
html += "<div class=\"text-right\">\n"; html += "<div class=\"text-right\">\n";
for (action in list.actions) { for (action in list.actions) {
if (list.actions[action].mode == 'all' || list.actions[action].mode == options.mode) { 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') + html += "<button " + this.attr(list.actions[action], 'ngClick') +
this.attr(list.actions[action], 'class'); this.attr(list.actions[action], 'class');
html += (list.actions[action].awToolTip) ? this.attr(list.actions[action],'awToolTip') : ""; html += (list.actions[action].awToolTip) ? this.attr(list.actions[action],'awToolTip') : "";