backoffice: disallow sorting/filtering on headers if all rows are not displayed

This commit is contained in:
Frédéric Péters 2012-08-23 09:08:06 +02:00
parent 2a0b111427
commit 513392b23a
1 changed files with 52 additions and 34 deletions

View File

@ -26,14 +26,28 @@ class FormDefUI:
self.formdef = formdef
def listing [html] (self, fields, selected_filter='all', url_action=None,
include_form=False, items=None, offset=0, count=-1):
get_response().add_javascript(['jquery.js',
'tablesorter/jquery.tablesorter.min.js'])
get_response().add_javascript_code(
str('''$(function() { $("table.sortable").tablesorter(); });'''))
get_response().add_css_include('../js/tablesorter/themes/blue/style.css')
include_form=False, items=None, offset=0, count=0):
partial_display = False
if not items:
if offset and not count:
count = 20
items, total_count = self.get_listing_items(selected_filter, offset, count)
if offset > 0 or total_count < count:
partial_display = True
if not partial_display:
get_response().add_javascript(['jquery.js',
'tablesorter/jquery.tablesorter.min.js'])
get_response().add_javascript_code(
str('''$(function() { $("table.sortable").tablesorter(); });'''))
else:
include_form = False
get_response().add_css_include('../js/tablesorter/themes/blue/style.css')
'<table id="listing" class="sortable tablesorter">'
'<colgroup>'
'<col/>'
'<col/>'
@ -77,42 +91,46 @@ class FormDefUI:
'</thead>'
'<tbody>'
self.tbody(fields=fields, selected_filter=selected_filter, items=items,
url_action=url_action, offset=offset, count=count)
self.tbody(fields, items, url_action)
'</tbody>'
"</table>"
def tbody [html] (self, fields=None, selected_filter='all', items=None,
url_action=None, offset=None, count=None):
if items is None:
if selected_filter == 'all':
item_ids = self.formdef.data_class().keys()
if offset and count:
# add links to paginate
pass
def get_listing_items(self, selected_filter='all', offset=None, count=None):
if selected_filter == 'all':
item_ids = self.formdef.data_class().keys()
else:
applied_filters = []
if selected_filter == 'pending':
applied_filters = ['wf-%s' % x.id for x in \
self.formdef.workflow.get_not_endpoint_status()]
elif selected_filter == 'done':
applied_filters = ['wf-%s' % x.id for x in \
self.formdef.workflow.get_endpoint_status()]
else:
applied_filters = []
if selected_filter == 'pending':
applied_filters = ['wf-%s' % x.id for x in \
self.formdef.workflow.get_not_endpoint_status()]
elif selected_filter == 'done':
applied_filters = ['wf-%s' % x.id for x in \
self.formdef.workflow.get_endpoint_status()]
else:
applied_filters = ['wf-%s' % selected_filter]
item_ids = []
for status_id in applied_filters:
item_ids.extend(self.formdef.data_class().get_ids_with_indexed_value(
str('status'), status_id))
applied_filters = ['wf-%s' % selected_filter]
item_ids = []
for status_id in applied_filters:
item_ids.extend(self.formdef.data_class().get_ids_with_indexed_value(
str('status'), status_id))
if offset and not count:
count = 20
item_ids.sort(lambda x,y: cmp(int(x), int(y)))
item_ids.reverse()
item_ids.sort(lambda x,y: cmp(int(x), int(y)))
item_ids.reverse()
total_count = len(item_ids)
if offset and count:
items = [self.formdef.data_class().get(x) for x in item_ids[offset:offset+count]]
else:
items = [self.formdef.data_class().get(x) for x in item_ids]
if offset and count:
items = [self.formdef.data_class().get(x) for x in item_ids[offset:offset+count]]
else:
items = [self.formdef.data_class().get(x) for x in item_ids]
return (items, total_count)
def tbody [html] (self, fields=None, items=None, url_action=None):
if url_action:
pass
#url_action = '/' + url_action