mirror of
https://github.com/ansible/awx.git
synced 2026-01-14 11:20:39 -03:30
adding more survey maker form validation
added validation on integers and floats that ensure answers are int/floats and that they meet the restrictions placed by min/max
This commit is contained in:
parent
71e87f7a41
commit
13bf8d89d0
@ -1,629 +0,0 @@
|
||||
/************************************
|
||||
* Copyright (c) 2014 AnsibleWorks, Inc.
|
||||
*
|
||||
*
|
||||
* SurveyMaker.js
|
||||
*
|
||||
* Controller functions for the survey maker
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name controllers.function:SurveyMaker
|
||||
* @description This controller's for the survey maker page.
|
||||
* The survey maker interacts with the job template page, and the two go hand in hand. The scenarios are:
|
||||
* New job template - add new survey
|
||||
* New job template - edit new survey
|
||||
* Edit existing job template - add new survey
|
||||
* Edit Existing job template - edit existing survey
|
||||
*
|
||||
* Adding a new survey to any page takes the user to the Add New Survey page
|
||||
* Adding a new survey to a new job template saves the survey to session memory (navigating to survey maker forces us to save JT in memory temporarily)
|
||||
* Adding a new survey to an existing job template send the survey to the API
|
||||
* Editing an existing survey takes the user to the Edit Survey page
|
||||
* Editing a survey attached to a new job template saves the survey to session memory (saves the job template in session memory)
|
||||
* Editing a survey attached to an existing job template saves the survey to the API
|
||||
*
|
||||
* The variables in local memory are cleaned out whenever the user navigates to a page (other than the Survey Maker page)
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
function SurveyMakerAdd($scope, $rootScope, $compile, $location, $log, $routeParams, SurveyMakerForm,
|
||||
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ClearScope, GetBasePath,
|
||||
ReturnToCaller, Wait, SurveyQuestionForm, Store) {
|
||||
|
||||
ClearScope();
|
||||
|
||||
// Inject dynamic view
|
||||
var generator = GenerateForm,
|
||||
form = SurveyMakerForm,
|
||||
base = $location.path().replace(/^\//, '').split('/')[0],
|
||||
id = $location.path().replace(/^\//, '').split('/')[1];
|
||||
|
||||
$scope.survey_questions=[];
|
||||
$scope.Store = Store;
|
||||
$scope.answer_types=[
|
||||
{name: 'Text' , type: 'text'},
|
||||
{name: 'Textarea', type: 'textarea'},
|
||||
{name: 'Multiple Choice (single select)', type: 'multiplechoice'},
|
||||
{name: 'Multiple Choice (multiple select)', type: 'multiselect'},
|
||||
{name: 'JSON', type: 'json'},
|
||||
{name: 'Integer', type: 'integer'},
|
||||
{name: 'Float', type: 'number'}
|
||||
];
|
||||
|
||||
|
||||
generator.inject(form, { mode: 'add', related: false, scope: $scope});
|
||||
generator.reset();
|
||||
// LoadBreadCrumbs();
|
||||
// LoadBreadCrumbs({
|
||||
// path: '/job_templates/' + id + '/survey',
|
||||
// title: 'jared rocks', // $scope.job_id + ' - ', //+ data.summary_fields.job_template.name,
|
||||
// altPath: '/job_templates/' + id + '/survey',
|
||||
// });
|
||||
|
||||
$scope.addQuestion = function(){
|
||||
|
||||
GenerateForm.inject(SurveyQuestionForm, {mode:'modal', id:'new_question', scope:$scope, breadCrumbs: false});
|
||||
};
|
||||
$scope.addQuestion();
|
||||
|
||||
// $('#question_shadow').mouseenter(function(){
|
||||
// $('#question_shadow').css({
|
||||
// "opacity": "1",
|
||||
// "border": "1px solid",
|
||||
// "border-color": "rgb(204,204,204)",
|
||||
// "border-radius": "4px"
|
||||
// });
|
||||
// $('#question_add_btn').show();
|
||||
// });
|
||||
|
||||
// $('#question_shadow').mouseleave(function(){
|
||||
// $('#question_shadow').css({
|
||||
// "opacity": ".4",
|
||||
// "border": "1px dashed",
|
||||
// "border-color": "rgb(204,204,204)",
|
||||
// "border-radius": "4px"
|
||||
// });
|
||||
// $('#question_add_btn').hide();
|
||||
// })
|
||||
|
||||
|
||||
// $('#question_shadow').on("click" , function(){
|
||||
// // var survey_width = $('#survey_maker_question_area').width()-10,
|
||||
// // html = "";
|
||||
|
||||
// // $('#add_question_btn').attr('disabled', 'disabled')
|
||||
// // $('#survey_maker_question_area').append(html);
|
||||
// addQuestion();
|
||||
// $('#question_shadow').hide();
|
||||
// $('#question_shadow').css({
|
||||
// "opacity": ".4",
|
||||
// "border": "1px dashed",
|
||||
// "border-color": "rgb(204,204,204)",
|
||||
// "border-radius": "4px"
|
||||
// });
|
||||
// });
|
||||
$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');
|
||||
};
|
||||
|
||||
$('#add_question_btn').on("click" , function(){
|
||||
$scope.addQuestion();
|
||||
$('#add_question_btn').attr('disabled', 'disabled');
|
||||
});
|
||||
|
||||
$scope.submitQuestion = function(){
|
||||
var form = SurveyQuestionForm,
|
||||
data = {},
|
||||
labels={},
|
||||
min= "min",
|
||||
max = "max",
|
||||
fld;
|
||||
//generator.clearApiErrors();
|
||||
Wait('start');
|
||||
|
||||
try {
|
||||
for (fld in form.fields) {
|
||||
if($scope[fld]){
|
||||
if(fld === "type"){
|
||||
data[fld] = $scope[fld].type;
|
||||
if($scope[fld].type==="integer" || $scope[fld].type==="float"){
|
||||
data[min] = $('#answer_min').val();
|
||||
data[max] = $('#answer_max').val();
|
||||
labels[min]= "Min";
|
||||
labels[max]= "Max";
|
||||
}
|
||||
}
|
||||
else{
|
||||
data[fld] = $scope[fld];
|
||||
}
|
||||
labels[fld] = form.fields[fld].label;
|
||||
}
|
||||
}
|
||||
Wait('stop');
|
||||
$scope.survey_questions.push(data);
|
||||
$('#new_question .aw-form-well').remove();
|
||||
// for(fld in form.fields){
|
||||
// $scope[fld] = '';
|
||||
// }
|
||||
$scope.finalizeQuestion(data , labels);
|
||||
|
||||
} catch (err) {
|
||||
Wait('stop');
|
||||
Alert("Error", "Error parsing extra variables. Parser returned: " + err);
|
||||
}
|
||||
};
|
||||
|
||||
$scope.formSave = function () {
|
||||
generator.clearApiErrors();
|
||||
Wait('start');
|
||||
var url;
|
||||
if(!$scope.Store("survey_for_new_job_template") && $scope.Store("survey_for_new_job_template")!==false){
|
||||
$scope.Store('survey_for_new_job_template', {
|
||||
// survey_created: true,
|
||||
name: $scope.survey_name,
|
||||
description: $scope.survey_description,
|
||||
spec:$scope.survey_questions
|
||||
});
|
||||
Wait('stop');
|
||||
$location.path("/job_templates/add/");
|
||||
}
|
||||
else {
|
||||
url = GetBasePath(base)+ id + '/survey_spec/';
|
||||
|
||||
Rest.setUrl(url);
|
||||
Rest.post({ name: $scope.survey_name, description: $scope.survey_description, spec:$scope.survey_questions })
|
||||
.success(function () {
|
||||
Wait('stop');
|
||||
$location.path("/job_templates/"+id);
|
||||
})
|
||||
.error(function (data, status) {
|
||||
ProcessErrors($scope, data, status, form, { hdr: 'Error!',
|
||||
msg: 'Failed to add new survey. Post returned status: ' + status });
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Save
|
||||
$scope.formSave = function () {
|
||||
generator.clearApiErrors();
|
||||
Wait('start');
|
||||
if($scope.Store("saved_job_template_for_survey")){
|
||||
$scope.Store('survey_for_new_job_template', {
|
||||
// survey_created: true,
|
||||
name: $scope.survey_name,
|
||||
description: $scope.survey_description,
|
||||
spec:$scope.survey_questions
|
||||
});
|
||||
Wait('stop');
|
||||
$location.path("/job_templates/add/");
|
||||
}
|
||||
else{
|
||||
var url = GetBasePath(base)+ id + '/survey_spec/';
|
||||
Rest.setUrl(url);
|
||||
Rest.post({ name: $scope.survey_name, description: $scope.survey_description, spec:$scope.survey_questions })
|
||||
.success(function () {
|
||||
Wait('stop');
|
||||
$location.path("/job_templates/"+id);
|
||||
})
|
||||
.error(function (data, status) {
|
||||
ProcessErrors($scope, data, status, form, { hdr: 'Error!',
|
||||
msg: 'Failed to add new survey. Post returned status: ' + status });
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// Cancel
|
||||
$scope.formReset = function () {
|
||||
$rootScope.flashMessage = null;
|
||||
generator.reset();
|
||||
};
|
||||
}
|
||||
|
||||
SurveyMakerAdd.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'SurveyMakerForm',
|
||||
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ClearScope', 'GetBasePath', 'ReturnToCaller', 'Wait', 'SurveyQuestionForm', 'Store'
|
||||
];
|
||||
|
||||
function SurveyMakerEdit($scope, $rootScope, $compile, $location, $log, $routeParams, SurveyMakerForm,
|
||||
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ClearScope, GetBasePath,
|
||||
ReturnToCaller, Wait, SurveyQuestionForm, Store) {
|
||||
|
||||
ClearScope();
|
||||
|
||||
// Inject dynamic view
|
||||
var generator = GenerateForm,
|
||||
form = SurveyMakerForm,
|
||||
base = $location.path().replace(/^\//, '').split('/')[0],
|
||||
id = $location.path().replace(/^\//, '').split('/')[1],
|
||||
i, data;
|
||||
|
||||
$scope.survey_questions=[];
|
||||
|
||||
$scope.answer_types=[
|
||||
{name: 'Text' , type: 'text'},
|
||||
{name: 'Textarea', type: 'textarea'},
|
||||
{name: 'Multiple Choice (single select)', type: 'multiplechoice'},
|
||||
{name: 'Multiple Choice (multiple select)', type: 'multiselect'},
|
||||
{name: 'JSON', type: 'json'},
|
||||
{name: 'Integer', type: 'integer'},
|
||||
{name: 'Float', type: 'number'}
|
||||
];
|
||||
|
||||
$scope.Store = Store;
|
||||
|
||||
generator.inject(form, { mode: 'edit', related: false, scope: $scope});
|
||||
generator.reset();
|
||||
// LoadBreadCrumbs();
|
||||
// LoadBreadCrumbs({
|
||||
// path: '/job_templates/' + id + '/survey',
|
||||
// title: 'jared rocks', // $scope.job_id + ' - ', //+ data.summary_fields.job_template.name,
|
||||
// altPath: '/job_templates/' + id + '/survey',
|
||||
// });
|
||||
|
||||
$scope.addQuestion = function(){
|
||||
|
||||
GenerateForm.inject(SurveyQuestionForm, {mode:'add', id:'new_question', scope:$scope, breadCrumbs: false});
|
||||
};
|
||||
// $scope.addQuestion();
|
||||
|
||||
// $('#question_shadow').mouseenter(function(){
|
||||
// $('#question_shadow').css({
|
||||
// "opacity": "1",
|
||||
// "border": "1px solid",
|
||||
// "border-color": "rgb(204,204,204)",
|
||||
// "border-radius": "4px"
|
||||
// });
|
||||
// $('#question_add_btn').show();
|
||||
// });
|
||||
|
||||
// $('#question_shadow').mouseleave(function(){
|
||||
// $('#question_shadow').css({
|
||||
// "opacity": ".4",
|
||||
// "border": "1px dashed",
|
||||
// "border-color": "rgb(204,204,204)",
|
||||
// "border-radius": "4px"
|
||||
// });
|
||||
// $('#question_add_btn').hide();
|
||||
// })
|
||||
|
||||
|
||||
// $('#question_shadow').on("click" , function(){
|
||||
// // var survey_width = $('#survey_maker_question_area').width()-10,
|
||||
// // html = "";
|
||||
|
||||
// // $('#add_question_btn').attr('disabled', 'disabled')
|
||||
// // $('#survey_maker_question_area').append(html);
|
||||
// addQuestion();
|
||||
// $('#question_shadow').hide();
|
||||
// $('#question_shadow').css({
|
||||
// "opacity": ".4",
|
||||
// "border": "1px dashed",
|
||||
// "border-color": "rgb(204,204,204)",
|
||||
// "border-radius": "4px"
|
||||
// });
|
||||
// });
|
||||
$scope.finalizeQuestion= function(data){
|
||||
var key,
|
||||
labels={
|
||||
"type": "Type",
|
||||
"question_name": "Question Text",
|
||||
"question_description": "Question Description",
|
||||
"variable": "Answer Varaible Name",
|
||||
"choices": "Choices",
|
||||
"min": "Min",
|
||||
"max": "Max",
|
||||
"required": "Required",
|
||||
"default": "Default Answer"
|
||||
},
|
||||
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');
|
||||
};
|
||||
|
||||
$('#add_question_btn').on("click" , function(){
|
||||
$scope.addQuestion();
|
||||
$('#add_question_btn').attr('disabled', 'disabled');
|
||||
});
|
||||
|
||||
Wait('start');
|
||||
|
||||
if($scope.Store("saved_job_template_for_survey") && $scope.Store("saved_job_template_for_survey").editing_survey===true){
|
||||
data = $scope.Store("survey_for_new_job_template");
|
||||
$scope.survey_name = data.name;
|
||||
$scope.survey_description = data.description;
|
||||
$scope.survey_questions = data.spec;
|
||||
for(i=0; i<$scope.survey_questions.length; i++){
|
||||
$scope.finalizeQuestion($scope.survey_questions[i]);
|
||||
}
|
||||
Wait('stop');
|
||||
}
|
||||
else{
|
||||
Rest.setUrl(GetBasePath(base)+ id + '/survey_spec/');
|
||||
Rest.get()
|
||||
.success(function (data) {
|
||||
var i;
|
||||
$scope.survey_name = data.name;
|
||||
$scope.survey_description = data.description;
|
||||
$scope.survey_questions = data.spec;
|
||||
for(i=0; i<$scope.survey_questions.length; i++){
|
||||
$scope.finalizeQuestion($scope.survey_questions[i]);
|
||||
}
|
||||
Wait('stop');
|
||||
// LoadBreadCrumbs({ path: '/organizations/' + id, title: data.name });
|
||||
// for (fld in form.fields) {
|
||||
// if (data[fld]) {
|
||||
// $scope[fld] = data[fld];
|
||||
// master[fld] = data[fld];
|
||||
// }
|
||||
// }
|
||||
|
||||
// related = data.related;
|
||||
// for (set in form.related) {
|
||||
// if (related[set]) {
|
||||
// relatedSets[set] = {
|
||||
// url: related[set],
|
||||
// iterator: form.related[set].iterator
|
||||
// };
|
||||
// }
|
||||
// }
|
||||
|
||||
// Initialize related search functions. Doing it here to make sure relatedSets object is populated.
|
||||
// RelatedSearchInit({ scope: $scope, form: form, relatedSets: relatedSets });
|
||||
// RelatedPaginateInit({ scope: $scope, relatedSets: relatedSets });
|
||||
// $scope.$emit('organizationLoaded');
|
||||
})
|
||||
.error(function (data, status) {
|
||||
ProcessErrors($scope, data, status, form, { hdr: 'Error!',
|
||||
msg: 'Failed to retrieve organization: ' + $routeParams.id + '. GET status: ' + status });
|
||||
});
|
||||
}
|
||||
$scope.submitQuestion = function(){
|
||||
var form = SurveyQuestionForm,
|
||||
data = {},
|
||||
labels={},
|
||||
min= "min",
|
||||
max = "max",
|
||||
fld;
|
||||
//generator.clearApiErrors();
|
||||
Wait('start');
|
||||
|
||||
try {
|
||||
for (fld in form.fields) {
|
||||
if($scope[fld]){
|
||||
if(fld === "type"){
|
||||
data[fld] = $scope[fld].type;
|
||||
if($scope[fld].type==="integer" || $scope[fld].type==="float"){
|
||||
data[min] = $('#answer_min').val();
|
||||
data[max] = $('#answer_max').val();
|
||||
labels[min]= "Min";
|
||||
labels[max]= "Max";
|
||||
}
|
||||
}
|
||||
else{
|
||||
data[fld] = $scope[fld];
|
||||
}
|
||||
labels[fld] = form.fields[fld].label;
|
||||
}
|
||||
}
|
||||
Wait('stop');
|
||||
$scope.survey_questions.push(data);
|
||||
$('#new_question .aw-form-well').remove();
|
||||
// for(fld in form.fields){
|
||||
// $scope[fld] = '';
|
||||
// }
|
||||
$scope.finalizeQuestion(data , labels);
|
||||
|
||||
} catch (err) {
|
||||
Wait('stop');
|
||||
Alert("Error", "Error parsing extra variables. Parser returned: " + err);
|
||||
}
|
||||
};
|
||||
// Save
|
||||
$scope.formSave = function () {
|
||||
generator.clearApiErrors();
|
||||
Wait('start');
|
||||
var url;
|
||||
if($scope.Store("survey_for_new_job_template") && $scope.Store("survey_for_new_job_template")!==false){
|
||||
$scope.Store('survey_for_new_job_template', {
|
||||
// survey_created: true,
|
||||
name: $scope.survey_name,
|
||||
description: $scope.survey_description,
|
||||
spec:$scope.survey_questions
|
||||
});
|
||||
Wait('stop');
|
||||
$location.path("/job_templates/add/");
|
||||
}
|
||||
else {
|
||||
url = GetBasePath(base)+ id + '/survey_spec/';
|
||||
|
||||
Rest.setUrl(url);
|
||||
Rest.post({ name: $scope.survey_name, description: $scope.survey_description, spec:$scope.survey_questions })
|
||||
.success(function () {
|
||||
Wait('stop');
|
||||
$location.path("/job_templates/"+id);
|
||||
})
|
||||
.error(function (data, status) {
|
||||
ProcessErrors($scope, data, status, form, { hdr: 'Error!',
|
||||
msg: 'Failed to add new survey. Post returned status: ' + status });
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Cancel
|
||||
$scope.formReset = function () {
|
||||
$rootScope.flashMessage = null;
|
||||
generator.reset();
|
||||
};
|
||||
}
|
||||
|
||||
SurveyMakerEdit.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'SurveyMakerForm',
|
||||
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ClearScope', 'GetBasePath', 'ReturnToCaller', 'Wait', 'SurveyQuestionForm', 'Store'
|
||||
];
|
||||
|
||||
|
||||
|
||||
// function OrganizationsEdit($scope, $rootScope, $compile, $location, $log, $routeParams, OrganizationForm, GenerateForm, Rest,
|
||||
// Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit, RelatedPaginateInit, Prompt, ClearScope, GetBasePath, Wait, Stream) {
|
||||
|
||||
// ClearScope();
|
||||
|
||||
// // Inject dynamic view
|
||||
// var form = OrganizationForm,
|
||||
// generator = GenerateForm,
|
||||
// defaultUrl = GetBasePath('organizations'),
|
||||
// base = $location.path().replace(/^\//, '').split('/')[0],
|
||||
// master = {},
|
||||
// id = $routeParams.organization_id,
|
||||
// relatedSets = {};
|
||||
|
||||
// generator.inject(form, { mode: 'edit', related: true, scope: $scope});
|
||||
// generator.reset();
|
||||
|
||||
// // After the Organization is loaded, retrieve each related set
|
||||
// if ($scope.organizationLoadedRemove) {
|
||||
// $scope.organizationLoadedRemove();
|
||||
// }
|
||||
// $scope.organizationLoadedRemove = $scope.$on('organizationLoaded', function () {
|
||||
// for (var set in relatedSets) {
|
||||
// $scope.search(relatedSets[set].iterator);
|
||||
// }
|
||||
// Wait('stop');
|
||||
// });
|
||||
|
||||
// // Retrieve detail record and prepopulate the form
|
||||
// Wait('start');
|
||||
// Rest.setUrl(defaultUrl + id + '/');
|
||||
// Rest.get()
|
||||
// .success(function (data) {
|
||||
// var fld, related, set;
|
||||
// LoadBreadCrumbs({ path: '/organizations/' + id, title: data.name });
|
||||
// for (fld in form.fields) {
|
||||
// if (data[fld]) {
|
||||
// $scope[fld] = data[fld];
|
||||
// master[fld] = data[fld];
|
||||
// }
|
||||
// }
|
||||
// related = data.related;
|
||||
// for (set in form.related) {
|
||||
// if (related[set]) {
|
||||
// relatedSets[set] = {
|
||||
// url: related[set],
|
||||
// iterator: form.related[set].iterator
|
||||
// };
|
||||
// }
|
||||
// }
|
||||
// // Initialize related search functions. Doing it here to make sure relatedSets object is populated.
|
||||
// RelatedSearchInit({ scope: $scope, form: form, relatedSets: relatedSets });
|
||||
// RelatedPaginateInit({ scope: $scope, relatedSets: relatedSets });
|
||||
// $scope.$emit('organizationLoaded');
|
||||
// })
|
||||
// .error(function (data, status) {
|
||||
// ProcessErrors($scope, data, status, form, { hdr: 'Error!',
|
||||
// msg: 'Failed to retrieve organization: ' + $routeParams.id + '. GET status: ' + status });
|
||||
// });
|
||||
|
||||
|
||||
// // Save changes to the parent
|
||||
// $scope.formSave = function () {
|
||||
// var fld, params = {};
|
||||
// generator.clearApiErrors();
|
||||
// Wait('start');
|
||||
// for (fld in form.fields) {
|
||||
// params[fld] = $scope[fld];
|
||||
// }
|
||||
// Rest.setUrl(defaultUrl + id + '/');
|
||||
// Rest.put(params)
|
||||
// .success(function () {
|
||||
// Wait('stop');
|
||||
// master = params;
|
||||
// $rootScope.flashMessage = "Your changes were successfully saved!";
|
||||
// })
|
||||
// .error(function (data, status) {
|
||||
// ProcessErrors($scope, data, status, OrganizationForm, { hdr: 'Error!',
|
||||
// msg: 'Failed to update organization: ' + id + '. PUT status: ' + status });
|
||||
// });
|
||||
// };
|
||||
|
||||
// $scope.showActivity = function () {
|
||||
// Stream({
|
||||
// scope: $scope
|
||||
// });
|
||||
// };
|
||||
|
||||
// // Reset the form
|
||||
// $scope.formReset = function () {
|
||||
// $rootScope.flashMessage = null;
|
||||
// generator.reset();
|
||||
// for (var fld in master) {
|
||||
// $scope[fld] = master[fld];
|
||||
// }
|
||||
// };
|
||||
|
||||
// // Related set: Add button
|
||||
// $scope.add = function (set) {
|
||||
// $rootScope.flashMessage = null;
|
||||
// $location.path('/' + base + '/' + $routeParams.organization_id + '/' + set);
|
||||
// };
|
||||
|
||||
// // Related set: Edit button
|
||||
// $scope.edit = function (set, id) {
|
||||
// $rootScope.flashMessage = null;
|
||||
// $location.path('/' + set + '/' + id);
|
||||
// };
|
||||
|
||||
// // Related set: Delete button
|
||||
// $scope['delete'] = function (set, itm_id, name, title) {
|
||||
// $rootScope.flashMessage = null;
|
||||
|
||||
// var action = function () {
|
||||
// Wait('start');
|
||||
// var url = defaultUrl + $routeParams.organization_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
|
||||
// });
|
||||
|
||||
// };
|
||||
// }
|
||||
|
||||
// OrganizationsEdit.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'OrganizationForm', 'GenerateForm',
|
||||
// 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit', 'RelatedPaginateInit', 'Prompt', 'ClearScope', 'GetBasePath',
|
||||
// 'Wait', 'Stream'
|
||||
// ];
|
||||
@ -98,12 +98,12 @@ angular.module('SurveyQuestionFormDefinition', [])
|
||||
type: 'custom',
|
||||
control: '<div class="row">'+
|
||||
'<div class="col-xs-6">'+
|
||||
'<label for="minimum"><span class="label-text">Minimum</span></label><input id="float_min" type="number" ng-model="float_min" class="form-control" integer >'+
|
||||
'<div class="error" ng-show="survey_question_form.default_int.$invalid">This is not valid integer!</div>'+
|
||||
'<label for="minimum"><span class="label-text">Minimum</span></label><input id="float_min" type="number" name="float_min" ng-model="float_min" class="form-control" smartFloat >'+
|
||||
'<div class="error" ng-show="survey_question_form.float_min.$invalid">This is not valid float!</div>'+
|
||||
'</div>'+
|
||||
'<div class="col-xs-6">'+
|
||||
'<label for="minimum"><span class="label-text">Maximum</span></label><input id="float_max" type="number" ng-model="float_max" class="form-control" integer >'+
|
||||
'<div class="error" ng-show="survey_question_form.float.$invalid">This is not valid integer!</div>'+
|
||||
'<label for="minimum"><span class="label-text">Maximum</span></label><input id="float_max" type="number" name="float_max" ng-model="float_max" class="form-control" smartFloat >'+
|
||||
'<div class="error" ng-show="survey_question_form.float_max.$invalid">This is not valid float!</div>'+
|
||||
'</div>'+
|
||||
'</div>',
|
||||
ngShow: 'type.type==="float" ',
|
||||
@ -138,45 +138,19 @@ angular.module('SurveyQuestionFormDefinition', [])
|
||||
'<input type="number" ng-model="default_int" name="default_int" ng-min="int_min" ng-max="int_max" class="form-control" integer />'+
|
||||
'<div class="error" ng-show="survey_question_form.default_int.$error.number || survey_question_form.default_int.$error.integer">This is not valid integer!</div>'+
|
||||
'<div class="error" ng-show="survey_question_form.default_int.$error.ngMin || survey_question_form.default_int.$error.ngMax"> The value must be in range {{int_min}} to {{int_max}}!</div>'+
|
||||
// 'value = {{default_int}}<br>'+
|
||||
// 'value.$valid = {{survey_question_form.default_int.$valid}}'+
|
||||
'</div>',
|
||||
|
||||
// '<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" survey-integer></div></div>'+
|
||||
// '<br><div ng-show="survey_question.default_int.$error.survey-integer">This is not valid integer!</div>',
|
||||
|
||||
|
||||
// '<div class="row">'+
|
||||
// '<div class="col-xs-6>'+
|
||||
// '<input id="default_int" ng-model="default_int" type="number" class=" col-xs-6 form-control" integer>'+
|
||||
|
||||
// '<div class="error" id="survey_question-default_int-required-error" ng-show="survey_question.default_int.$error.integer">This is not valid integer!</div>'+
|
||||
// // '<div class="error api-error ng-binding" id="survey_question-default_int-api-error" ng-bind="default_int_api_error"></div>'+
|
||||
// '</div>'+
|
||||
// '</div>',
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// <div>
|
||||
// <input type="text" ng-model="question_name" name="question_name" id="survey_question_question_name" class="form-control ng-pristine ng-invalid ng-invalid-required" required="" aw-survey-question="">
|
||||
// <div class="error ng-hide" id="survey_question-question_name-required-error" ng-show="survey_question_form.question_name.$dirty && survey_question_form.question_name.$error.required">A value is required!</div>
|
||||
// <div class="error api-error ng-binding" id="survey_question-question_name-api-error" ng-bind="question_name_api_error"></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>',
|
||||
control: '<div>'+
|
||||
'<label for="default_float"><span class="label-text">Default Answer</span></label>'+
|
||||
'<input type="number" ng-model="default_float" name="default_float" ng-min="float_min" ng-max="float_max" class="form-control" integer />'+
|
||||
'<div class="error" ng-show="survey_question_form.default_float.$error.number || survey_question_form.default_float.$error.integer">This is not valid float!</div>'+
|
||||
'<div class="error" ng-show="survey_question_form.default_float.$error.ngMin || survey_question_form.default_float.$error.ngMax"> The value must be in range {{float_min}} to {{float_max}}!</div>'+
|
||||
'</div>',
|
||||
column: 2,
|
||||
ngShow: 'type.type=== "float" '
|
||||
},
|
||||
|
||||
@ -284,7 +284,7 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
|
||||
index = params.index,
|
||||
required,
|
||||
element, choices, i, checked,
|
||||
max, min, defaultValue, numberValidation,
|
||||
max, min, defaultValue,
|
||||
|
||||
html = "";
|
||||
|
||||
@ -304,15 +304,17 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
|
||||
if(!Empty(question.question_description)){
|
||||
html += '<div class="col-xs-12 description"><i>'+question.question_description+'</i></div>\n';
|
||||
}
|
||||
defaultValue = (question.default) ? question.default : "";
|
||||
// defaultValue = (question.default) ? question.default : "";
|
||||
|
||||
if(question.type === 'text' ){
|
||||
defaultValue = (question.default) ? question.default : "";
|
||||
html+='<div class="row">'+
|
||||
'<div class="col-xs-8">'+
|
||||
'<input type="text" placeholder="'+defaultValue+'" class="form-control ng-pristine ng-invalid-required ng-invalid final" required="" readonly>'+
|
||||
'</div></div>';
|
||||
}
|
||||
if(question.type === "textarea"){
|
||||
defaultValue = (question.default) ? question.default : (question.default_textarea) ? question.default_textarea: "" ;
|
||||
html+='<div class="row">'+
|
||||
'<div class="col-xs-8">'+
|
||||
'<textarea class="form-control ng-pristine ng-invalid-required ng-invalid final" required="" rows="3" readonly>'+defaultValue+'</textarea>'+
|
||||
@ -321,7 +323,7 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
|
||||
if(question.type === 'multiplechoice' || question.type === "multiselect"){
|
||||
choices = question.choices.split(/\n/);
|
||||
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++){
|
||||
checked = (!Empty(question.default) && question.default.indexOf(choices[i])!==-1) ? "checked" : "";
|
||||
html+='<label class="'+element+'-inline final">'+
|
||||
@ -330,13 +332,23 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
|
||||
}
|
||||
|
||||
}
|
||||
if(question.type === 'integer' || question.type === "float"){
|
||||
min = (question.min) ? question.min : "";
|
||||
max = (question.max) ? question.max : "" ;
|
||||
numberValidation = (question.type==="integer") ? "integer" : 'float';
|
||||
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+='<div class="row">'+
|
||||
'<div class="col-xs-8">'+
|
||||
'<input type="number" class="final" name="'+question.variable+'" min="'+min+'" max="'+max+'" value="'+defaultValue+'" readonly '+numberValidation+'>'+
|
||||
'<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>';
|
||||
|
||||
}
|
||||
@ -462,7 +474,7 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
|
||||
|
||||
var scope = params.scope,
|
||||
index = params.index,
|
||||
element, fld, i,
|
||||
element, fld, i, pre,
|
||||
form = SurveyQuestionForm;
|
||||
|
||||
$('#add_question_btn').hide();
|
||||
@ -473,9 +485,12 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
|
||||
// $('#new_question .aw-form-well').remove();
|
||||
GenerateForm.inject(form, { id: 'question_'+index, mode: 'edit' , related: false, scope:scope, breadCrumbs: false});
|
||||
for(fld in form.fields){
|
||||
if( fld === 'answer_options_number'){
|
||||
$('#answer_min').val(scope.survey_questions[index].min);
|
||||
$('#answer_max').val(scope.survey_questions[index].max);
|
||||
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( fld === 'default_int' || fld === 'default_float'){
|
||||
$("#"+fld ).val(scope.survey_questions[index].default);
|
||||
@ -554,9 +569,13 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
|
||||
});
|
||||
};
|
||||
scope.addQuestion = function(){
|
||||
|
||||
GenerateForm.inject(form, { id:'new_question', mode: 'add' , scope:scope, related: false, breadCrumbs: false});
|
||||
scope.required = true; //set the required checkbox to true via the ngmodel attached to scope.required.
|
||||
|
||||
scope.int_min = null;
|
||||
scope.int_max = null;
|
||||
scope.float_min = null;
|
||||
scope.float_max = null;
|
||||
};
|
||||
|
||||
scope.addNewQuestion = function(){
|
||||
@ -673,9 +692,9 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
|
||||
scope.submitQuestion = function(){
|
||||
var form = SurveyQuestionForm,
|
||||
data = {},
|
||||
labels={},
|
||||
min= "min",
|
||||
max = "max",
|
||||
// labels={},
|
||||
// min= "min",
|
||||
// max = "max",
|
||||
fld, key, elementID;
|
||||
//generator.clearApiErrors();
|
||||
Wait('start');
|
||||
@ -688,40 +707,25 @@ 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==="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;
|
||||
data.min = scope.float_min;
|
||||
data.max = scope.float_max;
|
||||
data.default = 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;
|
||||
data.min = scope.int_min;
|
||||
data.max = scope.int_max;
|
||||
data.default = 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;
|
||||
|
||||
}
|
||||
}
|
||||
Wait('stop');
|
||||
|
||||
@ -141,6 +141,25 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Job
|
||||
};
|
||||
}])
|
||||
|
||||
|
||||
.directive('smartFloat', function() {
|
||||
var FLOAT_REGEXP = /^\-?\d+((\.|\,)\d+)?$/;
|
||||
return {
|
||||
require: 'ngModel',
|
||||
link: function(scope, elm, attrs, ctrl) {
|
||||
ctrl.$parsers.unshift(function(viewValue) {
|
||||
if (FLOAT_REGEXP.test(viewValue)) {
|
||||
ctrl.$setValidity('float', true);
|
||||
return parseFloat(viewValue.replace(',', '.'));
|
||||
} else {
|
||||
ctrl.$setValidity('float', false);
|
||||
return undefined;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
})
|
||||
|
||||
// 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.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user