[IMP] moved pagination script in separate js file,and solved minor issues
bzr revid: pga@tinyerp.com-20140204095157-0mfdy27l9l73dxf5
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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 '<h5 class="panel-primary"><div class="panel-heading">' + x + '</div></h5>' +
|
||||
'<p>'+ '<b>Responses : </b>' + key + '</p>' +
|
||||
'<p>' + "<b>Total Vote : </b>" + y + '</p>'
|
||||
})
|
||||
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 '<h5 class="panel-primary"><div class="panel-heading">' + x + '</div></h5>' +
|
||||
'<p>'+ '<b>Responses : </b>' + key + '</p>' +
|
||||
'<p>' + "<b>Total Vote : </b>" + y + '</p>'
|
||||
})
|
||||
|
||||
// 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!");
|
||||
});
|
||||
@@ -93,35 +93,7 @@
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<!-- Pagination Element -->
|
||||
<ul t-att-id="'pagination_'+str(question.id)" class="pagination" >
|
||||
<t t-if="len(question.user_input_line_ids) > 5">
|
||||
<li t-foreach="page_range(len(question.user_input_line_ids))" t-as="num">
|
||||
<a href="#" t-esc="num"></a>
|
||||
</li>
|
||||
</t>
|
||||
</ul>
|
||||
<!-- Dynamic Script for Pagination Element -->
|
||||
<script>
|
||||
$( document ).ready(function() {
|
||||
$('#table_question_<t t-esc="question.id"></t> tbody tr:lt(5)').removeClass('hidden');
|
||||
$('#<t t-esc="'pagination_'+str(question.id)"></t> li:first').addClass('active');
|
||||
$('#<t t-esc="'pagination_'+str(question.id)"></t> li a').click(function(event){
|
||||
event.preventDefault();
|
||||
$('#<t t-esc="'pagination_'+str(question.id)"></t> li').removeClass('active');
|
||||
$(this).parent('li').addClass('active');
|
||||
$('#table_question_<t t-esc="question.id"></t> tbody tr').addClass('hidden');
|
||||
var num = $(this).text();
|
||||
min = (5 * (num-1))-1;
|
||||
if (min == -1){
|
||||
$('#table_question_<t t-esc="question.id"></t> tbody tr:lt('+5 * num+')').removeClass('hidden');
|
||||
}
|
||||
else{
|
||||
$('#table_question_<t t-esc="question.id"></t> tbody tr:lt('+5 * num+'):gt('+min+')').removeClass('hidden');
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<t t-call="survey.pagination"/>
|
||||
</t>
|
||||
<t t-if="input_summary['answered'] == 0">
|
||||
<h2 style="padding-top:30px;padding-bottom:30px;text-align:center;" class="text-muted">Sorry, No one answered this question.</h2>
|
||||
@@ -144,9 +116,8 @@
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="tab-content">
|
||||
<div class="tab-pane active survey_graph" t-att-id="'graph_question_'+str(question.id)" t-att-data-question_id= "question.id" data-graph_type= "bar">
|
||||
<div class="tab-pane active survey_graph" t-att-id="'graph_question_'+str(question.id)" t-att-data-question_id="question.id" data-graph_type= "bar">
|
||||
<!-- svg element for drawing bar chart -->
|
||||
<svg style="height:20em"></svg>
|
||||
</div>
|
||||
@@ -193,7 +164,6 @@
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="tab-content">
|
||||
<div class="tab-pane active with-3d-shadow with-transitions survey_graph" t-att-id="'graph_question_'+str(question.id)" t-att-data-question_id= "question.id" data-graph_type= "multi_bar">
|
||||
<!-- svg element for drawing Multibar chart -->
|
||||
@@ -286,35 +256,7 @@
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<!-- Pagination Element -->
|
||||
<ul t-att-id="'pagination_'+str(question.id)" class="pagination" >
|
||||
<t t-if="len(question.user_input_line_ids) > 5">
|
||||
<li t-foreach="page_range(len(question.user_input_line_ids))" t-as="num">
|
||||
<a href="#" t-esc="num"></a>
|
||||
</li>
|
||||
</t>
|
||||
</ul>
|
||||
<!-- Dynamic Script for Pagination Element -->
|
||||
<script>
|
||||
$( document ).ready(function() {
|
||||
$('#table_question_<t t-esc="question.id"></t> tbody tr:lt(5)').removeClass('hidden');
|
||||
$('#<t t-esc="'pagination_'+str(question.id)"></t> li:first').addClass('active');
|
||||
$('#<t t-esc="'pagination_'+str(question.id)"></t> li a').click(function(event){
|
||||
event.preventDefault();
|
||||
$('#<t t-esc="'pagination_'+str(question.id)"></t> li').removeClass('active');
|
||||
$(this).parent('li').addClass('active');
|
||||
$('#table_question_<t t-esc="question.id"></t> tbody tr').addClass('hidden');
|
||||
var num = $(this).text();
|
||||
min = (5 * (num-1))-1;
|
||||
if (min == -1){
|
||||
$('#table_question_<t t-esc="question.id"></t> tbody tr:lt('+5 * num+')').removeClass('hidden');
|
||||
}
|
||||
else{
|
||||
$('#table_question_<t t-esc="question.id"></t> tbody tr:lt('+5 * num+'):gt('+min+')').removeClass('hidden');
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<t t-call="survey.pagination"/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -333,5 +275,15 @@
|
||||
</div>
|
||||
</t>
|
||||
</template>
|
||||
<!-- Pagination Element -->
|
||||
<template id="pagination" name="Survey Result">
|
||||
<ul t-att-id="'pagination_'+str(question.id)" class="pagination" t-att-data-question_id= "question.id">
|
||||
<t t-if="len(question.user_input_line_ids) > 5">
|
||||
<li t-foreach="page_range(len(question.user_input_line_ids), 5)" t-as="num">
|
||||
<a href="#" t-esc="num"></a>
|
||||
</li>
|
||||
</t>
|
||||
</ul>
|
||||
</template>
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
Reference in New Issue
Block a user