Skip to content

Commit

Permalink
WACOP: formstyle for filterform
Browse files Browse the repository at this point in the history
groupedoptionswidget can now render inside divs not just table
  • Loading branch information
flavour committed Jan 16, 2017
1 parent 23345af commit 2f2756d
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 109 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
28fc73f (2017-01-13 16:29:11)
23345af (2017-01-16 11:56:13)
1 change: 1 addition & 0 deletions modules/s3/s3filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1534,6 +1534,7 @@ def widget(self, resource, values):
help_field = opts_get("help_field"),
sort = opts_get("sort", True),
orientation = opts_get("orientation"),
table = opts_get("table"),
)
else:
# Default widget_type = "multiselect"
Expand Down
9 changes: 7 additions & 2 deletions modules/s3/s3widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2569,7 +2569,9 @@ def __init__(self,
help_field=None,
none=None,
sort=True,
orientation=None):
orientation=None,
table=True,
):
"""
Constructor
Expand All @@ -2586,6 +2588,7 @@ def __init__(self,
@param none: True to render "None" as normal option
@param sort: sort the options (only effective if size==None)
@param orientation: the ordering orientation, "columns"|"rows"
@param table: whether to render options inside a table or not
"""

self.options = options
Expand All @@ -2596,6 +2599,7 @@ def __init__(self,
self.none = none
self.sort = sort
self.orientation = orientation
self.table = table

# -------------------------------------------------------------------------
def __call__(self, field, value, **attributes):
Expand Down Expand Up @@ -2633,9 +2637,10 @@ def __call__(self, field, value, **attributes):

widget.add_class("groupedopts-widget")
widget_opts = {"columns": self.cols,
"emptyText": str(current.T("No options available")),
"emptyText": s3_str(current.T("No options available")),
"orientation": self.orientation or "columns",
"sort": self.sort,
"table": self.table,
}
script = '''$('#%s').groupedopts(%s)''' % \
(_id, json.dumps(widget_opts, separators=SEPARATORS))
Expand Down
8 changes: 4 additions & 4 deletions modules/templates/WACOP/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,11 @@ def custom_prep(r):
)

from s3 import S3DateFilter, S3OptionsFilter, S3TextFilter
from templates.WACOP.controllers import filter_formstyle, text_filter_formstyle
from templates.WACOP.controllers import filter_formstyle_summary, text_filter_formstyle

# @ToDo: This should use date/end_date not just date
date_filter = S3DateFilter("date",
#formstyle = filter_formstyle,
#formstyle = filter_formstyle_summary,
label = "",
#hide_time = True,
)
Expand All @@ -364,7 +364,7 @@ def custom_prep(r):
widget = "multiselect",
),
S3OptionsFilter("closed",
formstyle = filter_formstyle,
formstyle = filter_formstyle_summary,
options = {"*": T("All"),
False: T("Open"),
True: T("Closed"),
Expand All @@ -373,7 +373,7 @@ def custom_prep(r):
multiple = False,
),
S3OptionsFilter("incident_type_id",
formstyle = filter_formstyle,
formstyle = filter_formstyle_summary,
label = T("Incident Type"),
noneSelectedText = "All",
widget = "multiselect",
Expand Down
54 changes: 53 additions & 1 deletion modules/templates/WACOP/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,11 @@ def _updates_html(self, r, output, incident_id, updateable, **attr):
},
cols = 2,
multiple = False,
table = False,
))

filter_form = S3FilterForm(filter_widgets,
formstyle = filter_formstyle_profile,
submit=True,
ajax=True,
url=URL(args=[incident_id, "custom.dl"],
Expand Down Expand Up @@ -1491,7 +1493,7 @@ def render_row(row_id, label, widget, comment, hidden=False):
return parent

# =============================================================================
def filter_formstyle(form, fields, *args, **kwargs):
def filter_formstyle_summary(form, fields, *args, **kwargs):
"""
Custom formstyle for filters on the Incident Summary page
"""
Expand All @@ -1515,4 +1517,54 @@ def render_row(row_id, label, widget, comment, hidden=False):
parent.append(render_row(row_id, label, widget, comment))
return parent

# =============================================================================
def filter_formstyle_profile(form, fields, *args, **kwargs):
"""
Custom formstyle for filters on the Incident Profile page
- slightly tweaked formstyle_foundation_inline
"""

def render_row(row_id, label, widget, comment, hidden=False):

if hasattr(widget, "element"):
submit = widget.element("input", _type="submit")
if submit:
submit.add_class("small primary button")

if isinstance(label, LABEL):
label.add_class("left inline")

controls_col = DIV(widget, _class="small-12 columns controls")
if label:
label_col = DIV(label, _class="medium-2 columns")
else:
label_col = ""
#controls_col.add_class("medium-offset-2")

if comment:
comment = render_tooltip(label,
comment,
_class="inline-tooltip tooltip",
)
if hasattr(comment, "add_class"):
comment.add_class("inline-tooltip")
controls_col.append(comment)

_class = "form-row row hide" if hidden else "form-row row"
return DIV(label_col,
controls_col,
_class=_class, _id=row_id)

if args:
row_id = form
label = fields
widget, comment = args
hidden = kwargs.get("hidden", False)
return render_row(row_id, label, widget, comment, hidden)
else:
parent = TAG[""]()
for row_id, label, widget, comment in fields:
parent.append(render_row(row_id, label, widget, comment))
return parent

# END =========================================================================

0 comments on commit 2f2756d

Please sign in to comment.