mirror of
https://github.com/ansible/awx.git
synced 2026-05-24 00:57:48 -02:30
more validation on survey question
survey question needed to have validation that didn't allow the min/max values to overlap incorrectly and for the survey save button to be disabled if hte user is in the process of adding another question
This commit is contained in:
@@ -25,7 +25,7 @@ angular.module('SurveyQuestionFormDefinition', [])
|
|||||||
fields: {
|
fields: {
|
||||||
question_name: {
|
question_name: {
|
||||||
realName: 'question_text',
|
realName: 'question_text',
|
||||||
label: 'Text',
|
label: 'Name',
|
||||||
type: 'text',
|
type: 'text',
|
||||||
addRequired: true,
|
addRequired: true,
|
||||||
editRequired: 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',
|
ngOptions: 'answer_types.name for answer_types in answer_types track by answer_types.type',
|
||||||
addRequired: true,
|
addRequired: true,
|
||||||
editRequired: true,
|
editRequired: true,
|
||||||
column: 2
|
column: 2,
|
||||||
|
ngChange: 'typeChange()'
|
||||||
},
|
},
|
||||||
choices: {
|
choices: {
|
||||||
realName: 'answer_options',
|
realName: 'answer_options',
|
||||||
@@ -80,12 +80,14 @@ angular.module('SurveyQuestionFormDefinition', [])
|
|||||||
type: 'custom',
|
type: 'custom',
|
||||||
control:'<div class="row">'+
|
control:'<div class="row">'+
|
||||||
'<div class="col-xs-6">'+
|
'<div class="col-xs-6">'+
|
||||||
'<label for="minimum"><span class="label-text">Minimum</span></label><input id="int_min" type="number" name="int_min" ng-model="int_min" class="form-control" integer >'+
|
'<label for="minimum"><span class="label-text">Minimum</span></label><input id="int_min" type="number" name="int_min" ng-model="int_min" ng-max="int_max" class="form-control" integer >'+
|
||||||
'<div class="error" ng-show="survey_question_form.int_min.$invalid">This is not valid integer!</div>'+
|
'<div class="error" ng-show="survey_question_form.int_min.$error.number || survey_question_form.int_min.$error.integer">This is not valid integer!</div>'+
|
||||||
|
'<div class="error" ng-show="survey_question_form.int_min.$error.ngMax">Too high!</div>'+
|
||||||
'</div>'+
|
'</div>'+
|
||||||
'<div class="col-xs-6">'+
|
'<div class="col-xs-6">'+
|
||||||
'<label for="minimum"><span class="label-text">Maximum</span></label><input id="int_max" type="number" name="int_max" ng-model="int_max" class="form-control" integer >'+
|
'<label for="minimum"><span class="label-text">Maximum</span></label><input id="int_max" type="number" name="int_max" ng-model="int_max" ng-min="int_min" class="form-control" integer >'+
|
||||||
'<div class="error" ng-show="survey_question_form.int_max.$invalid">This is not valid integer!</div>'+
|
'<div class="error" ng-show="survey_question_form.int_max.$error.number || survey_question_form.int_max.$error.integer">This is not valid integer!</div>'+
|
||||||
|
'<div class="error" ng-show="survey_question_form.int_max.$error.ngMin">Too low!</div>'+
|
||||||
'</div>'+
|
'</div>'+
|
||||||
'</div>',
|
'</div>',
|
||||||
ngShow: 'type.type==="integer" ',
|
ngShow: 'type.type==="integer" ',
|
||||||
@@ -174,11 +176,16 @@ angular.module('SurveyQuestionFormDefinition', [])
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
buttons: {
|
buttons: {
|
||||||
|
question_cancel : {
|
||||||
|
label: 'Cancel',
|
||||||
|
'class' : 'btn btn-default',
|
||||||
|
ngClick: 'cancelQuestion()'
|
||||||
|
},
|
||||||
submit_question: {
|
submit_question: {
|
||||||
ngClick: 'submitQuestion()',
|
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' ,
|
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',
|
'class': 'btn btn-sm btn-primary',
|
||||||
label: 'Submit Question'
|
label: 'Add Question'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -450,87 +450,79 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi
|
|||||||
function($compile, Wait, Alert, CredentialForm, CreateLaunchDialog, SurveyControllerInit, GetBasePath, Rest, Empty,
|
function($compile, Wait, Alert, CredentialForm, CreateLaunchDialog, SurveyControllerInit, GetBasePath, Rest, Empty,
|
||||||
SurveyTakerForm, GenerateForm, ShowSurveyModal, ProcessErrors, $routeParams) {
|
SurveyTakerForm, GenerateForm, ShowSurveyModal, ProcessErrors, $routeParams) {
|
||||||
return function(params) {
|
return function(params) {
|
||||||
var
|
var html = params.html || "",
|
||||||
// parent_scope = params.scope,
|
|
||||||
// passwords = params.passwords,
|
|
||||||
// callback = params.callback || 'PasswordsAccepted',
|
|
||||||
html = params.html || "",
|
|
||||||
form = SurveyTakerForm,
|
form = SurveyTakerForm,
|
||||||
id= params.id,
|
id= params.id,
|
||||||
// acceptedPasswords = {},
|
|
||||||
scope = params.scope,
|
scope = params.scope,
|
||||||
// e, buttons,
|
i, j,
|
||||||
i,
|
|
||||||
// survey_vars={}, qst,
|
|
||||||
// url = params.url,
|
|
||||||
requiredAsterisk,
|
requiredAsterisk,
|
||||||
requiredClasses,
|
requiredClasses,
|
||||||
defaultValue,
|
defaultValue,
|
||||||
choices,
|
choices,
|
||||||
element,
|
element,
|
||||||
checked, min, max,
|
checked, min, max,
|
||||||
// generator = GenerateForm,
|
|
||||||
survey_url = GetBasePath('job_templates') + id + '/survey_spec/' ;
|
survey_url = GetBasePath('job_templates') + id + '/survey_spec/' ;
|
||||||
|
|
||||||
// // Get the existing record
|
|
||||||
// SurveyControllerInit({
|
|
||||||
// scope: scope,
|
|
||||||
// parent_scope: scope,
|
|
||||||
// id: id
|
|
||||||
// });
|
|
||||||
function buildHtml(question, index){
|
function buildHtml(question, index){
|
||||||
|
|
||||||
question.index = index;
|
question.index = index;
|
||||||
question[question.variable] = question.default;
|
|
||||||
scope[question.variable] = question.default;
|
|
||||||
|
|
||||||
|
|
||||||
if(!$('#question_'+question.index+':eq(0)').is('div')){
|
if(!$('#question_'+question.index+':eq(0)').is('div')){
|
||||||
html+='<div id="question_'+question.index+'" class="survey_taker_question_final row"></div>';
|
html+='<div id="question_'+question.index+'" class="question_final row"></div>';
|
||||||
$('#survey_taker_finalized_questions').append(html);
|
$('#finalized_questions').append(html);
|
||||||
}
|
}
|
||||||
|
|
||||||
requiredAsterisk = (question.required===true) ? "prepend-asterisk" : "";
|
requiredAsterisk = (question.required===true) ? "prepend-asterisk" : "";
|
||||||
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 += '<div class="col-xs-12 '+requiredAsterisk+'"><b>'+question.question_name+'</b></div>\n';
|
||||||
if(!Empty(question.question_description)){
|
if(!Empty(question.question_description)){
|
||||||
html += '<div class="col-xs-12 description"><i>'+question.question_description+'</i></div>\n';
|
html += '<div class="col-xs-12 description"><i>'+question.question_description+'</i></div>\n';
|
||||||
}
|
}
|
||||||
defaultValue = (question.default) ? question.default : "";
|
|
||||||
|
|
||||||
if(question.type === 'text' ){
|
if(question.type === 'text' ){
|
||||||
|
defaultValue = (question.default) ? question.default : "";
|
||||||
html+='<div class="row">'+
|
html+='<div class="row">'+
|
||||||
'<div class="col-xs-8">'+
|
'<div class="col-xs-8">'+
|
||||||
'<input type="text" ng-model="'+question.variable+'" '+ //placeholder="'+defaultValue+'"
|
'<input type="text" placeholder="'+defaultValue+'" class="form-control ng-pristine ng-invalid-required ng-invalid final" required="" readonly>'+
|
||||||
'class="form-control '+requiredClasses+' final" required="" >'+
|
|
||||||
'</div></div>';
|
'</div></div>';
|
||||||
}
|
}
|
||||||
if(question.type === "textarea"){
|
if(question.type === "textarea"){
|
||||||
|
defaultValue = (question.default) ? question.default : (question.default_textarea) ? question.default_textarea: "" ;
|
||||||
html+='<div class="row">'+
|
html+='<div class="row">'+
|
||||||
'<div class="col-xs-8">'+
|
'<div class="col-xs-8">'+
|
||||||
'<textarea ng-model="'+question.variable+'" class="form-control '+requiredClasses+' final" required="" rows="3" >'+//defaultValue+
|
'<textarea class="form-control ng-pristine ng-invalid-required ng-invalid final" required="" rows="3" readonly>'+defaultValue+'</textarea>'+
|
||||||
'</textarea>'+
|
|
||||||
'</div></div>';
|
'</div></div>';
|
||||||
}
|
}
|
||||||
if(question.type === 'multiplechoice' || question.type === "multiselect"){
|
if(question.type === 'multiplechoice' || 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 : "" ;
|
||||||
for( i = 0; i<choices.length; i++){
|
for( j = 0; j<choices.length; j++){
|
||||||
checked = (!Empty(question.default) && question.default.indexOf(choices[i].trim())!==-1) ? "checked" : "";
|
checked = (!Empty(question.default) && question.default.indexOf(choices[j])!==-1) ? "checked" : "";
|
||||||
html+='<label class="'+element+'-inline final">'+
|
html+='<label class="'+element+'-inline final">'+
|
||||||
'<input type="'+element+'" name="'+question.variable+ ' " id="" value=" '+choices[i]+' " '+checked+' >' +choices[i]+
|
'<input type="'+element+'" name="'+question.variable+ ' " id="" value=" '+choices[i]+' " '+checked+' disabled>' +choices[i]+
|
||||||
'</label>';
|
'</label>';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if(question.type === 'integer' || question.type === "float"){
|
if(question.type === 'integer'){
|
||||||
min = (question.min) ? question.min : "";
|
min = (!Empty(question.min)) ? question.min : "";
|
||||||
max = (question.max) ? question.max : "" ;
|
max = (!Empty(question.max)) ? question.max : "" ;
|
||||||
|
defaultValue = (!Empty(question.default)) ? question.default : (!Empty(question.default_int)) ? question.default_int : "" ;
|
||||||
html+='<div class="row">'+
|
html+='<div class="row">'+
|
||||||
'<div class="col-xs-8">'+
|
'<div class="col-xs-8">'+
|
||||||
'<input type="number" class="final" name="'+question.variable+'" min="'+min+'" max="'+max+'" value="'+defaultValue+'">'+
|
'<input type="number" class="final" name="'+question.variable+'" min="'+min+'" max="'+max+'" value="'+defaultValue+'" readonly>'+
|
||||||
|
'</div></div>';
|
||||||
|
|
||||||
|
}
|
||||||
|
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+='<div class="row">'+
|
||||||
|
'<div class="col-xs-8">'+
|
||||||
|
'<input type="number" class="final" name="'+question.variable+'" min="'+min+'" max="'+max+'" value="'+defaultValue+'" readonly>'+
|
||||||
'</div></div>';
|
'</div></div>';
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -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+='<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) {
|
// if (scope.removeDialogReady) {
|
||||||
// scope.removeDialogReady();
|
// scope.removeDialogReady();
|
||||||
|
|||||||
@@ -250,7 +250,7 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
|
|||||||
url = GetBasePath('job_templates')+ id + '/survey_spec/';
|
url = GetBasePath('job_templates')+ id + '/survey_spec/';
|
||||||
|
|
||||||
Rest.setUrl(url);
|
Rest.setUrl(url);
|
||||||
Rest.post({})
|
Rest.destroy()
|
||||||
.success(function () {
|
.success(function () {
|
||||||
scope.$emit("SurveyDeleted");
|
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+='<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 : "" ;
|
|
||||||
numberValidation = (question.type==="integer") ? "integer" : 'float';
|
|
||||||
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>';
|
|
||||||
|
|
||||||
}
|
|
||||||
$('#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',
|
.factory('EditQuestion', ['GetBasePath','Rest', 'Wait', 'ProcessErrors', '$compile', 'GenerateForm', 'SurveyQuestionForm',
|
||||||
function(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,
|
var scope = params.scope,
|
||||||
index = params.index,
|
index = params.index,
|
||||||
element, fld, i, pre,
|
element, fld, i,
|
||||||
form = SurveyQuestionForm;
|
form = SurveyQuestionForm;
|
||||||
|
|
||||||
|
$('#survey-save-button').attr('disabled', 'disabled');
|
||||||
$('#add_question_btn').hide();
|
$('#add_question_btn').hide();
|
||||||
$('#new_question .aw-form-well').remove();
|
$('#new_question .aw-form-well').remove();
|
||||||
element = $('.question_final:eq('+index+')');
|
element = $('.question_final:eq('+index+')');
|
||||||
element.css('opacity', 1.0);
|
element.css('opacity', 1.0);
|
||||||
element.empty();
|
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});
|
GenerateForm.inject(form, { id: 'question_'+index, mode: 'edit' , related: false, scope:scope, breadCrumbs: false});
|
||||||
for(fld in form.fields){
|
for(fld in form.fields){
|
||||||
if( fld === 'float_options' || fld === 'int_options'){
|
if( scope.survey_questions[index].type==='integer' && fld === 'int_options'){
|
||||||
pre = fld.substr(0, fld.indexOf('_'));
|
scope.int_min = scope.survey_questions[index].min;
|
||||||
scope[pre+'_min'] = scope.survey_questions[index].min;
|
scope.int_max = scope.survey_questions[index].max;
|
||||||
scope[pre+'_max'] = scope.survey_questions[index].max;
|
// $("#int_min").val(scope.survey_questions[index].min);
|
||||||
// $('#'+pre+'_min').val(scope.survey_questions[index].min);
|
// $("#int_max").val(scope.survey_questions[index].max);
|
||||||
// $('#'+pre+'_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'){
|
if( fld === 'default_int' || fld === 'default_float'){
|
||||||
$("#"+fld ).val(scope.survey_questions[index].default);
|
$("#"+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',
|
.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,
|
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) {
|
return function(params) {
|
||||||
var scope = params.scope,
|
var scope = params.scope,
|
||||||
id = params.id,
|
id = params.id,
|
||||||
@@ -584,6 +513,7 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
|
|||||||
$('#survey_question_question_name').focus();
|
$('#survey_question_question_name').focus();
|
||||||
$('#add_question_btn').attr('disabled', 'disabled');
|
$('#add_question_btn').attr('disabled', 'disabled');
|
||||||
$('#add_question_btn').hide();
|
$('#add_question_btn').hide();
|
||||||
|
$('#survey-save-button').attr('disabled' , 'disabled');
|
||||||
// });
|
// });
|
||||||
};
|
};
|
||||||
scope.editQuestion = function(index){
|
scope.editQuestion = function(index){
|
||||||
@@ -599,6 +529,9 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
|
|||||||
scope: scope
|
scope: scope
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
scope.cancelQuestion = function(){
|
||||||
|
alert('success');
|
||||||
|
};
|
||||||
|
|
||||||
scope.questionUp = function(index){
|
scope.questionUp = function(index){
|
||||||
var animating = false,
|
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){
|
scope.finalizeQuestion= function(data, index){
|
||||||
FinalizeQuestion({
|
FinalizeQuestion({
|
||||||
scope: scope,
|
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(){
|
scope.submitQuestion = function(){
|
||||||
var form = SurveyQuestionForm,
|
var form = SurveyQuestionForm,
|
||||||
@@ -712,13 +647,11 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
|
|||||||
data.min = scope.float_min;
|
data.min = scope.float_min;
|
||||||
data.max = scope.float_max;
|
data.max = scope.float_max;
|
||||||
data.default = scope.default_float;
|
data.default = scope.default_float;
|
||||||
|
|
||||||
}
|
}
|
||||||
if(scope[fld].type==="integer" ){
|
if(scope[fld].type==="integer" ){
|
||||||
data.min = scope.int_min;
|
data.min = scope.int_min;
|
||||||
data.max = scope.int_max;
|
data.max = scope.int_max;
|
||||||
data.default = scope.default_int;
|
data.default = scope.default_int;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
@@ -729,7 +662,7 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Wait('stop');
|
Wait('stop');
|
||||||
|
$('#survey-save-button').removeAttr('disabled');
|
||||||
if(GenerateForm.mode === 'add'){
|
if(GenerateForm.mode === 'add'){
|
||||||
scope.survey_questions.push(data);
|
scope.survey_questions.push(data);
|
||||||
$('#new_question .aw-form-well').remove();
|
$('#new_question .aw-form-well').remove();
|
||||||
@@ -758,7 +691,7 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
|
|||||||
'<label for="survey"><span class="label-text prepend-asterisk">Questions</span></label>'+
|
'<label for="survey"><span class="label-text prepend-asterisk">Questions</span></label>'+
|
||||||
'<div id="survey_maker_question_area"></div>'+
|
'<div id="survey_maker_question_area"></div>'+
|
||||||
'<div id="finalized_questions"></div>'+
|
'<div id="finalized_questions"></div>'+
|
||||||
'<button style="display:none" type="button" class="btn btn-sm btn-primary" id="add_question_btn" ng-click="addNewQuestion()" aw-tool-tip="Create a new question" data-placement="top" data-original-title="" title="" disabled><i class="fa fa-plus fa-lg"></i> Add Question</button>'+
|
'<button style="display:none" type="button" class="btn btn-sm btn-primary" id="add_question_btn" ng-click="addNewQuestion()" aw-tool-tip="Create a new question" data-placement="top" data-original-title="" title="" disabled><i class="fa fa-plus fa-lg"></i> New Question</button>'+
|
||||||
'<div id="new_question"></div>'+
|
'<div id="new_question"></div>'+
|
||||||
'</div>'+
|
'</div>'+
|
||||||
'</div>';
|
'</div>';
|
||||||
|
|||||||
Reference in New Issue
Block a user