1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 23:51:09 +03:00

fixed default answer field in question maker. also added validation for choices if multichoice or multiselect is chosen

This commit is contained in:
Jared Tabor 2014-10-06 16:15:06 -04:00
parent d6adb1d398
commit 47deaa702d
3 changed files with 56 additions and 52 deletions

View File

@ -19,23 +19,7 @@ angular.module('SurveyMakerFormDefinition', [])
name: 'survey_maker', //entity or model name in singular form
// // well: true,
breadCrumbs: false,
// twoColumns: true,
// // collapse: true,
// collapseTitle: "Properties",
// collapseMode: 'edit',
// collapseOpen: true,
// actions: {
// stream: {
// 'class': "btn-primary btn-xs activity-btn",
// ngClick: "showActivity()",
// awToolTip: "View Activity Stream",
// dataPlacement: "top",
// icon: "icon-comments-alt",
// mode: 'edit',
// iconSize: 'large'
// }
// },
fields: {
survey_name: {
@ -65,28 +49,7 @@ angular.module('SurveyMakerFormDefinition', [])
// capitalize: false,
// // column: 1
},
// survey_description: {
// type: 'custom',
// control: '<div class="col-sm-6"><div class="form-group">'+
// '<label for="survey_description"><span class="label-text">Survey Description</span></label><div>'+
// '<input type="text" ng-model="survey_description" name="survey_description" id="survey_maker_survey_description" class="form-control ng-pristine ng-valid">'+
// '<div class="error api-error ng-binding" id="survey_maker-survey_description-api-error" ng-bind="survey_description_api_error"></div>'+
// '</div></div></div></div>'
// // label: 'Survey Description',
// // type: 'text',
// // addRequired: false,
// // editRequired: false,
// // column: 2
// },
// questions: {
// type: 'custom',
// control: '<label for="survey"><span class="label-text prepend-asterisk">Questions</span></label>'+
// '<div id="survey_maker_question_area"></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>'+
// '<div id="new_question"></div>'
// }
},
buttons: { //for now always generates <button> tags

View File

@ -133,7 +133,33 @@ angular.module('SurveyQuestionFormDefinition', [])
addRequired: false,
editRequired: false,
column: 2,
ngHide: 'type.type === "textarea" '
ngHide: 'type.type === "textarea" || type.type === "multiselect" || type.type === "integer" || type.type === "float" '
},
default_multiselect: {
realName: 'default_answer',
label: 'Default Answer',
type: 'textarea',
rows: 3,
addRequired: false,
editRequired: false,
column: 2,
ngShow: 'type.type === "multiselect" '
},
default_int: {
realName: 'default_answer',
type: 'custom',
control: '<div class="row">'+
'<div class="col-xs-6"><label for="default_int"><span class="label-text">Default Answer</span></label><input id="default_int" ng-model="default_int" type="number" class="form-control"></div></div>',
column: 2,
ngShow: 'type.type === "integer" '
},
default_float: {
realName: 'default_answer',
type: 'custom',
control: '<div class="row">'+
'<div class="col-xs-6"><label for="default_float"><span class="label-text">Default Answer</span></label><input id="default_float" ng-model="default_float" type="number" class="form-control"></div></div>',
column: 2,
ngShow: 'type.type=== "float" '
},
default_textarea: {
realName: 'default_answer',
@ -186,9 +212,9 @@ angular.module('SurveyQuestionFormDefinition', [])
buttons: {
submit_question: {
ngClick: 'submitQuestion()',
ngDisabled: '!question_name || !variable || !type',
ngDisabled: "!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: 'Add Question'
label: 'Submit Question'
}
},

View File

@ -476,7 +476,9 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
$('#answer_min').val(scope.survey_questions[index].min);
$('#answer_max').val(scope.survey_questions[index].max);
}
if( fld === 'default_int' || fld === 'default_float'){
$("#"+fld ).val(scope.survey_questions[index].default);
}
if(form.fields[fld].type === 'select'){
for (i = 0; i < scope.answer_types.length; i++) {
if (scope.survey_questions[index][fld] === scope.answer_types[i].type) {
@ -514,11 +516,8 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
GetBasePath, Rest, ProcessErrors, $compile, FinalizeQuestion, EditQuestion, DeleteQuestion, SurveyTakerQuestion) {
return function(params) {
var scope = params.scope,
// parent_scope = params.parent_scope,
id = params.id,
i, url;
// iterator = (params.iterator) ? params.iterator : scope.iterator,
// base = $location.path().replace(/^\//, '').split('/')[0];
scope.survey_questions = [];
scope.answer_types=[
@ -555,11 +554,7 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
scope.addQuestion = function(){
GenerateForm.inject(SurveyQuestionForm, { id:'new_question', mode: 'add' , scope:scope, breadCrumbs: false});
scope.required = true; //set the required checkbox to true via the ngmodel attached to scope.required.
// $('#survey_question_submit_question_btn').attr('ng-disabled', "!question_name || !variable || !type && (type===multiplechoice || !choices)");
// element = angular.element(document.getElementById('survey_question_submit_question_btn'));
// // element.html(html);
// $compile(element)(scope);
};
scope.addNewQuestion = function(){
@ -691,18 +686,38 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
if(scope[fld]){
if(fld === "type"){
data[fld] = scope[fld].type;
if(scope[fld].type==="textarea"){
data["default"] = scope.default_textarea;
}
if(scope[fld].type==="integer" || scope[fld].type==="float"){
// if(scope[fld].type==="textarea"){
// data["default"] = scope.default_textarea;
// }
// if(scope[fld].type==="multiselect"){
// data["default"] = scope.default_multiselect;
// }
if(scope[fld].type === 'float'){
data[min] = $('#answer_min').val();
data[max] = $('#answer_max').val();
labels[min]= "Min";
labels[max]= "Max";
// data["default"] = $('#default_float').val(); //scope.default_float;
}
if(scope[fld].type==="integer" ){
data[min] = $('#answer_min').val();
data[max] = $('#answer_max').val();
labels[min]= "Min";
labels[max]= "Max";
// data["default"] = $('#default_int').val(); //scope.default_int;
}
}
else{
data[fld] = scope[fld];
if( fld === 'default_int' || fld === 'default_float' ){
data['default'] = $('#'+fld).val();
}
if(fld==="default_textarea" ){
data['default'] = scope.default_textarea;
}
if(fld==="default_multiselect"){
data['default'] = scope.default_multiselect;
}
}
labels[fld] = form.fields[fld].label;
}