diff --git a/awx/ui/static/js/forms/SurveyQuestion.js b/awx/ui/static/js/forms/SurveyQuestion.js
index d4409959aa..ff78ca4ca5 100644
--- a/awx/ui/static/js/forms/SurveyQuestion.js
+++ b/awx/ui/static/js/forms/SurveyQuestion.js
@@ -25,7 +25,7 @@ angular.module('SurveyQuestionFormDefinition', [])
fields: {
question_name: {
realName: 'question_text',
- label: 'Text',
+ label: 'Name',
type: 'text',
addRequired: true,
editRequired: true,
@@ -55,8 +55,8 @@ angular.module('SurveyQuestionFormDefinition', [])
ngOptions: 'answer_types.name for answer_types in answer_types track by answer_types.type',
addRequired: true,
editRequired: true,
- column: 2
-
+ column: 2,
+ ngChange: 'typeChange()'
},
choices: {
realName: 'answer_options',
@@ -80,12 +80,14 @@ angular.module('SurveyQuestionFormDefinition', [])
type: 'custom',
control:'
'+
'
'+
- '
'+
- '
This is not valid integer!
'+
+ '
'+
+ '
This is not valid integer!
'+
+ '
Too high!
'+
'
'+
'
'+
- '
'+
- '
This is not valid integer!
'+
+ '
'+
+ '
This is not valid integer!
'+
+ '
Too low!
'+
'
'+
'
',
ngShow: 'type.type==="integer" ',
@@ -174,11 +176,16 @@ angular.module('SurveyQuestionFormDefinition', [])
}
},
buttons: {
+ question_cancel : {
+ label: 'Cancel',
+ 'class' : 'btn btn-default',
+ ngClick: 'cancelQuestion()'
+ },
submit_question: {
ngClick: 'submitQuestion()',
ngDisabled: true, //'survey_question.$valid', //"!question_name || !variable || !type || ((type.type==='multiplechoice' || type.type === 'multiselect' ) && !choices)", //|| type.type===multiselect ',//'!question_name || !variable || !type' ,
'class': 'btn btn-sm btn-primary',
- label: 'Submit Question'
+ label: 'Add Question'
}
}
diff --git a/awx/ui/static/js/helpers/JobSubmission.js b/awx/ui/static/js/helpers/JobSubmission.js
index 82996769a2..c5d00e2052 100644
--- a/awx/ui/static/js/helpers/JobSubmission.js
+++ b/awx/ui/static/js/helpers/JobSubmission.js
@@ -450,87 +450,79 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi
function($compile, Wait, Alert, CredentialForm, CreateLaunchDialog, SurveyControllerInit, GetBasePath, Rest, Empty,
SurveyTakerForm, GenerateForm, ShowSurveyModal, ProcessErrors, $routeParams) {
return function(params) {
- var
- // parent_scope = params.scope,
- // passwords = params.passwords,
- // callback = params.callback || 'PasswordsAccepted',
- html = params.html || "",
+ var html = params.html || "",
form = SurveyTakerForm,
id= params.id,
- // acceptedPasswords = {},
scope = params.scope,
- // e, buttons,
- i,
- // survey_vars={}, qst,
- // url = params.url,
+ i, j,
requiredAsterisk,
requiredClasses,
defaultValue,
choices,
element,
checked, min, max,
- // generator = GenerateForm,
+
survey_url = GetBasePath('job_templates') + id + '/survey_spec/' ;
- // // Get the existing record
- // SurveyControllerInit({
- // scope: scope,
- // parent_scope: scope,
- // id: id
- // });
+
function buildHtml(question, index){
-
question.index = index;
- question[question.variable] = question.default;
- scope[question.variable] = question.default;
-
if(!$('#question_'+question.index+':eq(0)').is('div')){
- html+='';
- $('#survey_taker_finalized_questions').append(html);
+ html+='';
+ $('#finalized_questions').append(html);
}
requiredAsterisk = (question.required===true) ? "prepend-asterisk" : "";
requiredClasses = (question.required===true) ? "ng-pristine ng-invalid-required ng-invalid" : "";
-
html += ''+question.question_name+'
\n';
if(!Empty(question.question_description)){
html += ''+question.question_description+'
\n';
}
- defaultValue = (question.default) ? question.default : "";
if(question.type === 'text' ){
+ defaultValue = (question.default) ? question.default : "";
html+='';
}
if(question.type === "textarea"){
+ defaultValue = (question.default) ? question.default : (question.default_textarea) ? question.default_textarea: "" ;
html+='';
}
if(question.type === 'multiplechoice' || question.type === "multiselect"){
choices = question.choices.split(/\n/);
element = (question.type==="multiselect") ? "checkbox" : 'radio';
-
- for( i = 0; i'+
- '' +choices[i]+
+ question.default = (question.default) ? question.default : (question.default_multiselect) ? question.default_multiselect : "" ;
+ for( j = 0; j'+
+ '' +choices[i]+
'';
}
}
- if(question.type === 'integer' || question.type === "float"){
- min = (question.min) ? question.min : "";
- max = (question.max) ? question.max : "" ;
+ if(question.type === 'integer'){
+ min = (!Empty(question.min)) ? question.min : "";
+ max = (!Empty(question.max)) ? question.max : "" ;
+ defaultValue = (!Empty(question.default)) ? question.default : (!Empty(question.default_int)) ? question.default_int : "" ;
html+='';
+
+ }
+ if(question.type === "float"){
+ min = (!Empty(question.min)) ? question.min : "";
+ max = (!Empty(question.max)) ? question.max : "" ;
+ defaultValue = (!Empty(question.default)) ? question.default : (!Empty(question.default_float)) ? question.default_float : "" ;
+ html+='';
}
@@ -539,6 +531,61 @@ 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+='';
+ // $('#survey_taker_finalized_questions').append(html);
+ // }
+
+ // requiredAsterisk = (question.required===true) ? "prepend-asterisk" : "";
+ // requiredClasses = (question.required===true) ? "ng-pristine ng-invalid-required ng-invalid" : "";
+
+ // html += ''+question.question_name+'
\n';
+ // if(!Empty(question.question_description)){
+ // html += ''+question.question_description+'
\n';
+ // }
+ // defaultValue = (question.default) ? question.default : "";
+
+ // if(question.type === 'text' ){
+ // html+='';
+ // }
+ // if(question.type === "textarea"){
+ // html+=''+
+ // '
'+
+ // ''+
+ // '
';
+ // }
+ // if(question.type === 'multiplechoice' || question.type === "multiselect"){
+ // choices = question.choices.split(/\n/);
+ // element = (question.type==="multiselect") ? "checkbox" : 'radio';
+
+ // for( i = 0; i'+
+ // '' +choices[i]+
+ // '';
+ // }
+
+ // }
+ // if(question.type === 'integer' || question.type === "float"){
+ // min = (question.min) ? question.min : "";
+ // max = (question.max) ? question.max : "" ;
+ // html+='';
+
+ // }
+
// if (scope.removeDialogReady) {
// scope.removeDialogReady();
diff --git a/awx/ui/static/js/helpers/Survey.js b/awx/ui/static/js/helpers/Survey.js
index f4d98ed813..722fb18124 100644
--- a/awx/ui/static/js/helpers/Survey.js
+++ b/awx/ui/static/js/helpers/Survey.js
@@ -250,7 +250,7 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
url = GetBasePath('job_templates')+ id + '/survey_spec/';
Rest.setUrl(url);
- Rest.post({})
+ Rest.destroy()
.success(function () {
scope.$emit("SurveyDeleted");
@@ -387,86 +387,6 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
};
}])
- .factory('SurveyTakerQuestion', ['GetBasePath','Rest', 'Wait', 'ProcessErrors', '$compile', 'Empty',
- function(GetBasePath, Rest, Wait, ProcessErrors, $compile, Empty) {
- return function(params) {
-
- var scope = params.scope,
- // id = params.id,
- question = params.question,
- index = params.index,
- requiredAsterisk,
- requiredClasses,
- element, choices, i, checked,
- max, min, defaultValue, numberValidation,
- html = "";
-
- // if(scope.survey_questions.length>0){
- // $('#survey-save-button').removeAttr('disabled')
- // }
-
- question.index = index;
- question[question.variable] = question.default;
- scope[question.variable] = question.default;
-
-
- if(!$('#question_'+question.index+':eq(0)').is('div')){
- html+='';
- $('#survey_taker_finalized_questions').append(html);
- }
-
- requiredAsterisk = (question.required===true) ? "prepend-asterisk" : "";
- requiredClasses = (question.required===true) ? "ng-pristine ng-invalid-required ng-invalid" : "";
-
- html = ''+question.question_name+'
\n';
- if(!Empty(question.question_description)){
- html += ''+question.question_description+'
\n';
- }
- defaultValue = (question.default) ? question.default : "";
-
- if(question.type === 'text' ){
- html+='';
- }
- if(question.type === "textarea"){
- html+='';
- }
- if(question.type === 'multiplechoice' || question.type === "multiselect"){
- choices = question.choices.split(/\n/);
- element = (question.type==="multiselect") ? "checkbox" : 'radio';
-
- for( i = 0; i'+
- '' +choices[i]+
- '';
- }
-
- }
- if(question.type === 'integer' || question.type === "float"){
- min = (question.min) ? question.min : "";
- max = (question.max) ? question.max : "" ;
- numberValidation = (question.type==="integer") ? "integer" : 'float';
- html+='';
-
- }
- $('#question_'+question.index).append(html);
-
- element = angular.element(document.getElementById('question_'+question.index));
- $compile(element)(scope);
-
- };
- }])
.factory('EditQuestion', ['GetBasePath','Rest', 'Wait', 'ProcessErrors', '$compile', 'GenerateForm', 'SurveyQuestionForm',
function(GetBasePath, Rest, Wait, ProcessErrors, $compile, GenerateForm, SurveyQuestionForm) {
@@ -474,23 +394,32 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
var scope = params.scope,
index = params.index,
- element, fld, i, pre,
+ element, fld, i,
form = SurveyQuestionForm;
+ $('#survey-save-button').attr('disabled', 'disabled');
$('#add_question_btn').hide();
$('#new_question .aw-form-well').remove();
element = $('.question_final:eq('+index+')');
element.css('opacity', 1.0);
element.empty();
- // $('#new_question .aw-form-well').remove();
+ scope.int_min = null;
+ scope.int_max = null;
+ scope.float_min = null;
+ scope.float_max = null;
GenerateForm.inject(form, { id: 'question_'+index, mode: 'edit' , related: false, scope:scope, breadCrumbs: false});
for(fld in form.fields){
- if( fld === 'float_options' || fld === 'int_options'){
- pre = fld.substr(0, fld.indexOf('_'));
- scope[pre+'_min'] = scope.survey_questions[index].min;
- scope[pre+'_max'] = scope.survey_questions[index].max;
- // $('#'+pre+'_min').val(scope.survey_questions[index].min);
- // $('#'+pre+'_max').val(scope.survey_questions[index].max);
+ if( scope.survey_questions[index].type==='integer' && fld === 'int_options'){
+ scope.int_min = scope.survey_questions[index].min;
+ scope.int_max = scope.survey_questions[index].max;
+ // $("#int_min").val(scope.survey_questions[index].min);
+ // $("#int_max").val(scope.survey_questions[index].max);
+ }
+ if( scope.survey_questions[index].type==='float' && fld === 'float_options' ) {
+ scope.float_min = scope.survey_questions[index].min;
+ scope.float_max = scope.survey_questions[index].max;
+ // $("#float_min").val(scope.survey_questions[index].min);
+ // $("#float_max").val(scope.survey_questions[index].max);
}
if( fld === 'default_int' || fld === 'default_float'){
$("#"+fld ).val(scope.survey_questions[index].default);
@@ -527,9 +456,9 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
})
.factory('SurveyControllerInit', ['$location', 'DeleteSurvey', 'EditSurvey', 'AddSurvey', 'GenerateForm', 'SurveyQuestionForm', 'Wait', 'Alert',
- 'GetBasePath', 'Rest', 'ProcessErrors' , '$compile', 'FinalizeQuestion', 'EditQuestion', 'DeleteQuestion', 'SurveyTakerQuestion',
+ 'GetBasePath', 'Rest', 'ProcessErrors' , '$compile', 'FinalizeQuestion', 'EditQuestion', 'DeleteQuestion',
function($location, DeleteSurvey, EditSurvey, AddSurvey, GenerateForm, SurveyQuestionForm, Wait, Alert,
- GetBasePath, Rest, ProcessErrors, $compile, FinalizeQuestion, EditQuestion, DeleteQuestion, SurveyTakerQuestion) {
+ GetBasePath, Rest, ProcessErrors, $compile, FinalizeQuestion, EditQuestion, DeleteQuestion) {
return function(params) {
var scope = params.scope,
id = params.id,
@@ -584,6 +513,7 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
$('#survey_question_question_name').focus();
$('#add_question_btn').attr('disabled', 'disabled');
$('#add_question_btn').hide();
+ $('#survey-save-button').attr('disabled' , 'disabled');
// });
};
scope.editQuestion = function(index){
@@ -599,6 +529,9 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
scope: scope
});
};
+ scope.cancelQuestion = function(){
+ alert('success');
+ };
scope.questionUp = function(index){
var animating = false,
@@ -668,16 +601,6 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
}
};
- scope.surveyTakerQuestion= function(data, index){
- SurveyTakerQuestion({
- scope: scope,
- question: data,
- id: id,
- index: index
- //callback?
- });
- };
-
scope.finalizeQuestion= function(data, index){
FinalizeQuestion({
scope: scope,
@@ -688,6 +611,18 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
});
};
+ scope.typeChange = function() {
+ // alert('typechange');
+ scope.default = null;
+ scope.default_multiselect = null;
+ scope.default_float = null;
+ scope.default_int = null;
+ scope.default_textarea = null;
+ scope.int_min = null;
+ scope.int_max = null;
+ scope.float_min = null;
+ scope.float_max = null;
+ };
scope.submitQuestion = function(){
var form = SurveyQuestionForm,
@@ -712,13 +647,11 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
data.min = scope.float_min;
data.max = scope.float_max;
data.default = scope.default_float;
-
}
if(scope[fld].type==="integer" ){
data.min = scope.int_min;
data.max = scope.int_max;
data.default = scope.default_int;
-
}
}
else{
@@ -729,7 +662,7 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
}
}
Wait('stop');
-
+ $('#survey-save-button').removeAttr('disabled');
if(GenerateForm.mode === 'add'){
scope.survey_questions.push(data);
$('#new_question .aw-form-well').remove();
@@ -758,7 +691,7 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
''+
''+
''+
- ''+
+ ''+
''+
''+
'';