diff --git a/addons/survey/controllers/main.py b/addons/survey/controllers/main.py index 9e844c0ba82..afb2078b767 100644 --- a/addons/survey/controllers/main.py +++ b/addons/survey/controllers/main.py @@ -286,7 +286,7 @@ class WebsiteSurvey(http.Controller): def survey_reporting(self, survey, token=None, **post): '''Display an survey Results & Statistics for given survey.''' result_tamplate = 'survey.result' - if not survey.user_input_ids: + if not survey.user_input_ids or not [input_id.id for input_id in survey.user_input_ids if input_id.state != 'new']: result_tamplate = 'survey.no_result' return request.website.render(result_tamplate, {'survey': survey, @@ -296,9 +296,9 @@ class WebsiteSurvey(http.Controller): 'page_range':self.page_range }) - def page_range(self, total_record): + def page_range(self, total_record, limit): '''Returns number of pages required for pagination''' - total = math.ceil( total_record/5.0 ) + total = math.ceil( total_record/float(limit) ) return range(1, int( total+1 )) def prepare_result(self, question): @@ -355,7 +355,7 @@ class WebsiteSurvey(http.Controller): '''Returns overall summary of question e.g. answered, skipped, total_inputs''' result = {} if question.page_id.survey_id.user_input_ids: - result['total_inputs'] = len(question.page_id.survey_id.user_input_ids) + result['total_inputs'] = len([input_id.id for input_id in question.page_id.survey_id.user_input_ids if input_id.state != 'new']) question_input_ids = [] for user_input in question.user_input_line_ids: if not user_input.skipped: diff --git a/addons/survey/static/src/js/survey_result.js b/addons/survey/static/src/js/survey_result.js index 6f372ad7217..d1a5d20dbd2 100644 --- a/addons/survey/static/src/js/survey_result.js +++ b/addons/survey/static/src/js/survey_result.js @@ -23,87 +23,104 @@ $(document).ready(function () { 'use strict'; - console.log("Survey Result JS loaded ...."); + console.debug("[survey] Survey Result JS is loading..."); + //Script For Pagination + var survey_pagination = $('.pagination'); + var limit = 5; //Number of Record Par Page. If you change value here, make change in pagination template also. + $.each(survey_pagination, function(index, pagination){ + var question_id = $(pagination).attr("data-question_id"); + $('#table_question_'+ question_id +' tbody tr:lt('+limit+')').removeClass('hidden'); + $('#pagination_'+question_id+' li:first').addClass('active'); + $('#pagination_'+question_id+' li a').click(function(event){ + event.preventDefault(); + $('#pagination_'+question_id+' li').removeClass('active'); + $(this).parent('li').addClass('active'); + $('#table_question_'+ question_id +' tbody tr').addClass('hidden'); + var num = $(this).text(); + var min = (limit * (num-1))-1; + if (min == -1){ + $('#table_question_'+ question_id +' tbody tr:lt('+ limit * num +')').removeClass('hidden'); + } + else{ + $('#table_question_'+question_id+' tbody tr:lt('+ limit * num +'):gt('+min+')').removeClass('hidden'); + } + }); + }); + + //initialize MultiBar Chart + function init_multibar_chart(){ + var chart = nv.models.multiBarChart() + .x(function(d) { return d.text }) + .y(function(d) { return d.count }) + .staggerLabels(true); + + // Replacing Library's Default Tooltip with our Custom One + chart.tooltip(function(key, x, y, e, graph) { + return '
'+ 'Responses : ' + key + '
' + + '' + "Total Vote : " + y + '
' + }) + return chart + } + + //initialize discreteBar Chart + function init_bar_chart(){ + return nv.models.discreteBarChart() + .x(function(d) { return d.text }) + .y(function(d) { return d.count }) + .staggerLabels(true) + .tooltips(false) + .showValues(true) + } + + //load chart to svg element chart:initialized chart, response:AJAX response, quistion_id:if of survey question, tick_limit:text length limit + function load_chart(chart, response, question_id, tick_limit){ + // Custom Tick fuction for replacing long text with '...' + var customtick_function = function(d){ + if(! this || d.length <= tick_limit){ + return d; + } + else{ + return d.slice(0,tick_limit)+'...'; + } + } + chart.xAxis + .tickFormat(customtick_function); + chart.yAxis + .tickFormat(d3.format('d')); + + d3.select('#graph_question_' + question_id + ' svg') + .datum(response) + .transition().duration(500).call(chart); + nv.utils.windowResize(chart.update); + return chart + } + //Script For Graph var survey_graphs = $('.survey_graph'); $.each(survey_graphs, function(index, graph){ var question_id = $(graph).attr("data-question_id"); var graph_type = $(graph).attr("data-graph_type"); $.ajax({ url: '/survey/results/graph/'+question_id, - type: 'POST', // submission type - dataType: 'json', // answer expected type + type: 'POST', + dataType: 'json', success: function(response, status, xhr, wfe){ if(graph_type == 'multi_bar'){ nv.addGraph(function(){ - var chart = nv.models.multiBarChart() - .x(function(d) { return d.text }) - .y(function(d) { return d.count }) - .staggerLabels(true); - - // Replacing Library's Default Tooltip with our Custom One - chart.tooltip(function(key, x, y, e, graph) { - return ''+ 'Responses : ' + key + '
' + - '' + "Total Vote : " + y + '
' - }) - - // Custom Tick fuction for replacing long text with '...' - var customtick_function = function(d){ - if(! this || d.length < 25){ - return d; - } - else{ - return d.slice(0,25)+'...'; - } - } - - chart.xAxis - .tickFormat(customtick_function); - chart.yAxis - .tickFormat(d3.format('d')); - - d3.select('#graph_question_' + question_id + ' svg') - .datum(response) - .transition().duration(500).call(chart); - nv.utils.windowResize(chart.update); - return chart; + var chart = init_multibar_chart(); + return load_chart(chart,response,question_id,25); }); } else if(graph_type == 'bar'){ - nv.addGraph(function() { - var chart = nv.models.discreteBarChart() - .x(function(d) { return d.text }) - .y(function(d) { return d.count }) - .staggerLabels(true) - .tooltips(false) - .showValues(true) - - // Custom Tick fuction for replacing long text with '...' - var customtick_function = function(d){ - if(this.hasOwnProperty('window') || d.length < 35){ - return d; - } - else{ - return d.slice(0,35)+'...'; - } - } - - chart.xAxis - .tickFormat(customtick_function); - chart.yAxis - .tickFormat(d3.format('d')); - - d3.select('#graph_question_' + question_id + ' svg') - .datum(response) - .transition().duration(500) - .call(chart); - nv.utils.windowResize(chart.update); - return chart; + var chart = init_bar_chart(); + return load_chart(chart,response,question_id,35); }); } } }); - }) + }); + + console.debug("[survey] Survey Result JS loaded!"); }); \ No newline at end of file diff --git a/addons/survey/views/survey_result.xml b/addons/survey/views/survey_result.xml index 63b88cbc133..ce7ddf18d5e 100644 --- a/addons/survey/views/survey_result.xml +++ b/addons/survey/views/survey_result.xml @@ -93,35 +93,7 @@ - - - - +