From 34230c570c48e9b79bb044c47d9098b84141f577 Mon Sep 17 00:00:00 2001 From: MikeTschudi Date: Mon, 11 Apr 2016 11:58:31 -0700 Subject: [PATCH] Pulled survey out of main --- js/app/main.js | 113 +++---------------------------------- js/app/survey.js | 141 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+), 106 deletions(-) create mode 100644 js/app/survey.js diff --git a/js/app/main.js b/js/app/main.js index 97e50ef..f67ead8 100644 --- a/js/app/main.js +++ b/js/app/main.js @@ -16,8 +16,8 @@ | limitations under the License. */ //============================================================================================================================// -define(['lib/i18n.min!nls/resources.js', 'prepareAppConfigInfo', 'handleUserSignin', 'dataAccess', 'diag'], - function (i18n, prepareAppConfigInfo, handleUserSignin, dataAccess, diag) { +define(['lib/i18n.min!nls/resources.js', 'prepareAppConfigInfo', 'handleUserSignin', 'dataAccess', 'survey', 'diag'], + function (i18n, prepareAppConfigInfo, handleUserSignin, dataAccess, survey, diag) { 'use strict'; var main, unsupported = false, needProxy = false, proxyReady; @@ -318,76 +318,6 @@ define(['lib/i18n.min!nls/resources.js', 'prepareAppConfigInfo', 'handleUserSign } }, - startQuestion: function (ignore, iQuestion, questionInfo) { - //
- //
- var start = - "
" - + "
"; - return start; - }, - - createButtonChoice: function (ignore, iQuestion, questionInfo, isReadOnly) { - //
- // - // - // - //
- var buttons = "
"; - var domain = questionInfo.domain.split('|'); - $.each(domain, function (i, choice) { - buttons += ""; - }); - buttons += "
"; - return buttons; - }, - - createListChoice: function (ignore, iQuestion, questionInfo, isReadOnly) { - //
- //
- //
- //
- //
- var list = ""; - var domain = questionInfo.domain.split('|'); - $.each(domain, function (i, choice) { - list += "
"; - }); - return list; - }, - - wrapupQuestion: function () { - //
- //
- var wrap = "
"; - return wrap; - }, - - addQuestion: function (surveyContainer, iQuestion, questionInfo, isReadOnly) { - var question = main.startQuestion(surveyContainer, iQuestion, questionInfo); - if (questionInfo.style === "button") { - question += main.createButtonChoice(surveyContainer, iQuestion, questionInfo, isReadOnly); - } else { - question += main.createListChoice(surveyContainer, iQuestion, questionInfo, isReadOnly); - } - question += main.wrapupQuestion(surveyContainer, iQuestion, questionInfo); - $(surveyContainer).append(question); - - // Fix radio-button toggling - if (questionInfo.style === "button") { - $('#q' + iQuestion + ' button').click(function (evt) { - $(evt.currentTarget).addClass('active').siblings().removeClass('active'); - }); - } - }, - addPhoto: function (carouselSlidesHolder, indexInArray, isActive, photoUrl) { //
VIRB0125.JPG
// var content = "
= 0) { main.candidate.obj.attributes[prepareAppConfigInfo.appParams.bestPhotoField] = main.candidate.attachments[main.iSelectedPhoto].id; diff --git a/js/app/survey.js b/js/app/survey.js new file mode 100644 index 0000000..ea035da --- /dev/null +++ b/js/app/survey.js @@ -0,0 +1,141 @@ +/*global define,$,window */ +/*jslint browser:true */ +/** @license + | Copyright 2015 Esri + | + | Licensed under the Apache License, Version 2.0 (the "License"); + | you may not use this file except in compliance with the License. + | You may obtain a copy of the License at + | + | http://www.apache.org/licenses/LICENSE-2.0 + | + | Unless required by applicable law or agreed to in writing, software + | distributed under the License is distributed on an "AS IS" BASIS, + | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + | See the License for the specific language governing permissions and + | limitations under the License. + */ +//============================================================================================================================// +define(['lib/i18n.min!nls/resources.js'], function (i18n) { + 'use strict'; + var survey; + survey = { + + //--------------------------------------------------------------------------------------------------------------------// + + startQuestion: function (ignore, iQuestion, questionInfo) { + //
+ //
+ var start = + "
" + + "
"; + return start; + }, + + createButtonChoice: function (ignore, iQuestion, questionInfo, isReadOnly) { + //
+ // + // + // + //
+ var buttons = "
"; + var domain = questionInfo.domain.split('|'); + $.each(domain, function (i, choice) { + buttons += ""; + }); + buttons += "
"; + return buttons; + }, + + createListChoice: function (ignore, iQuestion, questionInfo, isReadOnly) { + //
+ //
+ //
+ //
+ //
+ var list = ""; + var domain = questionInfo.domain.split('|'); + $.each(domain, function (i, choice) { + list += "
"; + }); + return list; + }, + + wrapupQuestion: function () { + //
+ //
+ var wrap = "
"; + return wrap; + }, + + addQuestion: function (surveyContainer, iQuestion, questionInfo, isReadOnly) { + var question = survey.startQuestion(surveyContainer, iQuestion, questionInfo); + if (questionInfo.style === "button") { + question += survey.createButtonChoice(surveyContainer, iQuestion, questionInfo, isReadOnly); + } else { + question += survey.createListChoice(surveyContainer, iQuestion, questionInfo, isReadOnly); + } + question += survey.wrapupQuestion(surveyContainer, iQuestion, questionInfo); + $(surveyContainer).append(question); + + // Fix radio-button toggling + if (questionInfo.style === "button") { + $('#q' + iQuestion + ' button').click(function (evt) { + $(evt.currentTarget).addClass('active').siblings().removeClass('active'); + }); + } + }, + + create: function (surveyContainer, surveyDefinition, isReadOnly) { + // Remove children and their events + $(surveyContainer).children().remove(); + + // Create the questions + $.each(surveyDefinition, function (indexInArray, questionInfo) { + survey.addQuestion(surveyContainer, indexInArray, questionInfo, isReadOnly); + }); + + // Render any radiobutton groups + $(".btn-group").trigger('create'); + }, + + validate: function (surveyContainer, surveyDefinition, objAttributes) { + var iQuestionResult, firstMissing; + + $.each(surveyDefinition, function (iQuestion, questionInfo) { + if (questionInfo.style === "button") { + iQuestionResult = $('#q' + iQuestion + ' .active', surveyContainer).val(); + } else { + iQuestionResult = $('input[name=q' + iQuestion + ']:checked', surveyContainer).val(); + } + if (iQuestionResult) { + objAttributes[questionInfo.field] = questionInfo.domain.split("|")[iQuestionResult]; + } + + // Flag missing importants + if (questionInfo.important) { + if (iQuestionResult) { + $("#qg" + iQuestion).removeClass("flag-error"); + } else { + $("#qg" + iQuestion).addClass("flag-error"); + if (firstMissing === undefined) { + firstMissing = $("#qg" + iQuestion)[0]; + } + } + } + }); + + // Return the first missing important (if any) + return firstMissing; + } + + }; + return survey; +});