Skip to content
This repository has been archived by the owner on Aug 21, 2018. It is now read-only.

Commit

Permalink
[#870] Survey question csv (#878)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rupesh87 authored and lmmrssa committed Jun 19, 2017
1 parent 0e5e642 commit 86da250
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
46 changes: 25 additions & 21 deletions app/nation/app/Router.js
Original file line number Diff line number Diff line change
Expand Up @@ -2893,6 +2893,7 @@ $(function() {
App.$el.children('.body').html('<div class="directionsAndFloat" style="margin-top:10px"><h6 style="float:left;">'+App.languageDictValue.get('Survey_Number') + ' '+ surveyModel.get('SurveyNo') + '</h6> <button id = "addQuestion" class="btn btn-success" style="float:left;margin-left:20px;margin-bottom:10px;">Add Question</button><button class="btn btn-info" style="float:left;margin-left:20px" onclick="selectCriteria(\'' + surveyId + '\')">Send by criteria</button><button class="btn btn-info" style="float:left;margin-left:20px" onclick="communitiesList(\'' + surveyId + '\')">Send to bell members</button></div> <div id="dialog" style="display: none"> <span class="subtitle">Select a Question</span> <br /> <select id="add_new_question" class="surTextArea"> <option value="1" selected="selected">Multiple Choice (Single Answer)</option> <option value="5">Rating Scale</option> <option value="6">Single Textbox</option> <option value="8">Comment/Essay Box</option> </select><div id="1"> <span class="subtitle2">Question Text</span> <br /> <textarea cols="50" rows="6" id="question_text" name="question_text" class="surTextArea"></textarea> <br /> <span class="subtitle2">Answer Choices (each choice on a separate line)</span> <br /> <textarea cols="50" rows="5" id="answer_choices" name="answer_choices" class="surTextArea"></textarea> <br /> <span class="subtitle2">&nbsp;</span> <br /> <input type="checkbox" value="1" name="required" id="required_question"> <label id="require-surCheckBox" >Require Answer to Question.</label> <br /> <div align="center"> <br /> <input type="submit" value="Save Question" class="default_btn saveQuestionButton saveSurQuestion"> </div> </div><div id="6"> <span class="subtitle2">Question Text</span> <br /> <textarea cols="50" rows="6" id="question_text" name="question_text" class="surTextArea"></textarea> <br /> <input type="checkbox" value="1" name="required" id="required_question"> <label id="require-surCheckBox" >Require Answer to Question.</label><br /> <div align="center"> <br /> <input type="submit" value="Save Question" class="default_btn saveQuestionButton saveSurQuestion"> </div> </div><div id="8"> <span class="subtitle2">Question Text</span> <br /> <textarea cols="50" rows="6" id="question_text" name="question_text" class="surTextArea"></textarea> <br /> <input type="checkbox" value="1" name="required" id="required_question"> <label id="require-surCheckBox" >Require Answer to Question.</label><br /> <div align="center"> <br /> <input type="submit" value="Save Question" class="default_btn saveQuestionButton saveSurQuestion"> </div> </div><div id="5"> <span class="subtitle2">Question Text</span> <br /> <textarea cols="50" rows="6" id="question_text" name="question_text" class="surTextArea"></textarea> <br /> <span class="subtitle2">Answer Choices (each choice on a separate line)</span> <br /> <textarea cols="50" rows="5" id="answer_choices" name="answer_choices" class="surTextArea"></textarea> <br /> <span class="subtitle2">Column Choices</span> <br /><label id="select-ratings" >Select the number of ratings:</label> <br><select onchange="display(this.value);" name="rating_count" class="surTextArea" id="select_rating"><option value="2">2 ratings</option><option value="3">3 ratings</option><option value="4" selected="">4 ratings</option><option value="5">5 ratings</option><option value="6">6 ratings</option><option value="7">7 ratings</option><option value="8">8 ratings</option><option value="9">9 ratings</option></select><br><span id="rating1" name="rating1"><b>Label:</b> <input type="text" name="rating1_label" class="textBoxesOnSurvey ratingLabels"> <b>Weight:</b> <input type="text" value="1" size="3" name="rating1_weight" class="textBoxesOnSurvey" disabled="true"><br></span><span id="rating2" name="rating2"><b>Label:</b> <input type="text" name="rating2_label" class="textBoxesOnSurvey ratingLabels"> <b>Weight:</b> <input type="text" value="2" size="3" name="rating2_weight" class="textBoxesOnSurvey" disabled="true"><br></span><span id="rating3" name="rating3"><b>Label:</b> <input type="text" name="rating3_label" class="textBoxesOnSurvey ratingLabels"> <b>Weight:</b> <input type="text" value="3" size="3" name="rating3_weight" class="textBoxesOnSurvey" disabled="true"><br></span><span id="rating4" name="rating4"><b>Label:</b> <input type="text" name="rating4_label" class="textBoxesOnSurvey ratingLabels"> <b>Weight:</b> <input type="text" value="4" size="3" name="rating4_weight" class="textBoxesOnSurvey" disabled="true"><br></span><span style="display:none;" id="rating5" name="rating5"><b>Label:</b> <input type="text" name="rating5_label" class="textBoxesOnSurvey ratingLabels"> <b>Weight:</b> <input type="text" value="5" size="3" name="rating5_weight" class="textBoxesOnSurvey" disabled="true"><br></span><span style="display:none;" id="rating6" name="rating6"><b>Label:</b> <input type="text" name="rating6_label" class="textBoxesOnSurvey ratingLabels"> <b>Weight:</b> <input type="text" value="6" size="3" name="rating6_weight" class="textBoxesOnSurvey" disabled="true"><br></span> <span style="display:none;" id="rating7" name="rating7"><b>Label:</b> <input type="text" name="rating7_label" class="textBoxesOnSurvey ratingLabels"> <b>Weight:</b> <input type="text" value="7" size="3" name="rating7_weight" class="textBoxesOnSurvey" disabled="true"><br></span> <span style="display:none;" id="rating8" name="rating8"><b>Label:</b> <input type="text" name="rating8_label" class="textBoxesOnSurvey ratingLabels"> <b>Weight:</b> <input type="text" value="8" size="3" name="rating8_weight" class="textBoxesOnSurvey" disabled="true"><br></span> <span style="display:none;" id="rating9" name="rating9"><b>Label:</b> <input type="text" name="rating9_label" class="textBoxesOnSurvey ratingLabels"> <b>Weight:</b> <input type="text" value="9" size="3" name="rating9_weight" class="textBoxesOnSurvey" disabled="true"><br></span><script> function display(val) { if (val == "2") { document.getElementById("rating1").style.display = ""; document.getElementById("rating2").style.display = ""; document.getElementById("rating3").style.display = "none"; document.getElementById("rating4").style.display = "none"; document.getElementById("rating5").style.display = "none"; document.getElementById("rating6").style.display = "none"; document.getElementById("rating7").style.display = "none"; document.getElementById("rating8").style.display = "none"; document.getElementById("rating9").style.display = "none"; } else if (val == "3") { document.getElementById("rating1").style.display = ""; document.getElementById("rating2").style.display = ""; document.getElementById("rating3").style.display = ""; document.getElementById("rating4").style.display = "none"; document.getElementById("rating5").style.display = "none"; document.getElementById("rating6").style.display = "none"; document.getElementById("rating7").style.display = "none"; document.getElementById("rating8").style.display = "none"; document.getElementById("rating9").style.display = "none"; } else if (val == "4") { document.getElementById("rating1").style.display = ""; document.getElementById("rating2").style.display = ""; document.getElementById("rating3").style.display = ""; document.getElementById("rating4").style.display = ""; document.getElementById("rating5").style.display = "none"; document.getElementById("rating6").style.display = "none"; document.getElementById("rating7").style.display = "none"; document.getElementById("rating8").style.display = "none"; document.getElementById("rating9").style.display = "none"; } else if (val == "5") { document.getElementById("rating1").style.display = ""; document.getElementById("rating2").style.display = ""; document.getElementById("rating3").style.display = ""; document.getElementById("rating4").style.display = ""; document.getElementById("rating5").style.display = ""; document.getElementById("rating6").style.display = "none"; document.getElementById("rating7").style.display = "none"; document.getElementById("rating8").style.display = "none"; document.getElementById("rating9").style.display = "none"; } else if (val == "6") { document.getElementById("rating1").style.display = ""; document.getElementById("rating2").style.display = ""; document.getElementById("rating3").style.display = ""; document.getElementById("rating4").style.display = ""; document.getElementById("rating5").style.display = ""; document.getElementById("rating6").style.display = ""; document.getElementById("rating7").style.display = "none"; document.getElementById("rating8").style.display = "none"; document.getElementById("rating9").style.display = "none"; } else if (val == "7") { document.getElementById("rating1").style.display = ""; document.getElementById("rating2").style.display = ""; document.getElementById("rating3").style.display = ""; document.getElementById("rating4").style.display = ""; document.getElementById("rating5").style.display = ""; document.getElementById("rating6").style.display = ""; document.getElementById("rating7").style.display = ""; document.getElementById("rating8").style.display = "none"; document.getElementById("rating9").style.display = "none"; } else if (val == "8") { document.getElementById("rating1").style.display = ""; document.getElementById("rating2").style.display = ""; document.getElementById("rating3").style.display = ""; document.getElementById("rating4").style.display = ""; document.getElementById("rating5").style.display = ""; document.getElementById("rating6").style.display = ""; document.getElementById("rating7").style.display = ""; document.getElementById("rating8").style.display = ""; document.getElementById("rating9").style.display = "none"; } else if (val == "9") { document.getElementById("rating1").style.display = ""; document.getElementById("rating2").style.display = ""; document.getElementById("rating3").style.display = ""; document.getElementById("rating4").style.display = ""; document.getElementById("rating5").style.display = ""; document.getElementById("rating6").style.display = ""; document.getElementById("rating7").style.display = ""; document.getElementById("rating8").style.display = ""; document.getElementById("rating9").style.display = ""; } } </script> <span class="subtitle2">&nbsp;</span> <br /><span class="subtitle2">&nbsp;</span> <br /> <input type="checkbox" value="1" name="required" id="required_question"><label id="require-surCheckBox" >Require Answer to Question.</label> <br /> <div align="center"> <br /> <input type="submit" value="Save Question" class="default_btn saveQuestionButton saveSurQuestion"> </div></div></div>')
$('#addQuestion').text(App.languageDictValue.get('Add_Question'));
$('#sendSurveyBtn').text(App.languageDictValue.get('Send_to_communities'));
$('.directionsAndFloat').append("<a class='btn btn-info' style='margin-left: 10px;' onclick=App.Router.downloadCommunitySurveys('" + surveyModel.get('SurveyNo') + "," + surveyModel.get('SurveyTitle') + "','')>" +App.languageDictValue.attributes.Download+"</a>")
$(function () {
var originalContent;
$("#dialog").dialog({
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions app/nation/app/views/SurveyQuestionRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
},
Expand Down
3 changes: 2 additions & 1 deletion app/nation/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ <h3><%= languageDict.attributes.viplinks %></h3><br/><br/>
<a href="#surveydetail/<%= _id %>" class="btn btn-warning">
<%= languageDict.attributes.Details %>
</a>
<a class='btn btn-info' onclick="App.Router.downloadCommunitySurveys('<%= SurveyNo %>', '<%= SurveyTitle %>')">
<a class='btn btn-info' onclick="App.Router.downloadCommunitySurveys('<%= SurveyNo %>', '<%= SurveyTitle %>','')">
<%= languageDict.attributes.Download %>
</a>
<a class='btn btn-danger destroy'>
Expand Down Expand Up @@ -703,6 +703,7 @@ <h3><%= languageDict.attributes.viplinks %></h3><br/><br/>
<a class='resFeedBack btn btn-success edit_survey_question'>
<i class='icon-eye-open icon-white'></i> <%= languageDict.attributes.EditLabel %>
</a>
<a class='btn btn-info' onclick="App.Router.downloadCommunitySurveys('<%= surveyNo %>', '<%=surveyTitle %>','<%=_id %>')"> <%= languageDict.attributes.Download %><a>
<a class='btn btn-danger destroy'>
<i class='icon-remove icon-white'></i> <%= languageDict.attributes.Remove %>
</a>
Expand Down

0 comments on commit 86da250

Please sign in to comment.