From 86da2506e7a9fa91e4db23d5dd55ae950cd80496 Mon Sep 17 00:00:00 2001 From: Rupesh Manandhar Date: Fri, 16 Jun 2017 15:50:12 +0545 Subject: [PATCH] [#870] Survey question csv (#878) --- app/nation/app/Router.js | 46 ++++++++++++----------- app/nation/app/views/SurveyQuestionRow.js | 8 ++++ app/nation/index.html | 3 +- 3 files changed, 35 insertions(+), 22 deletions(-) diff --git a/app/nation/app/Router.js b/app/nation/app/Router.js index 620e56b54..1c9cd93cf 100644 --- a/app/nation/app/Router.js +++ b/app/nation/app/Router.js @@ -2893,6 +2893,7 @@ $(function() { App.$el.children('.body').html('
'+App.languageDictValue.get('Survey_Number') + ' '+ surveyModel.get('SurveyNo') + '
') $('#addQuestion').text(App.languageDictValue.get('Add_Question')); $('#sendSurveyBtn').text(App.languageDictValue.get('Send_to_communities')); + $('.directionsAndFloat').append("" +App.languageDictValue.attributes.Download+"") $(function () { var originalContent; $("#dialog").dialog({ @@ -3237,7 +3238,7 @@ $(function() { }); }, - downloadCommunitySurveys: function (surveyNo, surTitle) { + downloadCommunitySurveys: function (surveyNo, surTitle, questionId) { var that = this; $.ajax({ url:'/surveyresponse/_design/bell/_view/surveyResBySurveyNo?include_docs=true', @@ -3275,40 +3276,43 @@ $(function() { async: false }); var answerModels = answersColl.models; + console.log(answerModels.attributes) var answersArray = []; for(var k = 0 ; k < answerModels.length ; k++) { answersArray.push(answerModels[k].attributes); } for(var x = 0 ; x < answersArray.length ; x++) { - if(answersArray[x].Answer.length > 0) { - if(answersArray[x].Type == 'Rating Scale') { - for(var y = 0 ; y < answersArray[x].Options.length ; y++) { + if(questionId == '' || (questionId && ( surveyResModels[j].questions[x] == questionId))){ + if(answersArray[x].Answer.length > 0) { + if(answersArray[x].Type == 'Rating Scale') { + for(var y = 0 ; y < answersArray[x].Options.length ; y++) { + var JSONObj = {"Community":"", "Gender":"", "BirthYear":"", "Language":"", "QType":"", "QStatement":"", "Options":[], "Answer":[]}; + JSONObj.Community = commName; + JSONObj.Gender = gender; + JSONObj.BirthYear = birthYear; + JSONObj.Language = memberLanguage; + JSONObj.QType = answersArray[x].Type; + JSONObj.QStatement = answersArray[x].Statement + '--' + answersArray[x].Options[y]; + JSONObj.Options = answersArray[x].Ratings; + if(answersArray[x].Answer[y] != undefined) { + JSONObj.Answer = answersArray[x].Answer[y]; + } + jsonObjectsData.push(JSONObj) + } + } else { var JSONObj = {"Community":"", "Gender":"", "BirthYear":"", "Language":"", "QType":"", "QStatement":"", "Options":[], "Answer":[]}; JSONObj.Community = commName; JSONObj.Gender = gender; JSONObj.BirthYear = birthYear; JSONObj.Language = memberLanguage; JSONObj.QType = answersArray[x].Type; - JSONObj.QStatement = answersArray[x].Statement + '--' + answersArray[x].Options[y]; - JSONObj.Options = answersArray[x].Ratings; - if(answersArray[x].Answer[y] != undefined) { - JSONObj.Answer = answersArray[x].Answer[y]; + JSONObj.QStatement = answersArray[x].Statement; + if(answersArray[x].Options){ + JSONObj.Options = answersArray[x].Options; } + JSONObj.Answer = answersArray[x].Answer; jsonObjectsData.push(JSONObj) } - } else { - var JSONObj = {"Community":"", "Gender":"", "BirthYear":"", "Language":"", "QType":"", "QStatement":"", "Options":[], "Answer":[]}; - JSONObj.Community = commName; - JSONObj.Gender = gender; - JSONObj.BirthYear = birthYear; - JSONObj.Language = memberLanguage; - JSONObj.QType = answersArray[x].Type; - JSONObj.QStatement = answersArray[x].Statement; - if(answersArray[x].Options){ - JSONObj.Options = answersArray[x].Options; - } - JSONObj.Answer = answersArray[x].Answer; - jsonObjectsData.push(JSONObj) } } } diff --git a/app/nation/app/views/SurveyQuestionRow.js b/app/nation/app/views/SurveyQuestionRow.js index 38877cad8..a896c0bc7 100644 --- a/app/nation/app/views/SurveyQuestionRow.js +++ b/app/nation/app/views/SurveyQuestionRow.js @@ -46,6 +46,14 @@ $(function() { render: function() { var vars = this.model.toJSON(); + var surveyObject = new App.Models.Survey({ + _id: this.Id + }) + surveyObject.fetch({ + async: false + }) + vars.surveyNo = surveyObject.get('SurveyNo') + vars.surveyTitle = surveyObject.get('SurveyTitle') vars.languageDict=App.languageDictValue; this.$el.append(this.template(vars)) }, diff --git a/app/nation/index.html b/app/nation/index.html index 70f29c9a8..77c5fe428 100644 --- a/app/nation/index.html +++ b/app/nation/index.html @@ -645,7 +645,7 @@

<%= languageDict.attributes.viplinks %>



<%= languageDict.attributes.Details %> - + <%= languageDict.attributes.Download %> @@ -703,6 +703,7 @@

<%= languageDict.attributes.viplinks %>



<%= languageDict.attributes.EditLabel %> + <%= languageDict.attributes.Download %> <%= languageDict.attributes.Remove %>