[IMP] Added preset All vs Finished Filter
bzr revid: dizzy.zala@gmail.com-20140327064305-tlw358e0u9wu9jnd
This commit is contained in:
@@ -285,16 +285,22 @@ class WebsiteSurvey(http.Controller):
|
||||
type='http', auth='user', multilang=True, website=True)
|
||||
def survey_reporting(self, survey, token=None, **post):
|
||||
'''Display survey Results & Statistics for given survey.'''
|
||||
result_template, current_filters, filter_display_data = 'survey.result', [], []
|
||||
result_template, current_filters, filter_display_data, filter_finish = 'survey.result', [], [], False
|
||||
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_template = 'survey.no_result'
|
||||
if post.get('finished'):
|
||||
post.pop('finished')
|
||||
filter_finish = True
|
||||
if post:
|
||||
current_filters, filter_display_data = self.filter_input_ids(post)
|
||||
if filter_finish:
|
||||
current_filters = self.get_finished_list(current_filters)
|
||||
return request.website.render(result_template,
|
||||
{'survey_dict': self.prepare_result_dict(survey, current_filters),
|
||||
'page_range': self.page_range,
|
||||
'current_filters': current_filters,
|
||||
'filter_display_data': filter_display_data
|
||||
'filter_display_data': filter_display_data,
|
||||
'filter_finish': filter_finish
|
||||
})
|
||||
|
||||
def prepare_result_dict(self,survey, current_filters=[]):
|
||||
@@ -307,6 +313,15 @@ class WebsiteSurvey(http.Controller):
|
||||
result['page_ids'].append(page_dict)
|
||||
return result
|
||||
|
||||
def get_finished_list(self, current_filters):
|
||||
user_input,filtered_list = request.registry['survey.user_input'],[]
|
||||
if not current_filters:
|
||||
current_filters = user_input.search(request.cr, request.uid, [], context=request.context)
|
||||
user_input_objs = user_input.browse(request.cr, request.uid, current_filters, context=request.context)
|
||||
print 'user_input_objs',user_input_objs
|
||||
filtered_list = [input.id for input in user_input_objs if input.state == 'done']
|
||||
return filtered_list
|
||||
|
||||
def filter_input_ids(self, filters):
|
||||
'''If user applies any filters, then this function returns list of
|
||||
filtered user_input_id and label's strings for display data in web'''
|
||||
@@ -396,8 +411,8 @@ class WebsiteSurvey(http.Controller):
|
||||
@http.route(['/survey/results/graph/<int:question>'],
|
||||
type='http', auth='user', multilang=True, website=True)
|
||||
def get_graph_data(self, question, **post):
|
||||
question = request.registry.get('survey.question').browse(request.cr, request.uid, question)
|
||||
'''Returns appropriate formated data required by graph library on basis of filter'''
|
||||
question = request.registry.get('survey.question').browse(request.cr, request.uid, question)
|
||||
current_filters = safe_eval(post.get('current_filters', '[]'))
|
||||
result = []
|
||||
if question.type == 'multiple_choice':
|
||||
|
||||
@@ -154,6 +154,21 @@ $(document).ready(function () {
|
||||
$('.clear_survey_filter').click(function(){
|
||||
window.location.href = document.URL.substring(0,document.URL.indexOf("?"));
|
||||
});
|
||||
$('li.filter-all').click(function(){
|
||||
event.preventDefault();
|
||||
if(document.URL.indexOf("finished") != -1){
|
||||
window.location.href = document.URL.replace('?finished=1&','?').replace('&finished=1&','&').replace('?finished=1','').replace('&finished=1','');
|
||||
}
|
||||
});
|
||||
$('.filter-finished').click(function(){
|
||||
event.preventDefault();
|
||||
if(document.URL.indexOf("?") == -1 && document.URL.indexOf("filter") == -1){
|
||||
window.location.href = document.URL+'?'+encodeURI('finished=1');
|
||||
}
|
||||
else if (document.URL.indexOf("finished") == -1){
|
||||
window.location.href = document.URL+'&'+encodeURI('finished=1');
|
||||
}
|
||||
});
|
||||
|
||||
console.debug("[survey] Survey Result JS loaded!");
|
||||
});
|
||||
@@ -17,6 +17,18 @@
|
||||
<h1><span t-field="survey.title"></span> <span style="font-size:1.5em;" class="fa fa-bar-chart-o pull-right "/></h1>
|
||||
<h2><span t-field="survey.description"></span></h2>
|
||||
</div>
|
||||
<div>
|
||||
<ul class="nav nav-pills">
|
||||
<t t-if="filter_finish == True">
|
||||
<li class="filter-all"><a href="#">All</a></li>
|
||||
<li class="active filter-finished"><a href="#">Finished</a></li>
|
||||
</t>
|
||||
<t t-if="filter_finish == False">
|
||||
<li class="active filter-all"><a href="#">All</a></li>
|
||||
<li class="filter-finished"><a href="#">Finished</a></li>
|
||||
</t>
|
||||
</ul>
|
||||
</div>
|
||||
<div t-if="filter_display_data" class="filteres">
|
||||
<span><h3><span class="fa fa-filter"></span> Filters <small class="pull-right clear_survey_filter"> <i class="fa fa-times"></i> Clear All Filters</small></h3></span>
|
||||
<span t-foreach="filter_display_data" t-as="filter_data">
|
||||
|
||||
Reference in New Issue
Block a user