Skip to content

Commit

Permalink
added datatable options (search_label) propagation though Module
Browse files Browse the repository at this point in the history
  • Loading branch information
redyvon committed May 21, 2015
1 parent 029d506 commit ab36623
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 6 additions & 5 deletions abilian/web/forms/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def render(self, entities, **kwargs):
'aoColumns': aoColumns,
'bFilter': self.show_search,
'oLanguage': {
'sSearch': _("Filter records:"),
'sSearch': self.options.get('search_label', _("Filter records:")),
},
'bStateSave': False,
'bPaginate': self.paginate,
Expand Down Expand Up @@ -244,13 +244,16 @@ class AjaxMainTableView(object):
"""
show_controls = False
paginate = True
options = {}

def __init__(self, columns, ajax_source, search_criterions=(), name=None):
def __init__(self, columns, ajax_source, search_criterions=(), name=None, options=None):
self.init_columns(columns)
self.ajax_source = ajax_source
self.search_criterions = search_criterions
self.name = name if name is not None else id(self)
self.save_state = name is not None
if options is not None:
self.options = options

def init_columns(self, columns):
# TODO: compute the correct width for each column.
Expand All @@ -268,13 +271,12 @@ def render(self):
aoColumns = [{'asSorting': []}] if self.show_controls else []
aoColumns += [{'asSorting': ["asc", "desc"]}
for i in range(0, len(self.columns))]

datatable_options = {
'sDom': 'lfFrtip',
'aoColumns': aoColumns,
'bFilter': True,
'oLanguage': {
'sSearch': _("Filter records:"),
'sSearch': self.options.get('search_label', _("Filter records:")),
'sPrevious': _("Previous"),
'sNext': _("Next"),
'sInfo': _("Showing _START_ to _END_ of _TOTAL_ entries"),
Expand Down Expand Up @@ -563,7 +565,6 @@ def __init__(self, input_type=None, pre_icon=None, post_icon=None,
if post_icon is not None:
self.post_icon = post_icon


def __call__(self, field, *args, **kwargs):
if not any((self.pre_icon, self.post_icon)):
return super(TextInput, self).__call__(field, *args, **kwargs)
Expand Down
4 changes: 3 additions & 1 deletion abilian/web/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ class Module(object):
blueprint = None
search_criterions = (search.TextSearchCriterion("name",
attributes=('name', 'nom')),)
tableview_options = {} # used mostly to change datatable search_label
_urls = []

def __init__(self):
Expand Down Expand Up @@ -454,7 +455,8 @@ def list_view(self):
name=self.managed_class.__name__.lower(),
columns=self.list_view_columns,
ajax_source=url_for('.list_json'),
search_criterions=self.search_criterions,)
search_criterions=self.search_criterions,
options=self.tableview_options)
rendered_table = table_view.render()

ctx = dict(rendered_table=rendered_table,
Expand Down

0 comments on commit ab36623

Please sign in to comment.