def widget(self, resource, values): """ Render this widget as HTML helper object(s) @param resource: the resource @param values: the search values from the URL query """ attr = self._attr(resource) opts = self.opts name = attr["_name"] ftype, levels, noopt = self._options(resource) if noopt: return SPAN(noopt, _class="no-options-available") # Filter class (default+custom) _class = self._class if "_class" in attr and attr["_class"]: _class = "%s %s" % (_class, attr["_class"]) attr["_class"] = _class # Store id and name for the data element base_id = attr["_id"] base_name = attr["_name"] widgets = [] w_append = widgets.append operator = self.operator field_name = self.field # @ToDo: Hide dropdowns other than first if opts.widget == "multiselect": # Multiselect Dropdown with Checkboxes if "multiselect-filter-widget" not in _class: attr["_class"] = "%s multiselect-filter-widget" % _class # Add one widget per level for level in levels: # Dummy field name = "%s-%s" % (base_name, level) options = levels[level]["options"] options.sort() dummy_field = Storage(name=name, type=ftype, requires=IS_IN_SET(options, multiple=True)) # Unique ID/name attr["_id"] = "%s-%s" % (base_id, level) attr["_name"] = name # Find relevant values to pre-populate the widget _values = values["~.%s$%s__%s" % (field_name, level, operator)] w = S3MultiSelectWidget(filter = opts.get("filter", False), header = opts.get("header", False), selectedList = opts.get("selectedList", 3), noneSelectedText = "Select %s" % levels[level]["label"]) widget = w(dummy_field, _values, **attr) w_append(widget) else: # Grouped Checkboxes if "s3-checkboxes-widget" not in _class: attr["_class"] = "%s s3-checkboxes-widget" % _class attr["cols"] = opts["cols"] # Add one widget per level for level in levels: # Dummy field name = "%s-%s" % (base_name, level) options = levels[level]["options"] options.sort() dummy_field = Storage(name=name, type=ftype, requires=IS_IN_SET(options, multiple=True)) # Unique ID/name attr["_id"] = "%s-%s" % (base_id, level) attr["_name"] = name # Find relevant values to pre-populate _values = values["~.%s$%s__%s" % (field_name, level, operator)] w_append(s3_grouped_checkboxes_widget(dummy_field, _values, **attr)) # Restore id and name for the data_element attr["_id"] = base_id attr["_name"] = base_name # Render the filter widget return TAG[""](*widgets)
def widget(self, resource, values): """ Render this widget as HTML helper object(s) @param resource: the resource @param values: the search values from the URL query """ attr = self._attr(resource) opts = self.opts name = attr["_name"] # Filter class (default+custom) _class = self._class if "_class" in attr and attr["_class"]: _class = "%s %s" % (_class, attr["_class"]) attr["_class"] = _class # Get the options ftype, options, noopt = self._options(resource) if noopt: return SPAN(noopt, _class="no-options-available") else: options = OrderedDict(options) # Any-All-Option : for many-to-many fields the user can # search for records containing all the options or any # of the options: if len(options) > 1 and ftype[:4] == "list": if self.operator == "anyof": filter_type = "any" else: filter_type = "all" if self.operator == "belongs": self.operator = "contains" any_all = DIV(T("Filter type "), INPUT(_name="%s_filter" % name, _id="%s_filter_any" % name, _type="radio", _value="any", value=filter_type), LABEL(T("Any"), _for="%s_filter_any" % name), INPUT(_name="%s_filter" % name, _id="%s_filter_all" % name, _type="radio", _value="all", value=filter_type), LABEL(T("All"), _for="%s_filter_all" % name), _class="s3-options-filter-anyall") else: any_all = "" # Render the filter widget dummy_field = Storage(name=name, type=ftype, requires=IS_IN_SET(options, multiple=True)) widget_type = opts["widget"] if widget_type == "multiselect-bootstrap": script = "/%s/static/scripts/bootstrap-multiselect.js" % \ current.request.application scripts = current.response.s3.scripts if script not in scripts: scripts.append(script) widget = MultipleOptionsWidget.widget(dummy_field, values, **attr) widget.add_class("multiselect-filter-bootstrap") elif widget_type == "multiselect": if "multiselect-filter-widget" not in _class: attr["_class"] = "%s multiselect-filter-widget" % _class w = S3MultiSelectWidget( filter = opts.get("filter", False), header = opts.get("header", False), selectedList = opts.get("selectedList", 3), ) widget = w(dummy_field, values, **attr) else: if "s3-checkboxes-widget" not in _class: attr["_class"] = "%s s3-checkboxes-widget" % _class attr["cols"] = opts["cols"] widget = s3_grouped_checkboxes_widget(dummy_field, values, **attr) return TAG[""](any_all, widget)
def widget(self, resource, values): """ Render this widget as HTML helper object(s) @param resource: the resource @param values: the search values from the URL query """ attr = self._attr(resource) opts = self.opts name = attr["_name"] ftype, levels, noopt = self._options(resource) if noopt: return SPAN(noopt, _class="no-options-available") # Filter class (default+custom) _class = self._class if "_class" in attr and attr["_class"]: _class = "%s %s" % (_class, attr["_class"]) attr["_class"] = _class # Store id and name for the data element base_id = attr["_id"] base_name = attr["_name"] widgets = [] w_append = widgets.append operator = self.operator field_name = self.field # @ToDo: Hide dropdowns other than first if opts.widget == "multiselect": # Multiselect Dropdown with Checkboxes if "multiselect-filter-widget" not in _class: attr["_class"] = "%s multiselect-filter-widget" % _class # Add one widget per level for level in levels: # Dummy field name = "%s-%s" % (base_name, level) options = levels[level]["options"] options.sort() dummy_field = Storage(name=name, type=ftype, requires=IS_IN_SET(options, multiple=True)) # Unique ID/name attr["_id"] = "%s-%s" % (base_id, level) attr["_name"] = name # Find relevant values to pre-populate the widget _values = values["~.%s$%s__%s" % (field_name, level, operator)] w = S3MultiSelectWidget( filter=opts.get("filter", False), header=opts.get("header", False), selectedList=opts.get("selectedList", 3), noneSelectedText="Select %s" % levels[level]["label"]) widget = w(dummy_field, _values, **attr) w_append(widget) else: # Grouped Checkboxes if "s3-checkboxes-widget" not in _class: attr["_class"] = "%s s3-checkboxes-widget" % _class attr["cols"] = opts["cols"] # Add one widget per level for level in levels: # Dummy field name = "%s-%s" % (base_name, level) options = levels[level]["options"] options.sort() dummy_field = Storage(name=name, type=ftype, requires=IS_IN_SET(options, multiple=True)) # Unique ID/name attr["_id"] = "%s-%s" % (base_id, level) attr["_name"] = name # Find relevant values to pre-populate _values = values["~.%s$%s__%s" % (field_name, level, operator)] w_append( s3_grouped_checkboxes_widget(dummy_field, _values, **attr)) # Restore id and name for the data_element attr["_id"] = base_id attr["_name"] = base_name # Render the filter widget return TAG[""](*widgets)