Files
Last update 4 months 3 weeks
by
Arnaud-Apu-Fanovard
surveylogicinstance.min.js.téléchargementwindow.lpTag=window.lpTag||{};lpTag.taglets=lpTag.taglets||{};lpTag.taglets.SurveyLogic=lpTag.taglets.SurveyLogic||function(e){if(!e.survey||"object"!=typeof e.survey||this===window)return!1;this.survey=e.survey.survey||e.survey;this.createQuestionsMap();this.defaultSelectValue=e.defaultSelectValue||"";this.header=this.survey.header||""};!function(e){var t="prototype";e[t].questionTypes={TEXTF:"Text Field",TEXT:"Text Area",SELECT:"Dropdown Box",RADIO:"Radio Button",RADIOH:"Radio Button (side by side)",CHECKBOX:"Checkbox",CSAT:"CSAT"};e[t].validationTypes={EMAIL:"email",NUMBER:"numeric",STRING:"alpha_numeric",CSAT:"csat",PHONE:"phoneNumber"};e[t].errorTypes={EMAIL:"email",NUMBER:"numeric",ILLEGAL_CHARS:"illegal_chars",REQUIRED:"required",CSAT_RANGE:"csat_range",LENGTH:"length",PHONE:"phoneNumber"};e[t].questionsText={MAX_LENGTH:2e3};e[t].csatRange={lowest:0,highest:5};e[t].getAllQuestions=function(){return this.survey&&this.survey.questions&&this.survey.questions.question&&this.survey.questions.question.constructor===Array?this.survey.questions.question:[]};e[t].createQuestionsMap=function(){this.questionLogicMap={};this.questionIdMap={};this.mandatoryQuestions=[];for(var e=this.getAllQuestions(),t=0;t<e.length;t++){e[t].id=0===e[t].id?t+1e3:e[t].id;void 0!==e[t].logicId&&(this.questionLogicMap[e[t].logicId]={arrayLocation:""+t});void 0!==e[t].id&&(this.questionIdMap[e[t].id]={arrayLocation:""+t});e[t].mandatory&&!0===e[t].mandatory&&this.mandatoryQuestions.push(t)}};e[t].getQuestionByLogicId=function(e){return this.getQuestionByMap(e,this.questionLogicMap)};e[t].getQuestionById=function(e){return this.getQuestionByMap(e,this.questionIdMap)};e[t].getQuestionByIndex=function(e){var t={};t[e]={arrayLocation:e};return this.getQuestionByMap(e,t)};e[t].getQuestionAnswersById=function(e){e=this.getQuestionById(e);return this.getQuestionAnswers(e)};e[t].getQuestionAnswersByLogicId=function(e){e=this.getQuestionByLogicId(e);return this.getQuestionAnswers(e)};e[t].getQuestionAnswersByIndex=function(e){e=this.getQuestionByIndex(e);return this.getQuestionAnswers(e)};e[t].getQuestionAnswers=function(e){var t=[];if(e.entry)for(var s=0;s<e.entry.length;s++)e.entry[s].checked&&t.push(e.entry[s].value);else e.lastKnownValue&&t.push(e.lastKnownValue);return t};e[t].getQuestionByMap=function(e,t){var s=this.getAllQuestions(),n=-1;try{n=Number(t[e].arrayLocation)}catch(e){}return-1<n&&s.length>n?s[n]:{}};e[t].submitAnswerGetNextQuestions=function(e,t){this.submitAnswer(e,t);return this.getActiveQuestions({getExcluded:!0})};e[t].getActiveQuestions=function(e){for(var t=this.getAllQuestions(),s={},n=[],i=[],r=!1,o=!(!e||!e.getExcluded)&&e.getExcluded,a=!(!e||!e.mandatoryOnly)&&e.mandatoryOnly,u=0;u<t.length;u++){if(!0!==s[u]){a&&!0!==t[u].mandatory||n.push(t[u]);r=!1}else{i.push(t[u]);r=!0}switch(t[u].type){case this.questionTypes.CHECKBOX:case this.questionTypes.SELECT:case this.questionTypes.RADIO:case this.questionTypes.RADIOH:s=this.getExcludedIndexes(t[u],s,r)}}return n=o?{questionsToShow:n,questionIdsToHide:i}:n};e[t].getActiveQuestionsIds=function(){for(var e=this.getActiveQuestions(),t=[],s=0;s<e.length;s++)t.push(e[s].id);return t};e[t].getExcludedIndexes=function(e,t,s){if(!e.entry)return!1;for(var n=0;n<e.entry.length;n++)if("boolean"==typeof e.entry[n].checked&&(!e.entry[n].checked||s)&&e.entry[n].logic&&e.entry[n].logic.showLogicId)for(var i=e.entry[n].logic.showLogicId.constructor===Array?e.entry[n].logic.showLogicId:[e.entry[n].logic.showLogicId],r=0;r<i.length;r++)this.questionLogicMap[i[r]]&&(t[this.questionLogicMap[i[r]].arrayLocation]=!0);return t};e[t].submitAnswer=function(e,t){var s=this.getQuestionById(e);if(s.type===this.questionTypes.CSAT)this.submitCSATAnswer(s,t);else if(s.entry){t=t.constructor===Array?t:[t];for(var n=0;n<s.entry.length;n++){s.entry[n].checked=!1;for(var i=0;i<t.length;i++)t[i]===s.entry[n].value&&(s.entry[n].checked=!0)}}else this.submitTextAnswer(s,t)};e[t].submitTextAnswer=function(e,t){e="object"==typeof e?e:this.getQuestionById(e);if(e.type===this.questionTypes.TEXTF||e.type===this.questionTypes.TEXT){t=t.replace(/\s\s*$/,"");e.lastKnownValue=String(t)}};e[t].submitCSATAnswer=function(e,t){e="object"==typeof e?e:this.getQuestionById(e);e.lastKnownValue=e.csat_rate=String(t)};e[t].getJSONSurvey=function(){var e={survey:{id:this.survey.id||"",question:[]}},t=this.getActiveQuestions();try{for(var s=0;s<t.length;s++){var n=this.createQuestionJSON(t[s]);("string"==typeof n.answer||0<n.answer.length)&&e.survey.question.push(n)}}catch(e){}return e};e[t].createQuestionJSON=function(e){var t={id:e.id,answer:[]};if(e.entry)for(var s=0;s<e.entry.length;s++)!0===e.entry[s].checked&&t.answer.push(e.entry[s].value);else e.lastKnownValue&&(t.answer=e.lastKnownValue);return t};e[t].getXMLSurvey=function(){for(var e='<survey id="'+this.survey.id+'" >',t=this.getActiveQuestions(),s=0;s<t.length;s++){var n=this.createQuestionXML(t[s]);n.hasAnswer&&(e+=n.XML)}return e+="</survey>"};e[t].createQuestionXML=function(e){var t=!1,s='<question id="'+e.id+'" >';if(e.entry){for(var n=0;n<e.entry.length;n++)if(!0===e.entry[n].checked){s+="<answer>"+e.entry[n].value+"</answer>";t=!0}}else if(e.lastKnownValue){s+="<answer>"+e.lastKnownValue+"</answer>";t=!0}return{XML:s+="</question>",hasAnswer:t}};e[t].validateSurvey=function(e){var t={surveyValid:!0,questionsNeeded:[]},s=this.getActiveQuestions({mandatoryOnly:!e||"boolean"!=typeof e||!e});try{for(var n=0;n<s.length;n++)if(!this.validateQuestion(s[n])){t.surveyValid=!1;t.questionsNeeded.push(s[n])}}catch(e){}return t};e[t].validateQuestion=function(e){return e.entry?this.validateMultiOptionQuestion(e):e.type===this.questionTypes.CSAT?this.validateCSATQuestion(e):this.validateTextQuestion(e)};e[t].validateMultiOptionQuestion=function(e){for(var t=!1,s=0;s<e.entry.length;s++)if(!0===e.entry[s].checked){t=!0;break}if(e.mandatory&&!t)e.error=this.errorTypes.REQUIRED;else{e.error=null;delete e.error;t=!0}return t};e[t].validateTextQuestion=function(e){var t=!0;if(""!==e.lastKnownValue)switch(e.validationType){case this.validationTypes.EMAIL:(t=this.isValidEmail(e.lastKnownValue))||(e.error=this.errorTypes.EMAIL);break;case this.validationTypes.NUMBER:(t=this.isNumber(e.lastKnownValue))||(e.error=this.errorTypes.NUMBER);break;case this.validationTypes.PHONE:(t=this.isValidPhoneNumber(e.lastKnownValue))||(e.error=this.errorTypes.PHONE);break;default:case this.validationTypes.STRING:(t=this.isString(e.lastKnownValue)&&this.isValidChars(e.lastKnownValue))?(t=this.isValidLength(e.lastKnownValue))||(e.error=this.errorTypes.LENGTH):e.error=this.errorTypes.ILLEGAL_CHARS}if(!e.mandatory||e.lastKnownValue&&""!==e.lastKnownValue){if(t){e.error=null;delete e.error}}else{e.error=this.errorTypes.REQUIRED;t=!1}return t};e[t].validateCSATQuestion=function(e){void 0===e.csat_rate&&(e.csat_rate=0);var t=this.isNumber(e.csat_rate)&&this.isInCSATRange(+e.csat_rate);t||(e.error=this.errorTypes.CSAT_RANGE);return t};e[t].isInCSATRange=function(e){return e>=this.csatRange.lowest&&e<=this.csatRange.highest};e[t].isValidChars=function(e){return e.search(/<|>|\"/)<0};e[t].isValidEmail=function(e){try{return new RegExp(/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/).test(e)}catch(e){return!1}};e[t].isValidPhoneNumber=function(e){try{return new RegExp(/^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\.\/0-9]*$/g).test(e)}catch(e){return!1}};e[t].isNumber=function(e){return!isNaN(e)};e[t].isString=function(e){return"string"==typeof e};e[t].isValidLength=function(e){return e.length<=this.questionsText.MAX_LENGTH};e[t].dispose=function(){for(var e in this)if(this.hasOwnProperty(e)){this[e]=null;delete this[e]}}}(lpTag.taglets.SurveyLogic);