diff --git a/assets/css/components/posts/ui.css b/assets/css/components/posts/ui.css index d8fb7642..23c9c036 100644 --- a/assets/css/components/posts/ui.css +++ b/assets/css/components/posts/ui.css @@ -33,4 +33,12 @@ .post .post-countdown { text-align: center; padding: 10px; +} + +.post .post-survey-question { + text-align: center; +} + +.post .post-survey-chart-contener { + margin-bottom: 10px; } \ No newline at end of file diff --git a/assets/js/components/posts/ui.js b/assets/js/components/posts/ui.js index 12668610..458526c0 100644 --- a/assets/js/components/posts/ui.js +++ b/assets/js/components/posts/ui.js @@ -240,6 +240,154 @@ ComunicWeb.components.posts.ui = { ComunicWeb.components.countdown.init(infos.time_end, target); } + //In case of survey + else if(infos.kind == "survey"){ + + //Add survey question + var surveyQuestion = createElem2({ + appendTo: postRoot, + type: "h4", + innerHTML: infos.data_survey.infos.question, + class: "post-survey-question" + }); + + //Create row + var row = createElem2({ + appendTo: postRoot, + type: "div", + class: "row post-survey-chart-contener" + }); + + //Create canvas column + var leftColumn = createElem2({ + appendTo: row, + type: "div", + class: "col-md-8" + }); + + //Chart contener + var chartContener = createElem2({ + appendTo: leftColumn, + type: "div", + class: "chart-responsive" + }); + + //Create canvas + var canvas = createElem2({ + appendTo: chartContener, + type: "canvas", + }); + canvas.style.height = "150px"; + + //Create data column + var rightColumn = createElem2({ + appendTo: row, + type: "div", + class: "col-md-4" + }); + + //Initialize legend + var charLegend = createElem2({ + appendTo: rightColumn, + type: "ul", + class: "chart-legend clearfix" + }); + + //Define chart options + var pieOptions = { + //Boolean - Whether we should show a stroke on each segment + segmentShowStroke: true, + //String - The colour of each segment stroke + segmentStrokeColor: "#fff", + //Number - The width of each segment stroke + segmentStrokeWidth: 1, + //Number - The percentage of the chart that we cut out of the middle + percentageInnerCutout: 50, // This is 0 for Pie charts + //Number - Amount of animation steps + animationSteps: 100, + //String - Animation easing effect + animationEasing: "easeOutBounce", + //Boolean - Whether we animate the rotation of the Doughnut + animateRotate: true, + //Boolean - Whether we animate scaling the Doughnut from the centre + animateScale: false, + //Boolean - whether to make the chart responsive to window resizing + responsive: true, + // Boolean - whether to maintain the starting aspect ratio or not when responsive, if set to false, will take up entire container + maintainAspectRatio: false, + //String - A legend template + legendTemplate: "