From f47157102caf3bbb4e3540a05eeed7ee724f8d18 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 10 Jul 2017 21:04:56 -0500 Subject: [PATCH] Add initial/basic support for "simple" mobile grid filter w/ radio buttons so far only one such filter is (presumably?) supported..etc. --- tailbone/newgrids/core.py | 4 +- tailbone/newgrids/filters.py | 14 +++++- tailbone/newgrids/mobile.py | 10 ++++- tailbone/static/css/mobile.css | 5 +++ tailbone/static/js/tailbone.mobile.js | 6 +++ tailbone/templates/mobile/filters_simple.mako | 16 +++++++ tailbone/templates/mobile/master/index.mako | 4 ++ .../templates/mobile/receiving/index.mako | 8 ---- tailbone/views/master.py | 11 ++++- tailbone/views/purchasing/receiving.py | 45 ++++++++++++++++--- 10 files changed, 104 insertions(+), 19 deletions(-) create mode 100644 tailbone/templates/mobile/filters_simple.mako diff --git a/tailbone/newgrids/core.py b/tailbone/newgrids/core.py index 2ba93f17..36cf5b8b 100644 --- a/tailbone/newgrids/core.py +++ b/tailbone/newgrids/core.py @@ -26,6 +26,8 @@ Core Grid Classes from __future__ import unicode_literals, absolute_import +import six + from rattail.db.api import get_setting, save_setting from rattail.util import prettify @@ -106,7 +108,7 @@ class Grid(object): """ Iterate over all filters available to the grid. """ - return self.filters.itervalues() + return six.itervalues(self.filters) def iter_active_filters(self): """ diff --git a/tailbone/newgrids/filters.py b/tailbone/newgrids/filters.py index baaf1e1a..f0857059 100644 --- a/tailbone/newgrids/filters.py +++ b/tailbone/newgrids/filters.py @@ -149,7 +149,7 @@ class GridFilter(object): setattr(self, key, value) def __repr__(self): - return "GridFilter({0})".format(repr(self.key)) + return "{}({})".format(self.__class__.__name__, repr(self.key)) def get_default_verbs(self): """ @@ -206,6 +206,18 @@ class GridFilter(object): return self.value_renderer.render(value=value, **kwargs) +class MobileFilter(GridFilter): + """ + Base class for mobile grid filters. + """ + default_verbs = ['equal'] + + def __init__(self, key, **kwargs): + kwargs.setdefault('default_active', True) + kwargs.setdefault('default_verb', 'equal') + super(MobileFilter, self).__init__(key, **kwargs) + + class AlchemyGridFilter(GridFilter): """ Base class for SQLAlchemy grid filters. diff --git a/tailbone/newgrids/mobile.py b/tailbone/newgrids/mobile.py index ab002e7c..c08453a3 100644 --- a/tailbone/newgrids/mobile.py +++ b/tailbone/newgrids/mobile.py @@ -26,16 +26,24 @@ Mobile Grids from __future__ import unicode_literals, absolute_import +from pyramid.renderers import render from webhelpers2.html import HTML -from tailbone.newgrids import AlchemyGrid +from tailbone.newgrids import filters, AlchemyGrid class MobileGrid(AlchemyGrid): """ Base class for all mobile grids """ + default_filters = filters.GridFilterSet() def column_header(self, column): kwargs = {'c': column.label} return HTML.tag('th', **kwargs) + + def render_filters(self, template='/mobile/filters_simple.mako', **kwargs): + context = kwargs + context['request'] = self.request + context['grid'] = self + return render(template, context) diff --git a/tailbone/static/css/mobile.css b/tailbone/static/css/mobile.css index 7dd238f9..9ed2ed93 100644 --- a/tailbone/static/css/mobile.css +++ b/tailbone/static/css/mobile.css @@ -34,3 +34,8 @@ font-weight: bold; margin-top: 1em; } + +/* make sure space comes between simple filter and "grid" list */ +.simple-filter { + margin-bottom: 1.5em; +} diff --git a/tailbone/static/js/tailbone.mobile.js b/tailbone/static/js/tailbone.mobile.js index af34191a..3e8db76b 100644 --- a/tailbone/static/js/tailbone.mobile.js +++ b/tailbone/static/js/tailbone.mobile.js @@ -69,6 +69,12 @@ $(document).on('pageshow', function() { }); +// handle radio button value change for "simple" grid filter +$(document).on('change', '.simple-filter .ui-radio', function() { + $(this).parents('form:first').submit(); +}); + + // vendor validation for new purchasing batch $(document).on('click', 'form[name="new-purchasing-batch"] input[type="submit"]', function() { var $form = $(this).parents('form'); diff --git a/tailbone/templates/mobile/filters_simple.mako b/tailbone/templates/mobile/filters_simple.mako new file mode 100644 index 00000000..d0644e5f --- /dev/null +++ b/tailbone/templates/mobile/filters_simple.mako @@ -0,0 +1,16 @@ +## -*- coding: utf-8; -*- +
+ ${h.form(request.current_route_url(), method='get')} + ${h.csrf_token(request)} + + % for filtr in grid.iter_filters(): + ${h.hidden('{}.verb'.format(filtr.key), value=filtr.verb)} +
+ % for value, label in filtr.iter_choices(): + ${h.radio(filtr.key, value=value, label=label, checked=value == filtr.value)} + % endfor +
+ % endfor + + ${h.end_form()} +
diff --git a/tailbone/templates/mobile/master/index.mako b/tailbone/templates/mobile/master/index.mako index b212c3cd..74b5d7f7 100644 --- a/tailbone/templates/mobile/master/index.mako +++ b/tailbone/templates/mobile/master/index.mako @@ -9,6 +9,10 @@ <%def name="title()">${model_title_plural} +% if grid.filterable: + ${grid.render_filters()|n} +% endif +