From 8072d1eb3eb5b93d673491b8c3a5e6b2cd3abe0a Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Mon, 14 Jan 2019 20:48:03 +0100 Subject: [PATCH] Display surveys --- .../assets/js/main.js | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/assets/zip/personnal-data-export-navigator/assets/js/main.js b/assets/zip/personnal-data-export-navigator/assets/js/main.js index 58753f99..7da31e64 100644 --- a/assets/zip/personnal-data-export-navigator/assets/js/main.js +++ b/assets/zip/personnal-data-export-navigator/assets/js/main.js @@ -334,7 +334,76 @@ function ApplyPosts(){ } + //Post with survey + if(post.kind == "survey"){ + let infoSurvey = post.data_survey; + + let surveyContainer = createElem2({ + appendTo: cardContent, + type: "div", + class: "post-survey card blue" + }); + + //Survey content + let surveyContent = createElem2({ + appendTo: surveyContainer, + type: "div", + class: "card-content" + }); + + //Survey title + createElem2({ + appendTo: surveyContent, + type: "h2", + class: "survey-title", + innerHTML: infoSurvey.question + }); + + //User choice (if any) + if(infoSurvey.user_choice > 0){ + + createElem2({ + appendTo: surveyContent, + type: "p", + innerHTML: "Your choice : " + infoSurvey.choices[infoSurvey.user_choice].name + }); + + } + + //Survey choices + let surveyChoicesTable = createElem2({ + appendTo: surveyContainer, + type: "table", + class: "survey-choices-table" + }); + + //Table header + createElem2({ + appendTo: surveyChoicesTable, + type: "thead", + innerHTML: "ChoiceResponses" + }); + + //Table body + let surveyTableBody = createElem2({ + appendTo: surveyChoicesTable, + type: "tbody" + }); + + for (const key in infoSurvey.choices) { + if (!infoSurvey.choices.hasOwnProperty(key)) + continue; + const choice = infoSurvey.choices[key]; + + //Add choice + createElem2({ + appendTo: surveyTableBody, + type: "tr", + innerHTML: "" + choice.name + "" + choice.responses + "" + }); + } + } //Display the list of comments let postComments = createElem2({