fixed css/styling on job launch modal for inputs

the styling was not uniform throughout the job launch modal window, cleaned this up
This commit is contained in:
Jared Tabor
2014-10-17 12:46:27 -04:00
parent 8f46719ef3
commit ece2acc956
2 changed files with 176 additions and 301 deletions

View File

@@ -14,25 +14,60 @@
angular.module('JobSubmissionHelper', [ 'RestServices', 'Utilities', 'CredentialFormDefinition', 'CredentialsListDefinition', angular.module('JobSubmissionHelper', [ 'RestServices', 'Utilities', 'CredentialFormDefinition', 'CredentialsListDefinition',
'LookUpHelper', 'JobSubmissionHelper', 'JobTemplateFormDefinition', 'ModalDialog', 'FormGenerator', 'JobVarsPromptFormDefinition']) 'LookUpHelper', 'JobSubmissionHelper', 'JobTemplateFormDefinition', 'ModalDialog', 'FormGenerator', 'JobVarsPromptFormDefinition'])
.factory('LaunchJob', ['Rest', 'Wait', 'ProcessErrors', .factory('LaunchJob', ['Rest', 'Wait', 'ProcessErrors', 'ToJSON',
function(Rest, Wait, ProcessErrors) { function(Rest, Wait, ProcessErrors, ToJSON) {
return function(params) { return function(params) {
var scope = params.scope, var scope = params.scope,
passwords = params.passwords || {}, // passwords = params.passwords || {},
callback = params.callback || 'JobLaunched', callback = params.callback || 'JobLaunched',
url = params.url; job_launch_data = {},
url = params.url,
fld;
if(scope.passwords_needed_to_start.length>0){
scope.passwords.forEach(function(password) {
job_launch_data[password] = scope[password];
});
}
if(scope.prompt_for_vars===true){
job_launch_data.extra_vars = ToJSON(scope.parseType, scope.variables, true);
}
if(scope.survey_enabled===true){
for (fld in scope.job_launch_form){
if(scope[fld]){
job_launch_data[fld] = scope[fld];
}
}
}
Wait('start');
Rest.setUrl(url); Rest.setUrl(url);
Rest.post(passwords) Rest.post(job_launch_data)
.success(function(data) { .success(function(data) {
scope.new_job_id = data.job; Wait('stop');
if(!$('#password-modal').is(':hidden')){
$('#password-modal').dialog('close');
}
scope.$emit(callback, data); scope.$emit(callback, data);
scope.$destroy();
}) })
.error(function (data, status) { .error(function(data, status) {
ProcessErrors(scope, data, status, null, { hdr: 'Error!', ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'Attempt to start job at ' + url + ' failed. POST returned: ' + status }); msg: 'Failed updating job ' + scope.job_template_id + ' with variables. PUT returned: ' + status });
}); });
// Wait('start');
// Rest.setUrl(url);
// Rest.post(passwords)
// .success(function(data) {
// scope.new_job_id = data.job;
// scope.$emit(callback, data);
// })
// .error(function (data, status) {
// ProcessErrors(scope, data, status, null, { hdr: 'Error!',
// msg: 'Attempt to start job at ' + url + ' failed. POST returned: ' + status });
// });
}; };
}]) }])
@@ -106,16 +141,16 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi
.factory('CreateLaunchDialog', ['$compile', 'Rest', 'GetBasePath', 'TextareaResize', 'CreateDialog', 'GenerateForm', .factory('CreateLaunchDialog', ['$compile', 'Rest', 'GetBasePath', 'TextareaResize', 'CreateDialog', 'GenerateForm',
'JobVarsPromptForm', 'Wait', 'ProcessErrors', 'ToJSON', 'JobVarsPromptForm', 'Wait',
function($compile, Rest, GetBasePath, TextareaResize,CreateDialog, GenerateForm, function($compile, Rest, GetBasePath, TextareaResize,CreateDialog, GenerateForm,
JobVarsPromptForm, Wait, ProcessErrors, ToJSON) { JobVarsPromptForm, Wait) {
return function(params) { return function(params) {
var buttons, var buttons,
scope = params.scope, scope = params.scope,
html = params.html, html = params.html,
job_launch_data = {}, // job_launch_data = {},
callback = params.callback || 'PlaybookLaunchFinished', callback = params.callback || 'PlaybookLaunchFinished',
url = params.url, // url = params.url,
e; e;
// html+='<br>job_launch_form.$valid = {{job_launch_form.$valid}}<br>'; // html+='<br>job_launch_form.$valid = {{job_launch_form.$valid}}<br>';
@@ -125,46 +160,12 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi
e = angular.element(document.getElementById('password-modal')); e = angular.element(document.getElementById('password-modal'));
$compile(e)(scope); $compile(e)(scope);
scope.jobLaunchFormAccept = function(){
if(scope.passwords_needed_to_start.length>0){
scope.passwords.forEach(function(password) {
job_launch_data[password] = scope[password];
});
}
if(scope.prompt_for_vars===true){
job_launch_data.extra_vars = ToJSON(scope.parseType, scope.variables, true);
}
if(scope.survey_enabled===true){
for ( var fld in scope.job_launch_form){
if(scope[fld]){
job_launch_data[fld] = scope[fld];
}
}
}
Rest.setUrl(url);
Rest.post(job_launch_data)
.success(function(data) {
Wait('stop');
$('#password-modal').dialog('close');
scope.$emit(callback, data);
scope.$destroy();
})
.error(function(data, status) {
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'Failed updating job ' + scope.job_template_id + ' with variables. PUT returned: ' + status });
});
};
buttons = [{ buttons = [{
label: "Cancel", label: "Cancel",
onClick: function() { onClick: function() {
$('password-modal').close(); $('#password-modal').dialog('close');
// scope.$emit('CancelJob');
// scope.$destroy();
}, },
icon: "fa-times", icon: "fa-times",
"class": "btn btn-default", "class": "btn btn-default",
@@ -172,7 +173,7 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi
},{ },{
label: "Continue", label: "Continue",
onClick: function() { onClick: function() {
scope.jobLaunchFormAccept(); scope.$emit(callback);
}, },
icon: "fa-check", icon: "fa-check",
"class": "btn btn-primary", "class": "btn btn-primary",
@@ -216,7 +217,7 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi
callback = params.callback || 'PasswordsAccepted', callback = params.callback || 'PasswordsAccepted',
url = params.url, url = params.url,
form = CredentialForm, form = CredentialForm,
acceptedPasswords = {}, // acceptedPasswords = {},
fld, field, fld, field,
html=params.html || ""; html=params.html || "";
@@ -324,21 +325,21 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi
} }
}; };
scope.passwordAccept = function() { // scope.passwordAccept = function() {
if (!scope.password_form.$invalid) { // if (!scope.password_form.$invalid) {
scope.passwords.forEach(function(password) { // scope.passwords.forEach(function(password) {
acceptedPasswords[password] = scope[password]; // acceptedPasswords[password] = scope[password];
}); // });
$('#password-modal').dialog('close'); // $('#password-modal').dialog('close');
scope.$emit(callback, acceptedPasswords); // scope.$emit(callback, acceptedPasswords);
} // }
}; // };
scope.passwordCancel = function() { // scope.passwordCancel = function() {
$('#password-modal').dialog('close'); // $('#password-modal').dialog('close');
scope.$emit('CancelJob'); // scope.$emit('CancelJob');
scope.$destroy(); // scope.$destroy();
}; // };
// Password change // Password change
scope.clearPWConfirm = function (fld) { scope.clearPWConfirm = function (fld) {
@@ -368,7 +369,7 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi
// parent_scope = params.scope, // parent_scope = params.scope,
scope = params.scope, scope = params.scope,
callback = params.callback, callback = params.callback,
job = params.job, // job = params.job,
url = params.url, url = params.url,
vars_url = GetBasePath('job_templates')+scope.job_template_id + '/', vars_url = GetBasePath('job_templates')+scope.job_template_id + '/',
// e, helpContainer, // e, helpContainer,
@@ -496,29 +497,29 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi
// callback: 'DialogReady' // callback: 'DialogReady'
// }); // });
scope.varsCancel = function() { // scope.varsCancel = function() {
$('#password-modal').dialog('close'); // $('#password-modal').dialog('close');
scope.$emit('CancelJob'); // scope.$emit('CancelJob');
scope.$destroy(); // scope.$destroy();
}; // };
scope.varsAccept = function() { // scope.varsAccept = function() {
job.extra_vars = ToJSON(scope.parseType, scope.variables, true); // job.extra_vars = ToJSON(scope.parseType, scope.variables, true);
Wait('start'); // Wait('start');
//Rest.setUrl(GetBasePath('jobs') + job.id + '/'); // //Rest.setUrl(GetBasePath('jobs') + job.id + '/');
Rest.setUrl(url); // Rest.setUrl(url);
Rest.put(job) // Rest.put(job)
.success(function() { // .success(function() {
Wait('stop'); // Wait('stop');
$('#password-modal').dialog('close'); // $('#password-modal').dialog('close');
scope.$emit(callback); // scope.$emit(callback);
scope.$destroy(); // scope.$destroy();
}) // })
.error(function(data, status) { // .error(function(data, status) {
ProcessErrors(scope, data, status, null, { hdr: 'Error!', // ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'Failed updating job ' + job.id + ' with variables. PUT returned: ' + status }); // msg: 'Failed updating job ' + job.id + ' with variables. PUT returned: ' + status });
}); // });
}; // };
}; };
}]) }])
@@ -531,6 +532,7 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi
var html = params.html || "", var html = params.html || "",
id= params.id, id= params.id,
url = params.url, url = params.url,
callback=params.callback,
scope = params.scope, scope = params.scope,
i, j, i, j,
requiredAsterisk, requiredAsterisk,
@@ -545,110 +547,88 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi
function buildHtml(question, index){ function buildHtml(question, index){
question.index = index; question.index = index;
if(!$('#taker_'+question.index+':eq(0)').is('div')){
html+='<div id="taker_'+question.index+'" class="survey_taker_question row">';
$('#survey_taker_finalized_questions').append(html);
}
requiredAsterisk = (question.required===true) ? "prepend-asterisk" : ""; requiredAsterisk = (question.required===true) ? "prepend-asterisk" : "";
html+='<div id="taker_'+question.index+'" class="form-group '+requiredAsterisk+' ">';
requiredClasses = (question.required===true) ? "ng-pristine ng-invalid-required ng-invalid" : ""; requiredClasses = (question.required===true) ? "ng-pristine ng-invalid-required ng-invalid" : "";
html += '<div class="col-xs-12 '+requiredAsterisk+'"><b>'+question.question_name+'</b></div>\n'; html += '<label for="'+question.variable+'">'+question.question_name+'</label>\n';
if(!Empty(question.question_description)){ if(!Empty(question.question_description)){
html += '<div class="col-xs-12 survey_taker_description"><i>'+question.question_description+'</i></div>\n'; html += '<div class="survey_taker_description"><i>'+question.question_description+'</i></div>\n';
} }
scope[question.variable] = question.default; scope[question.variable] = question.default;
if(question.type === 'text' ){
//defaultValue = (question.default) ? question.default : "";
html+='<div class="row">'+ if(question.type === 'text' ){
'<div class="col-xs-8">'+ html+='<input type="text" id="'+question.variable+'" ng-model="'+question.variable+'" '+
'<input type="text" id="'+question.variable+'" ng-model="'+question.variable+'" '+
'name="'+question.variable+'" '+ 'name="'+question.variable+'" '+
'class="form-control survey_taker_input ng-pristine ng-invalid-required ng-invalid" required="" >'+ 'class="form-control ng-pristine ng-invalid-required ng-invalid" required="" >'+
'<div class="error survey_error" ng-show="job_launch_form.'+ question.variable + '.$dirty && ' + '<div class="error survey_error" ng-show="job_launch_form.'+ question.variable + '.$dirty && ' +
'job_launch_form.'+question.variable+'.$error.required\">A value is required!</div>'+ 'job_launch_form.'+question.variable+'.$error.required\">A value is required!</div>'+
'<div class=\"error api-error\" ng-bind=\"" + fld + "_api_error\"></div>'+ '<div class=\"error api-error\" ng-bind=\"" + fld + "_api_error\"></div>';
'</div>'+
'</div>';
} }
if(question.type === "textarea"){ if(question.type === "textarea"){
scope[question.variable] = question.default || question.default_textarea; scope[question.variable] = question.default || question.default_textarea;
html+='<div class="row">'+ html+='<textarea id="'+question.variable+'" name="'+question.variable+'" ng-model="'+question.variable+'" '+
'<div class="col-xs-8">'+ 'class="form-control ng-pristine ng-invalid-required ng-invalid final" required="" rows="3"></textarea>'+
'<textarea id="'+question.variable+'" name="'+question.variable+'" ng-model="'+question.variable+'" '+
'class="form-control survey_taker_input ng-pristine ng-invalid-required ng-invalid final" required="" rows="3"></textarea>'+
'<div class="error survey_error" ng-show="job_launch_form.'+ question.variable + '.$dirty && ' + '<div class="error survey_error" ng-show="job_launch_form.'+ question.variable + '.$dirty && ' +
'job_launch_form.'+question.variable+'.$error.required\">A value is required!</div>'+ 'job_launch_form.'+question.variable+'.$error.required\">A value is required!</div>'+
'<div class=\"error api-error\" ng-bind=\"" + fld + "_api_error\"></div>'+ '<div class=\"error api-error\" ng-bind=\"" + fld + "_api_error\"></div>';
'</div></div>';
} }
if(question.type === 'multiplechoice'){ if(question.type === 'multiplechoice'){
choices = question.choices.split(/\n/); choices = question.choices.split(/\n/);
element = (question.type==="multiselect") ? "checkbox" : 'radio'; element = (question.type==="multiselect") ? "checkbox" : 'radio';
question.default = (question.default) ? question.default : (question.default_multiselect) ? question.default_multiselect : "" ; question.default = (question.default) ? question.default : (question.default_multiselect) ? question.default_multiselect : "" ;
html+='<div class="survey_taker_input" > '; html+='<div class="survey_taker_input" > ';
for( j = 0; j<choices.length; j++){ for( j = 0; j<choices.length; j++){
checked = (!Empty(question.default) && question.default.indexOf(choices[j])!==-1) ? "checked" : ""; checked = (!Empty(question.default) && question.default.indexOf(choices[j])!==-1) ? "checked" : "";
// html+='<label class="'+element+'-inline">'+
// '<input class="survey_taker_input" type="'+element+'" name="'+question.variable+ ' " id="" value=" '+choices[j]+' " '+checked+' >' +choices[j]+
// '</label>';
html+= '<input type="'+element+'" class="mc" ng-model="'+question.variable+'" ng-required="!'+question.variable+'" name="'+question.variable+ ' " id="'+question.variable+'" value=" '+choices[j]+' " '+checked+' >' + html+= '<input type="'+element+'" class="mc" ng-model="'+question.variable+'" ng-required="!'+question.variable+'" name="'+question.variable+ ' " id="'+question.variable+'" value=" '+choices[j]+' " '+checked+' >' +
'<span>'+choices[j] +'</span><br>' ; '<span>'+choices[j] +'</span><br>' ;
} }
html+= '<div class="error survey_error" ng-show="job_launch_form.'+ question.variable + '.$dirty && ' + html+= '<div class="error survey_error" ng-show="job_launch_form.'+ question.variable + '.$dirty && ' +
'job_launch_form.'+question.variable+'.$error.required\">A value is required!</div>'+ 'job_launch_form.'+question.variable+'.$error.required\">A value is required!</div>'+
'<div class=\"error api-error\" ng-bind=\"" + fld + "_api_error\"></div>'; '<div class=\"error api-error\" ng-bind=\"" + fld + "_api_error\"></div>';
html+= '</div>'; html+= '</div>'; //end survey_taker_input
} }
if(question.type === "multiselect"){ if(question.type === "multiselect"){
choices = question.choices.split(/\n/); choices = question.choices.split(/\n/);
element = (question.type==="multiselect") ? "checkbox" : 'radio'; element = (question.type==="multiselect") ? "checkbox" : 'radio';
question.default = (question.default) ? question.default : (question.default_multiselect) ? question.default_multiselect : "" ; question.default = (question.default) ? question.default : (question.default_multiselect) ? question.default_multiselect : "" ;
// scope[question.variable].choices = choices; // scope[question.variable].choices = choices;
html+='<div class="survey_taker_input" > '; html+='<div class="survey_taker_input" > ';
for( j = 0; j<choices.length; j++){ for( j = 0; j<choices.length; j++){
checked = (!Empty(question.default) && question.default.indexOf(choices[j])!==-1) ? "checked" : ""; checked = (!Empty(question.default) && question.default.indexOf(choices[j])!==-1) ? "checked" : "";
html+= '<input type="checkbox" class="mc" ng-required="!'+question.variable+'" name="'+question.variable+ ' " id="'+question.variable+'" value=" '+choices[j]+' " '+checked+' >' + html+= '<input type="checkbox" class="mc" ng-required="!'+question.variable+'" name="'+question.variable+ ' " id="'+question.variable+'" value=" '+choices[j]+' " '+checked+' >' +
'<span>'+choices[j] +'</span><br>' ; '<span>'+choices[j] +'</span><br>' ;
} }
html+= '<div class="error survey_error" ng-show="job_launch_form.'+ question.variable + '.$dirty && ' + html+= '<div class="error survey_error" ng-show="job_launch_form.'+ question.variable + '.$dirty && ' +
'job_launch_form.'+question.variable+'.$error.required\">A value is required!</div>'+ 'job_launch_form.'+question.variable+'.$error.required\">A value is required!</div>'+
'<div class=\"error api-error\" ng-bind=\"" + fld + "_api_error\"></div>'; '<div class=\"error api-error\" ng-bind=\"" + fld + "_api_error\"></div>';
html+= '</div>'; html+= '</div>'; //end survey_taker_input
} }
if(question.type === 'integer'){ if(question.type === 'integer'){
min = (!Empty(question.min)) ? Number(question.min) : ""; min = (!Empty(question.min)) ? Number(question.min) : "";
max = (!Empty(question.max)) ? Number(question.max) : "" ; max = (!Empty(question.max)) ? Number(question.max) : "" ;
//defaultValue = (!Empty(question.default)) ? question.default : (!Empty(question.default_int)) ? question.default_int : "" ; html+='<input type="number" id="'+question.variable+'" class=" form-control" name="'+question.variable+'" ng-min="'+min+'" ng-max="'+max+'" ng-model="'+question.variable+' " integer>'+
html+='<div class="row">'+
'<div class="col-xs-8">'+
'<input type="number" id="'+question.variable+'" class="survey_taker_input form-control" name="'+question.variable+'" ng-min="'+min+'" ng-max="'+max+'" ng-model="'+question.variable+' " integer>'+
'<div class="error survey_error" ng-show="job_launch_form.'+question.variable+'.$error.number || job_launch_form.'+question.variable+'.$error.integer">This is not valid integer!</div>'+ '<div class="error survey_error" ng-show="job_launch_form.'+question.variable+'.$error.number || job_launch_form.'+question.variable+'.$error.integer">This is not valid integer!</div>'+
'<div class="error survey_error" ng-show="job_launch_form.'+question.variable+'.$error.ngMin || job_launch_form.'+question.variable+'.$error.ngMax"> The value must be in range {{'+min+'}} to {{'+max+'}}!</div>'+ '<div class="error survey_error" ng-show="job_launch_form.'+question.variable+'.$error.ngMin || job_launch_form.'+question.variable+'.$error.ngMax"> The value must be in range {{'+min+'}} to {{'+max+'}}!</div>';
'</div></div>';
} }
if(question.type === "float"){ if(question.type === "float"){
min = (!Empty(question.min)) ? question.min : ""; min = (!Empty(question.min)) ? question.min : "";
max = (!Empty(question.max)) ? question.max : "" ; max = (!Empty(question.max)) ? question.max : "" ;
defaultValue = (!Empty(question.default)) ? question.default : (!Empty(question.default_float)) ? question.default_float : "" ; defaultValue = (!Empty(question.default)) ? question.default : (!Empty(question.default_float)) ? question.default_float : "" ;
html+='<div class="row">'+ html+='<input type="number" id="'+question.variable+'" class=" form-control" name="'+question.variable+'" ng-min="'+min+'" ng-max="'+max+'" ng-model="'+question.variable+'" smart-float>'+
'<div class="col-xs-8">'+
'<input type="number" id="'+question.variable+'" class="survey_taker_input form-control" name="'+question.variable+'" ng-min="'+min+'" ng-max="'+max+'" ng-model="'+question.variable+'" smart-float>'+
'<div class="error survey_error" ng-show="job_launch_form.'+question.variable+'.$error.number || job_launch_form.'+question.variable+'.$error.float">This is not valid float!</div>'+ '<div class="error survey_error" ng-show="job_launch_form.'+question.variable+'.$error.number || job_launch_form.'+question.variable+'.$error.float">This is not valid float!</div>'+
'<div class="error survey_error" ng-show="job_launch_form.'+question.variable+'.$error.ngMin || job_launch_form.'+question.variable+'.$error.ngMax"> The value must be in range {{'+min+'}} to {{'+max+'}}!</div>'+ '<div class="error survey_error" ng-show="job_launch_form.'+question.variable+'.$error.ngMin || job_launch_form.'+question.variable+'.$error.ngMax"> The value must be in range {{'+min+'}} to {{'+max+'}}!</div>';
'</div></div>';
} }
html+='</div>'; html+='</div>';
if(question.index === scope.survey_questions.length-1){ if(question.index === scope.survey_questions.length-1){
CreateLaunchDialog({scope: scope, html: html, url: url}); scope.$emit(callback, html, url);
} }
} }
@@ -658,126 +638,19 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi
}); });
}; };
// question.index = index;
// question[question.variable] = question.default;
// scope[question.variable] = question.default;
// if(!$('#question_'+question.index+':eq(0)').is('div')){
// html+='<div id="question_'+question.index+'" class="survey_taker_question_final row"></div>';
// $('#survey_taker_finalized_questions').append(html);
// }
// requiredAsterisk = (question.required===true) ? "prepend-asterisk" : "";
// requiredClasses = (question.required===true) ? "ng-pristine ng-invalid-required ng-invalid" : "";
// html += '<div class="col-xs-12 '+requiredAsterisk+'"><b>'+question.question_name+'</b></div>\n';
// if(!Empty(question.question_description)){
// html += '<div class="col-xs-12 description"><i>'+question.question_description+'</i></div>\n';
// }
// defaultValue = (question.default) ? question.default : "";
// if(question.type === 'text' ){
// html+='<div class="row">'+
// '<div class="col-xs-8">'+
// '<input type="text" ng-model="'+question.variable+'" '+ //placeholder="'+defaultValue+'"
// 'class="form-control '+requiredClasses+' final" required="" >'+
// '</div></div>';
// }
// if(question.type === "textarea"){
// html+='<div class="row">'+
// '<div class="col-xs-8">'+
// '<textarea ng-model="'+question.variable+'" class="form-control '+requiredClasses+' final" required="" rows="3" >'+//defaultValue+
// '</textarea>'+
// '</div></div>';
// }
// if(question.type === 'multiplechoice' || question.type === "multiselect"){
// choices = question.choices.split(/\n/);
// element = (question.type==="multiselect") ? "checkbox" : 'radio';
// for( i = 0; i<choices.length; i++){
// checked = (!Empty(question.default) && question.default.indexOf(choices[i].trim())!==-1) ? "checked" : "";
// html+='<label class="'+element+'-inline final">'+
// '<input type="'+element+'" name="'+question.variable+ ' " id="" value=" '+choices[i]+' " '+checked+' >' +choices[i]+
// '</label>';
// }
// }
// if(question.type === 'integer' || question.type === "float"){
// min = (question.min) ? question.min : "";
// max = (question.max) ? question.max : "" ;
// html+='<div class="row">'+
// '<div class="col-xs-8">'+
// '<input type="number" class="final" name="'+question.variable+'" min="'+min+'" max="'+max+'" value="'+defaultValue+'">'+
// '</div></div>';
// }
// if (scope.removeDialogReady) {
// scope.removeDialogReady();
// }
// scope.removeDialogReady = scope.$on('DialogReady', function() {
// $('#password-modal').dialog('open');
// $('#finalized_questions').attr('opacity', 1.0);
// // $('#surveyName').focus();
// // $('#question_unique_required_chbox').prop('checked' , true);
// });
// if (scope.removeSurveyTakerCompleted) {
// scope.removeSurveyTakerCompleted();
// }
// scope.removeSurveyTakerCompleted = scope.$on('SurveyTakerCompleted', function() {
// for(i=0; i<scope.survey_questions.length; i++){
// survey_vars[scope.survey_questions[i].variable] = scope[scope.survey_questions[i].variable];
// }
// Wait('start');
// Rest.setUrl(url);
// Rest.post(survey_vars)
// .success(function(data) {
// scope.new_job_id = data.job;
// // scope.$emit(callback, data);
// $('#password-modal').dialog('close');
// scope.$emit('StartPlaybookRun', passwords);
// })
// .error(function (data, status) {
// ProcessErrors(scope, data, status, null, { hdr: 'Error!',
// msg: 'Attempt to start job at ' + url + ' failed. POST returned: ' + status });
// });
// });
Rest.setUrl(survey_url); Rest.setUrl(survey_url);
Rest.get() Rest.get()
.success(function (data) { .success(function (data) {
if(!Empty(data)){ if(!Empty(data)){
// generator.inject(form, { id: 'password-modal' , mode: 'edit', related: false, scope: scope, breadCrumbs: false });
// ShowSurveyModal({ title: data.name, scope: scope, callback: 'DialogReady' , mode: 'survey-taker'});
scope.survey_name = data.name; scope.survey_name = data.name;
scope.survey_description = data.description; scope.survey_description = data.description;
scope.survey_questions = data.spec; scope.survey_questions = data.spec;
// if(!Empty(scope.survey_description)){
// $('#survey_taker_description').append(scope.survey_description);
// }
for(i=0; i<scope.survey_questions.length; i++){ for(i=0; i<scope.survey_questions.length; i++){
buildHtml(scope.survey_questions[i], i); buildHtml(scope.survey_questions[i], i);
} }
// scope.addQuestion();
// Wait('stop');
} else {
// AddSurvey({
// scope: scope
// });
} }
}) })
.error(function (data, status) { .error(function (data, status) {
ProcessErrors(scope, data, status, { hdr: 'Error!', ProcessErrors(scope, data, status, { hdr: 'Error!',
@@ -811,11 +684,8 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi
job_template, job_template,
extra_vars, extra_vars,
new_job_id, new_job_id,
new_job,
launch_url, launch_url,
prompt_for_vars = false, html;
html,
passwords;
scope.job_template_id = id; scope.job_template_id = id;
if (base === 'job_templates' || base === 'portal') { if (base === 'job_templates' || base === 'portal') {
url = GetBasePath('job_templates') + id + '/launch/'; url = GetBasePath('job_templates') + id + '/launch/';
@@ -825,47 +695,47 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi
} }
if (scope.removePostTheJob) { // if (scope.removePostTheJob) {
scope.removePostTheJob(); // scope.removePostTheJob();
} // }
scope.removePostTheJob = scope.$on('PostTheJob', function() { // scope.removePostTheJob = scope.$on('PostTheJob', function() {
var url = (job_template.related.jobs) ? job_template.related.jobs : job_template.related.job_template + 'jobs/'; // var url = (job_template.related.jobs) ? job_template.related.jobs : job_template.related.job_template + 'jobs/';
Wait('start'); // Wait('start');
Rest.setUrl(url); // Rest.setUrl(url);
Rest.post(job_template) // Rest.post(job_template)
.success(function (data) { // .success(function (data) {
new_job_id = data.id; // new_job_id = data.id;
launch_url = data.related.start; // launch_url = data.related.start;
prompt_for_vars = data.ask_variables_on_launch; // prompt_for_vars = data.ask_variables_on_launch;
new_job = data; // new_job = data;
if (data.passwords_needed_to_start.length > 0) { // if (data.passwords_needed_to_start.length > 0) {
scope.$emit('PromptForPasswords', data.passwords_needed_to_start); // scope.$emit('PromptForPasswords', data.passwords_needed_to_start);
} // }
else if (data.ask_variables_on_launch) { // else if (data.ask_variables_on_launch) {
scope.$emit('PromptForVars'); // scope.$emit('PromptForVars');
} // }
else { // else {
scope.$emit('StartPlaybookRun'); // scope.$emit('StartPlaybookRun');
} // }
}) // })
.error(function (data, status) { // .error(function (data, status) {
var key, html; // var key, html;
if (status === 400) { // if (status === 400) {
// there's a data problem with the job template // // there's a data problem with the job template
html = "<ul style=\"list-style-type: none; margin: 15px 0;\">\n"; // html = "<ul style=\"list-style-type: none; margin: 15px 0;\">\n";
for (key in data) { // for (key in data) {
html += "<li><strong>" + key + "</strong>: " + data[key][0] + "</li>\n"; // html += "<li><strong>" + key + "</strong>: " + data[key][0] + "</li>\n";
} // }
html += "</ul>\n"; // html += "</ul>\n";
Wait('stop'); // Wait('stop');
Alert('Job Template Error', "<p>Fix the following issues before using the template:</p>" + html, 'alert-danger'); // Alert('Job Template Error', "<p>Fix the following issues before using the template:</p>" + html, 'alert-danger');
} // }
else { // else {
ProcessErrors(scope, data, status, null, { hdr: 'Error!', // ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'Failed to create job. POST returned status: ' + status }); // msg: 'Failed to create job. POST returned status: ' + status });
} // }
}); // });
}); // });
if (scope.removeCancelJob) { if (scope.removeCancelJob) {
scope.removeCancelJob(); scope.removeCancelJob();
@@ -902,9 +772,9 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi
LaunchJob({ LaunchJob({
scope: scope, scope: scope,
url: url, url: url,
callback: 'PlaybookLaunchFinished', callback: 'PlaybookLaunchFinished'
passwords: passwords
}); });
}); });
if (scope.removePromptForPasswords) { if (scope.removePromptForPasswords) {
@@ -960,18 +830,29 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi
scope: scope, scope: scope,
id: scope.job_template_id, id: scope.job_template_id,
variables: extra_vars, variables: extra_vars,
callback: 'StartPlaybookRun', callback: 'CreateModal',
url: url, url: url,
html: html html: html
}); });
} }
else { else {
// scope.$emit('StartPlaybookRun'); scope.$emit('CreateModal', html, url);
CreateLaunchDialog({scope: scope, html: html, url: url}); // CreateLaunchDialog({scope: scope, html: html, url: url});
} }
}); });
if (scope.removeCreateModal) {
scope.removeCreateModal();
}
scope.removeCreateModal = scope.$on('CreateModal', function(e, html, url) {
CreateLaunchDialog({
scope: scope,
html: html,
url: url,
callback: 'StartPlaybookRun'
});
});
if (scope.removeCredentialReady) { if (scope.removeCredentialReady) {

View File

@@ -64,23 +64,17 @@
margin-bottom: 15px; margin-bottom: 15px;
} }
.survey_taker_question{
margin-bottom: 25px;
}
.survey_taker_input{ .survey_taker_input{
margin-top: 5px;
margin-left: 15px;
.mc{ .mc{
margin-left: 18px; margin-left: 18px;
margin-right: 7px; margin-right: 7px;
} }
} }
.survey_taker_description{ .survey_taker_description{
padding-left: 30px; margin-bottom:10px
} }
.survey_error{ .survey_error{