survey maker additions for question types

This commit is contained in:
Jared Tabor
2014-09-24 17:36:20 -04:00
parent 9064bb3107
commit 40192b5172
8 changed files with 187 additions and 430 deletions

View File

@@ -117,7 +117,8 @@ angular.module('Tower', [
'SocketHelper',
'AboutAnsibleHelpModal',
'SurveyMakerFormDefinition',
'SurveyQuestionFormDefinition'
'SurveyQuestionFormDefinition',
])
.constant('AngularScheduler.partials', urlPrefix + 'lib/angular-scheduler/lib/')

View File

@@ -864,7 +864,7 @@ function JobTemplatesEdit($scope, $rootScope, $compile, $location, $log, $routeP
if(fld ==='survey_enabled'){
// $scope.$emit('EnableSurvey', fld);
$('#job_templates_survey_enabled_chbox').attr('checked', $scope[fld]);
if(Empty(data.related.survey_spec)){
if(Empty(data.summary_fields.survey)) {
$('#job_templates_delete_survey_btn').hide();
$('#job_templates_edit_survey_btn').hide();
$('#job_templates_create_survey_btn').show();
@@ -1084,7 +1084,7 @@ function JobTemplatesEdit($scope, $rootScope, $compile, $location, $log, $routeP
Rest.patch({"survey_enabled": $scope.survey_enabled})
.success(function (data) {
if(Empty(data.related.survey_spec)){
if(Empty(data.summary_fields.survey)){
$('#job_templates_delete_survey_btn').hide();
$('#job_templates_edit_survey_btn').hide();
$('#job_templates_create_survey_btn').show();
@@ -1103,67 +1103,7 @@ function JobTemplatesEdit($scope, $rootScope, $compile, $location, $log, $routeP
});
};
//navigate to the survey maker
// $scope.addSurvey = function() {
// $location.path($location.path() + '/survey/add');
// };
//navigate to the survey maker
// $scope.editSurvey = function() {
// $scope.Store("survey_for_new_job_template", false);
// $location.path($location.path() + '/survey/edit');
// };
// //delete a survey by posting a blank survey
// $scope.deleteSurvey = function() {
// // $location.path($location.path() + '/survey/add');
// Wait('start');
// var url = defaultUrl+ id + '/survey_spec/';
// Rest.setUrl(url);
// Rest.post({})
// .success(function () {
// Wait('stop');
// $('#job_templates_delete_survey_btn').hide();
// $('#job_templates_edit_survey_btn').hide();
// $('#job_templates_create_survey_btn').show();
// })
// .error(function (data, status) {
// ProcessErrors($scope, data, status, form, { hdr: 'Error!',
// msg: 'Failed to add new survey. Post returned status: ' + status });
// });
// };
// // Related set: Delete button
// $scope['delete'] = function (set, itm_id, name, title) {
// $rootScope.flashMessage = null;
// var action = function () {
// var url = defaultUrl + id + '/' + set + '/';
// Rest.setUrl(url);
// Rest.post({
// id: itm_id,
// disassociate: 1
// })
// .success(function () {
// $('#prompt-modal').modal('hide');
// $scope.search(form.related[set].iterator);
// })
// .error(function (data, status) {
// $('#prompt-modal').modal('hide');
// ProcessErrors($scope, data, status, null, { hdr: 'Error!',
// msg: 'Call to ' + url + ' failed. POST returned status: ' + status });
// });
// };
// Prompt({
// hdr: 'Delete',
// body: 'Are you sure you want to remove ' + name + ' from ' + $scope.name + ' ' + title + '?',
// action: action
// });
// };
}
JobTemplatesEdit.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'JobTemplateForm',

View File

@@ -54,7 +54,7 @@ angular.module('SurveyMakerFormDefinition', [])
'<div class="col-sm-12"><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></div></div>'
'<div id="new_question"></div></div></div></div>'
// label: 'Survey Name',
// type: 'text',
// addRequired: true,

View File

@@ -35,27 +35,28 @@ angular.module('SurveyQuestionFormDefinition', [])
fields: {
question_name: {
realName: 'question_text',
label: 'Question Text',
label: 'Text',
type: 'text',
addRequired: true,
editRequired: true,
column: 1
column: 1,
awSurveyQuestion: true
},
question_description: {
realName: 'question_description',
label: 'Question Description',
type: 'textarea',
rows: 2,
addRequired: true,
editRequired: true,
column: 2
label: 'Description',
type: 'text',
// rows: 2,
addRequired: false,
editRequired: false,
column: 1
},
variable: {
label: 'Answer Variable Name',
type: 'text',
addRequired: true,
editRequired: true,
column: 2
column: 1
// sourceModel: 'organization',
// sourceField: 'name',
// ngClick: 'lookUpOrganization()',
@@ -71,7 +72,7 @@ angular.module('SurveyQuestionFormDefinition', [])
ngOptions: 'answer_types.name for answer_types in answer_types track by answer_types.type',
addRequired: true,
editRequired: true,
column: 1
column: 2
},
// answer_options_text: {
@@ -97,7 +98,7 @@ angular.module('SurveyQuestionFormDefinition', [])
dataTitle: 'Multiple Choice Options',
dataPlacement: 'right',
dataContainer: "body",
column: 1
column: 2
},
answer_options_number: {
realName: 'answer_options',
@@ -109,7 +110,7 @@ angular.module('SurveyQuestionFormDefinition', [])
ngShow: 'type.type==="integer" || type.type==="float" ',
addRequired: true,
editRequired: true,
column: 1
column: 2
},
// answer_options_json: {
// realName: 'answer_options',
@@ -131,16 +132,17 @@ angular.module('SurveyQuestionFormDefinition', [])
type: 'text',
addRequired: false,
editRequired: false,
column: 1
column: 2
},
required: {
realName: 'default_answer',
realName: 'required_answer',
label: 'Required',
type: 'checkbox',
// checked: true,
addRequired: false,
editRequired: false,
column: 2
// trueValue: true
// label: 'Answer required or optional',
// type: 'custom',
// column: 2,
@@ -174,11 +176,7 @@ angular.module('SurveyQuestionFormDefinition', [])
ngClick: 'submitQuestion()',
ngDisabled: true,
'class': 'btn btn-sm btn-primary',
label: 'Submit Question'
},
reset: {
ngClick: 'questionReset()',
ngDisabled: true
label: 'Add Question'
}
},

View File

@@ -60,7 +60,6 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
},
onOpen: function() {
Wait('stop');
$('#survey-tabs a:first').tab('show');
// $('#surveyName').focus();
// $('#rrule_nlp_description').dblclick(function() {
// setTimeout(function() { scope.$apply(function() { scope.showRRule = (scope.showRRule) ? false : true; }); }, 100);
@@ -99,39 +98,10 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
scope.removeDialogReady();
}
scope.removeDialogReady = scope.$on('DialogReady', function() {
$('#survey-modal-dialog').dialog('open');
// $('#schedulerName').focus();
// setTimeout(function() {
// scope.$apply(function() {
// scheduler.setRRule(schedule.rrule);
// scheduler.setName(schedule.name);
// });
// }, 300);
});
$('#survey-modal-dialog').dialog('open');
});
// scope.saveSurvey = function() {
// Wait('start');
// if(scope.mode==="add"){
// $('#survey-modal-dialog').dialog('close');
// scope.$emit('SurveySaved');
// }
// else{
// // var url = data.url+ 'survey_spec/';
// Rest.setUrl(url);
// Rest.post({ name: scope.survey_name, description: scope.survey_description, spec: scope.survey_questions })
// .success(function () {
// // Wait('stop');
// $('#survey-modal-dialog').dialog('close');
// scope.$emit('SurveySaved');
// })
// .error(function (data, status) {
// ProcessErrors(scope, data, status, form, { hdr: 'Error!',
// msg: 'Failed to add new survey. Post returned status: ' + status });
// });
// }
// };
Wait('start');
if(scope.mode === 'add'){
tempSurv.survey_name = scope.survey_name;
@@ -162,7 +132,7 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
for(i=0; i<scope.survey_questions.length; i++){
scope.finalizeQuestion(scope.survey_questions[i], labels);
}
// scope.addQuestion();
Wait('stop');
} else {
AddSurvey({
@@ -190,13 +160,6 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
generator = GenerateForm,
form = SurveyMakerForm;
// if (!Empty($routeParams.template_id)) {
// url += $routeParams.template_id + '/survey_spec/';
// }
// else if (!Empty($routeParams.id)) {
// url += $routeParams.id + '/survey_spec/';
// }
if (scope.removeDialogReady) {
scope.removeDialogReady();
}
@@ -204,6 +167,7 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
scope.addQuestion();
$('#survey-modal-dialog').dialog('open');
// $('#surveyName').focus();
// $('#question_unique_required_chbox').prop('checked' , true);
});
Wait('start');
@@ -222,147 +186,7 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
scope.$emit('surveySaved');
});
// scope.saveSurvey = function() {
// Wait('start');
// $('#survey-modal-dialog').dialog('close');
// scope.$emit('SurveySaved');
// };
};
}])
.factory('SchedulePost', ['Rest', 'ProcessErrors', 'RRuleToAPI', 'Wait', function(Rest, ProcessErrors, RRuleToAPI, Wait) {
return function(params) {
var scope = params.scope,
url = params.url,
scheduler = params.scheduler,
mode = params.mode,
schedule = (params.schedule) ? params.schedule : {},
callback = params.callback,
newSchedule, rrule;
if (scheduler.isValid()) {
Wait('start');
newSchedule = scheduler.getValue();
rrule = scheduler.getRRule();
schedule.name = newSchedule.name;
schedule.rrule = RRuleToAPI(rrule.toString());
schedule.description = (/error/.test(rrule.toText())) ? '' : rrule.toText();
Rest.setUrl(url);
if (mode === 'add') {
Rest.post(schedule)
.success(function(){
if (callback) {
scope.$emit(callback);
}
else {
Wait('stop');
}
})
.error(function(data, status){
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'POST to ' + url + ' returned: ' + status });
});
}
else {
Rest.put(schedule)
.success(function(){
if (callback) {
scope.$emit(callback);
}
else {
Wait('stop');
}
})
.error(function(data, status){
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'POST to ' + url + ' returned: ' + status });
});
}
}
else {
return false;
}
};
}])
/**
* Inject the scheduler_dialog.html wherever needed
*/
.factory('LoadDialogPartial', ['Rest', '$compile', 'ProcessErrors', function(Rest, $compile, ProcessErrors) {
return function(params) {
var scope = params.scope,
element_id = params.element_id,
callback = params.callback,
url;
// Add the schedule_dialog.html partial
url = '/static/partials/schedule_dialog.html';
Rest.setUrl(url);
Rest.get()
.success(function(data) {
var e = angular.element(document.getElementById(element_id));
e.append(data);
$compile(e)(scope);
scope.$emit(callback);
})
.error(function(data, status) {
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'Call to ' + url + ' failed. GET returned: ' + status });
});
};
}])
/**
* Flip a schedule's enable flag
*
* ToggleSchedule({
* scope: scope,
* id: schedule.id to update
* callback: scope.$emit label to call when update completes
* });
*
*/
.factory('ToggleSchedule', ['Wait', 'GetBasePath', 'ProcessErrors', 'Rest', function(Wait, GetBasePath, ProcessErrors, Rest) {
return function(params) {
var scope = params.scope,
id = params.id,
callback = params.callback,
url = GetBasePath('schedules') + id +'/';
// Perform the update
if (scope.removeScheduleFound) {
scope.removeScheduleFound();
}
scope.removeScheduleFound = scope.$on('ScheduleFound', function(e, data) {
data.enabled = (data.enabled) ? false : true;
Rest.put(data)
.success( function() {
if (callback) {
scope.$emit(callback, id);
}
else {
Wait('stop');
}
})
.error( function() {
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'Failed to update schedule ' + id + ' PUT returned: ' + status });
});
});
Wait('start');
// Get the schedule
Rest.setUrl(url);
Rest.get()
.success(function(data) {
scope.$emit('ScheduleFound', data);
})
.error(function(data,status){
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'Failed to retrieve schedule ' + id + ' GET returned: ' + status });
});
};
}])
@@ -422,24 +246,99 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
};
}])
/**
* Convert rrule string to an API agreeable format
/**
* Takes a finalized question and displays it on the survey maker page
*
* FinalizeQuestion({
* scope: $scope containing list of survey form fields
* question: question object that was submitted by the question form
* id: id of job template that survey is attached to
* callback: $scope.$emit label to call when delete is completed
* })
*
*/
.factory('RRuleToAPI', [ function() {
return function(rrule) {
var response;
response = rrule.replace(/(^.*(?=DTSTART))(DTSTART=.*?;)(.*$)/, function(str, p1, p2, p3) {
return p2.replace(/\;/,'').replace(/=/,':') + ' ' + 'RRULE:' + p1 + p3;
});
return response;
.factory('FinalizeQuestion', ['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,
// callback = params.callback,
// url,
// key,
element, choices, i, checked,
max, min, defaultValue,
html = '<div class="question_final row">';
html += '<div class="col-xs-12"><b>'+question.question_name+'</b></div>\n';
if(!Empty(question.question_description)){
html += '<div class="col-xs-12"> '+question.question_description+'</div>\n';
}
defaultValue = (question.default) ? question.default : "";
if(question.type === 'text' ){
html+='<div class="row">'+
'<div class="col-xs-8">'+
'<input type="text" placeholder="'+defaultValue+'" class="form-control ng-pristine ng-invalid-required ng-invalid" required="" >'+
'</div></div>';
}
if(question.type === "textarea"){
html+='<div class="row">'+
'<div class="col-xs-8">'+
'<textarea class="form-control ng-pristine ng-invalid-required ng-invalid" 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])!==-1) ? "checked" : "";
html+='<label class="'+element+'-inline">'+
'<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" name="'+question.variable+'" min="'+min+'" max="'+max+'" value="'+defaultValue+'">'+
'</div></div>';
}
if(question.type === "json"){
}
html += '<div class="col-xs-12 text-right" id="question_actions">';
html += '<a id="edit-action" data-placement="top" ng-click="editQuestion(this)" aw-tool-tip="Edit question" data-original-title="" title=""><i class="fa fa-pencil"></i> </a>';
html += '<a id="delete-action" data-placement="top" ng-click="deleteQuestion(job_template.id, job_template.name)" aw-tool-tip="Delete template" data-original-title="" title=""><i class="fa fa-trash-o"></i> </a>';
html += '<a id="edit-action" data-placement="top" ng-click="moveQuestion(this)" aw-tool-tip="Move up" data-original-title="" title=""><i class="fa fa-sort-desc"></i> </a>';
html += '<a id="edit-action" data-placement="top" ng-click="editQuestion(this)" aw-tool-tip="Edit question" data-original-title="" title=""><i class="fa fa-sort-asc"></i> </a>';
html+='</div></div>';
$('#finalized_questions').append(html);
element = angular.element(document.getElementById('finalized_questions'));
// element.html(html);
$compile(element)(scope);
// var questionScope = scope.$new;
$('#add_question_btn').show();
$('#add_question_btn').removeAttr('disabled');
$('#survey_maker_save_btn').removeAttr('disabled');
};
}])
.factory('SurveyControllerInit', ['$location', 'DeleteSurvey', 'EditSurvey', 'AddSurvey', 'GenerateForm', 'SurveyQuestionForm', 'Wait', 'Alert',
'GetBasePath', 'Rest', 'ProcessErrors' ,
function($location, DeleteSurvey, EditSurvey, AddSurvey, GenerateForm, SurveyQuestionForm, Wait, Alert, GetBasePath, Rest, ProcessErrors) {
'GetBasePath', 'Rest', 'ProcessErrors' , '$compile', 'FinalizeQuestion',
function($location, DeleteSurvey, EditSurvey, AddSurvey, GenerateForm, SurveyQuestionForm, Wait, Alert,
GetBasePath, Rest, ProcessErrors, $compile, FinalizeQuestion) {
return function(params) {
var scope = params.scope,
// parent_scope = params.parent_scope,
@@ -456,7 +355,7 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
{name: 'Multiple Choice (multiple select)', type: 'multiselect'},
{name: 'JSON', type: 'json'},
{name: 'Integer', type: 'integer'},
{name: 'Float', type: 'number'}
{name: 'Float', type: 'float'}
];
scope.deleteSurvey = function() {
@@ -482,29 +381,27 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
});
};
scope.addQuestion = function(){
GenerateForm.inject(SurveyQuestionForm, { id:'new_question', scope:scope, breadCrumbs: false});
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.
};
scope.editQuestion = function(question){
alert('success : ' + question);
};
scope.finalizeQuestion= function(data, labels){
var key,
html = '<div class="question_final row">';
for (key in data) {
html+='<div class="col-xs-6"><label for="question_text"><span class="label-text">'+labels[key] +': </span></label>'+data[key]+'</div>\n';
}
html+='</div>';
$('#finalized_questions').before(html);
$('#add_question_btn').show();
$('#add_question_btn').removeAttr('disabled');
$('#survey_maker_save_btn').removeAttr('disabled');
scope.finalizeQuestion= function(data){
FinalizeQuestion({
scope: scope,
question: data,
id: id,
//callback?
});
};
scope.addNewQuestion = function(){
// $('#add_question_btn').on("click" , function(){
scope.addQuestion();
$('#add_question_btn').attr('disabled', 'disabled');
$('#add_question_btn').hide();
// });
};
scope.submitQuestion = function(){
@@ -538,6 +435,8 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
Wait('stop');
scope.survey_questions.push(data);
$('#new_question .aw-form-well').remove();
// scope.addQuestion()
$('#add_question_btn').show();
// for(fld in form.fields){
// $scope[fld] = '';
// }
@@ -571,137 +470,6 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
}
};
};
}])
.factory('SchedulesListInit', [ function() {
return function(params) {
var scope = params.scope,
list = params.list,
choices = params.choices;
scope[list.name].forEach(function(item, item_idx) {
var fld, field,
itm = scope[list.name][item_idx];
itm.enabled = (itm.enabled) ? true : false;
if (itm.enabled) {
itm.play_tip = 'Schedule is active. Click to stop.';
itm.status = 'active';
itm.status_tip = 'Schedule is active. Click to stop.';
}
else {
itm.play_tip = 'Schedule is stopped. Click to activate.';
itm.status = 'stopped';
itm.status_tip = 'Schedule is stopped. Click to activate.';
}
itm.nameTip = item.name + " schedule. Click to edit.";
// Copy summary_field values
for (field in list.fields) {
fld = list.fields[field];
if (fld.sourceModel) {
if (itm.summary_fields[fld.sourceModel]) {
itm[field] = itm.summary_fields[fld.sourceModel][fld.sourceField];
}
}
}
// Set the item type label
if (list.fields.type) {
choices.every(function(choice) {
if (choice.value === item.type) {
itm.type_label = choice.label;
return false;
}
return true;
});
}
});
};
}])
/**
*
* Called from a controller to setup the scope for a schedules list
*
*/
.factory('LoadSchedulesScope', ['$compile', '$location', '$routeParams','SearchInit', 'PaginateInit', 'GenerateList', 'SchedulesControllerInit',
'SchedulesListInit', 'SearchWidget',
function($compile, $location, $routeParams, SearchInit, PaginateInit, GenerateList, SchedulesControllerInit, SchedulesListInit, SearchWidget) {
return function(params) {
var parent_scope = params.parent_scope,
scope = params.scope,
list = params.list,
id = params.id,
url = params.url,
pageSize = params.pageSize || 5,
spinner = (params.spinner === undefined) ? true : params.spinner,
base = $location.path().replace(/^\//, '').split('/')[0],
e, html;
if (base === 'jobs') {
// on jobs page the search widget appears on the right
html = SearchWidget({
iterator: list.iterator,
template: params.list,
includeSize: false
});
e = angular.element(document.getElementById(id + '-search-container')).append(html);
$compile(e)(scope);
GenerateList.inject(list, {
mode: 'edit',
id: id,
breadCrumbs: false,
scope: scope,
showSearch: false
});
}
else {
GenerateList.inject(list, {
mode: 'edit',
id: id,
breadCrumbs: false,
scope: scope,
searchSize: 'col-lg-6 col-md-6 col-sm-6 col-xs-12',
showSearch: true
});
}
SearchInit({
scope: scope,
set: list.name,
list: list,
url: url
});
PaginateInit({
scope: scope,
list: list,
url: url,
pageSize: pageSize
});
scope.iterator = list.iterator;
if (scope.removePostRefresh) {
scope.removePostRefresh();
}
scope.$on('PostRefresh', function(){
SchedulesControllerInit({
scope: scope,
parent_scope: parent_scope,
list: list
});
SchedulesListInit({
scope: scope,
list: list,
choices: parent_scope.type_choices
});
parent_scope.$emit('listLoaded');
});
if ($routeParams.id__int) {
scope[list.iterator + 'SearchField'] = 'id';
scope[list.iterator + 'SearchValue'] = $routeParams.id__int;
scope[list.iterator + 'SearchFieldLabel'] = 'ID';
}
scope.search(list.iterator, null, null, null, null, spinner);
};
}]);

View File

@@ -34,13 +34,31 @@
}
.question_final{
border: 1px dashed;
border-color: rgb(204,204,204);
border-radius: 4px;
/*border: 1px dashed;
*border-color: rgb(204,204,204);
*border-radius: 4px;
*/
padding: 5px;
margin-top: 15px;
height: 130px;
opacity: 0.4;
opacity: 0.7;
textarea{
margin-left: 15px;
}
input{
margin-left: 15px;
}
label{
margin-left: 15px;
}
}
#new_question{
margin-top: 5px;
}
question_actions{
opacity: 1.0;
}
#add_question_btn{

View File

@@ -63,6 +63,32 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Job
};
})
// caplitalize Add to any input field where the first letter of each
// word should be capitalized. Use in place of css test-transform.
// For some reason "text-transform: capitalize" in breadcrumbs
// causes a break at each blank space. And of course,
// "autocapitalize='word'" only works in iOS. Use this as a fix.
.directive('awSurveyQuestion', function() {
return {
require: 'ngModel',
link: function(scope, elm, attrs, ctrl) {
ctrl.$parsers.unshift( function(viewValue) {
var values = viewValue.split(" "),
result = "", i;
result += values[0].charAt(0).toUpperCase() + values[0].substr(1) + ' ';
for (i = 1; i < values.length; i++){
result += values[i] + ' ';
}
result = result.trim();
if (result !== viewValue) {
ctrl.$setViewValue(result);
ctrl.$render();
}
return result;
});
}
};
})
// integer Validate that input is of type integer. Taken from Angular developer
// guide, form examples. Add min and max directives, and this will check
// entered values is within the range.

View File

@@ -735,6 +735,7 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'Utilities', 'ListGenerator
html += (field.readonly || field.showonly) ? "readonly " : "";
html += (field.awPassMatch) ? "awpassmatch=\"" + field.associated + "\" " : "";
html += (field.capitalize) ? "capitalize " : "";
html += (field.awSurveyQuestion) ? "aw-survey-question" : "" ;
html += (field.ask) ? "ng-disabled=\"" + fld + "_ask\" " : "";
html += (field.autocomplete !== undefined) ? this.attr(field, 'autocomplete') : "";
html += (field.awRequiredWhen) ? "data-awrequired-init=\"" + field.awRequiredWhen.init + "\" aw-required-when=\"" +
@@ -905,7 +906,12 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'Utilities', 'ListGenerator
field.awRequiredWhen.variable + "\" " : "";
html += ">\n";
html += "<option value=\"\">";
html += (field.defaultOption) ? field.defaultOption : "Choose a " + field.label.toLowerCase();
//for survey maker, needed the select drop down to say "select an answer type"
if(form.name === "question_unique"){
html += (field.defaultOption) ? field.defaultOption : "Choose an " + field.label.toLowerCase();
} else{
html += (field.defaultOption) ? field.defaultOption : "Choose a " + field.label.toLowerCase();
}
html += "</option>\n";
html += "</select>\n";
// Add error messages