def widget(self, field, value,**attributes):



        #generate the standard widget for this field
        if self.multiple == True:
            select_widget = MultipleOptionsWidget.widget(field, value, size=7)
            attr =  MultipleOptionsWidget._attributes(field, {'value':value}, **attributes)
        else:
            select_widget = OptionsWidget.widget(field, value)
            attr = OptionsWidget._attributes(field, {'value':value}, **attributes)

        #get the widget's id (need to know later on so can tell receiving controller what to update)
        my_select_id = select_widget.attributes.get('_id', None)
        add_args = [my_select_id]
        #create a div that will load the specified controller via ajax
        form_loader_div = DIV(LOAD(c=self.controller, f=self.function, args=add_args,ajax=True), _id=my_select_id+"_dialog-form", _title=self.form_title)
        #generate the "add" button that will appear next the options widget and open our dialog

        activator_button = A(XML('<button type="button" class="btn btn-primary" data-toggle="button">'+T(self.button_text)+'</button>'), _id=my_select_id+"_option_add_trigger")
        #create javascript for creating and opening the dialog
        js = '$( "#%s_dialog-form" ).dialog({autoOpen: false, show: "blind", hide: "explode", width: %s});' % (my_select_id, self.dialog_width)
        js += '$( "#%s_option_add_trigger" ).click(function() { $( "#%s_dialog-form" ).dialog( "open" );return false;}); ' % (my_select_id, my_select_id)        #decorate our activator button for good measure
        js += '$(function() { $( "#%s_option_add_trigger" ).button({text: true, icons: { primary: "ui-icon-circle-plus"} }); });' % (my_select_id)
        jq_script=SCRIPT(js, _type="text/javascript")

        wrapper = DIV(_id=my_select_id+"_adder_wrapper")
        wrapper.components.extend([select_widget, form_loader_div, activator_button, jq_script])
        return wrapper
    def widget(self, field, value,**attributes):



        #generate the standard widget for this field
        if self.multiple == True:
            select_widget = MultipleOptionsWidget.widget(field, value, size=7)
            attr =  MultipleOptionsWidget._attributes(field, {'value':value}, **attributes)
        else:
            select_widget = OptionsWidget.widget(field, value)
            attr = OptionsWidget._attributes(field, {'value':value}, **attributes)

        #get the widget's id (need to know later on so can tell receiving controller what to update)
        my_select_id = select_widget.attributes.get('_id', None)
        add_args = [my_select_id]
        #create a div that will load the specified controller via ajax
        form_loader_div = DIV(LOAD(c=self.controller, f=self.function, args=add_args,ajax=True), _id=my_select_id+"_dialog-form", _title=self.form_title)
        #generate the "add" button that will appear next the options widget and open our dialog

        activator_button = A(XML('<button type="button" class="btn btn-primary" data-toggle="button">'+T(self.button_text)+'</button>'), _id=my_select_id+"_option_add_trigger")
        #create javascript for creating and opening the dialog
        js = '$( "#%s_dialog-form" ).dialog({autoOpen: false, show: "blind", hide: "explode", width: %s});' % (my_select_id, self.dialog_width)
        js += '$( "#%s_option_add_trigger" ).click(function() { $( "#%s_dialog-form" ).dialog( "open" );return false;}); ' % (my_select_id, my_select_id)        #decorate our activator button for good measure
        js += '$(function() { $( "#%s_option_add_trigger" ).button({text: true, icons: { primary: "ui-icon-circle-plus"} }); });' % (my_select_id)
        jq_script=SCRIPT(js, _type="text/javascript")

        wrapper = DIV(_id=my_select_id+"_adder_wrapper")
        wrapper.components.extend([select_widget, form_loader_div, activator_button, jq_script])
        return wrapper
 def create_widget(self):
     """
     create either a single select widget or multiselect widget
     """
     if not self.multi in [None, 'False']:
         if self.orderby:
             w = FilteredOptionsWidget.widget(self.field,
                                              self.value,
                                              orderby=self.orderby,
                                              multiple='multiple')
         else:
             w = MultipleOptionsWidget.widget(self.field, self.value)
         #place selected items at end of sortable select widget
         if self.sortable:
             print 'val: ', self.value
             try:
                 for v in self.value:
                     opt = w.element(_value=v)
                     i = w.elements().index(opt)
                     w.append(opt)
                     del w[i - 1]
             except AttributeError, e:
                 if type(v) == 'IntType':
                     opt = w.element(_value=self.value)
                     i = w.elements().index(opt)
                     w.append(opt)
                     del w[i - 1]
                 else:
                     print e
             except Exception, e:
                 print e, type(e)
 def create_widget(self):
     """
     create either a single select widget or multiselect widget
     """
     if not self.multi in [None, "False"]:
         if self.orderby:
             w = FilteredOptionsWidget.widget(self.field, self.value, orderby=self.orderby, multiple="multiple")
         else:
             w = MultipleOptionsWidget.widget(self.field, self.value)
         # place selected items at end of sortable select widget
         if self.sortable:
             print "val: ", self.value
             try:
                 for v in self.value:
                     opt = w.element(_value=v)
                     i = w.elements().index(opt)
                     w.append(opt)
                     del w[i - 1]
             except AttributeError, e:
                 if type(v) == "IntType":
                     opt = w.element(_value=self.value)
                     i = w.elements().index(opt)
                     w.append(opt)
                     del w[i - 1]
                 else:
                     print e
             except Exception, e:
                 print e, type(e)
    def create_widget(self, field, value, clean_val, multi, restricted, rval):
        """create either a single select widget or multiselect widget"""

        if multi:
            w = MultipleOptionsWidget.widget(field, value)
            # TODO: Create filtered multiple options widget class
        else:
            if rval:
                w = FilteredOptionsWidget.widget(field, value, restricted, rval)
            else:
                w = OptionsWidget.widget(field, value)

        return w
    def create_widget(self, field, value, clean_val, multi, restricted, rval):
        """create either a single select widget or multiselect widget"""

        if multi:
            w = MultipleOptionsWidget.widget(field, value)
            #TODO: Create filtered multiple options widget class
        else:
            if rval:
                w = FilteredOptionsWidget.widget(field, value, restricted,
                                                 rval)
            else:
                w = OptionsWidget.widget(field, value)

        return w
 def _create_widget(self):
     """
     Create either a single select widget or multiselect widget
     """
     if not self.multi in [None, False, "False"]:
         if self.orderby or self.rval:
             w = FilteredMultipleOptionsWidget.widget(
                 self.field,
                 self.value,
                 orderby=self.orderby,
                 multiple="multiple",
                 restricted=self.restricted,
                 rval=self.rval,
             )
         else:
             w = MultipleOptionsWidget.widget(self.field, self.value)
         # place selected items at end of sortable select widget
         if self.sortable:
             print "trying to sort values ============="
             print "value is", self.value
             try:
                 for v in self.value:
                     print "1"
                     opt = w.element(_value=str(v))
                     print "2"
                     i = w.elements().index(opt)
                     print "3"
                     w.append(opt)
                     print "4"
                     del w[i - 1]
             except AttributeError, e:
                 print "error with", v
                 if type(v) == "IntType":
                     opt = w.element(_value=self.value)
                     i = w.elements().index(opt)
                     w.append(opt)
                     del w[i - 1]
                 else:
                     print e
             except Exception, e:
                 print e, type(e)
             pprint([e["_value"] for e in w.elements()])
    def widget(self, field, value, **attr):
        LookupWidget.widget_files()

        width = self.width or getattr(field, "widget_width", None)

        if not width:
            attr["_class"] = "span4"
        attr["_style"] = "height: 20px; margin-bottom: 14px;"
        if width:
            attr["_style"] += "width:%s;" % width

        wgt_default = MultipleOptionsWidget.widget(field, value, **attr)
        wgt_id = wgt_default.attributes.get("_id", "no_id")

        js = """
            jQuery(document).ready(function(){
                jQuery('#%(field_name)s').select2();
            });
            """ % {
            "field_name": wgt_id
        }
        jq_script = SCRIPT(js, _type="text/javascript")

        btn_new = ""
        if self.add_new:
            btn_new = A(
                I(_class="fa fa-plus-circle"),
                _href=self.add_new,
                _class="btn btn-small",
                _title=current.T("New record"),
                _style="margin-top: 0px; margin-left:3px;",
                **{"_data-toggle": "tooltip"}
            )

        wrapper = DIV(_class="LookupWidget")
        wrapper.components.extend([wgt_default, btn_new, jq_script])
        return wrapper
示例#9
0
    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)
示例#10
0
    def _create_widget(self):
        """
        Create either a single select widget or multiselect widget
        """
        if self.multi not in [None, False, 'False']:
            if self.orderby or self.rval:
                w = FilteredMultipleOptionsWidget.widget(
                    self.field,
                    self.value,
                    orderby=self.orderby,
                    multiple='multiple',
                    restricted=self.restricted,
                    rval=self.rval)
            else:
                w = MultipleOptionsWidget.widget(self.field, self.value)
            # place selected items at end of sortable select widget
            if self.sortable:
                print('trying to sort values =============')
                print('value is', self.value)
                try:
                    for v in self.value:
                        print('1')
                        opt = w.element(_value=str(v))
                        print('2')
                        i = w.elements().index(opt)
                        print('3')
                        w.append(opt)
                        print('4')
                        del w[i - 1]
                except AttributeError as e:
                    print('error with', v)
                    if type(v) == 'IntType':
                        opt = w.element(_value=self.value)
                        i = w.elements().index(opt)
                        w.append(opt)
                        del w[i - 1]
                    else:
                        print(e)
                except Exception as e:
                    print(e, type(e))
                pprint([elem['_value'] for elem in w.elements()])
        else:
            if self.orderby or self.rval or self.restrictor:
                w = FilteredOptionsWidget.widget(self.field,
                                                 self.value,
                                                 orderby=self.orderby,
                                                 restricted=self.restricted,
                                                 rval=self.rval)
            else:
                w = OptionsWidget.widget(self.field, self.value)

        w['_id'] = '{}_{}'.format(self.fieldset[0], self.fieldset[1])
        w['_name'] = self.fieldset[1]
        myclasses = 'plugin_ajaxselect '
        if self.multi not in [None, False, 'False']:
            myclasses += 'multiple '
        if self.restrictor not in [None, 'None', 'none']:
            myclasses += 'restrictor for_{} '.format(self.restrictor)
        if self.restricted not in [None, 'None', 'none']:
            myclasses += 'restricted by_{} '.format(self.restricted)
        w['_class'] = myclasses

        return w
示例#11
0
    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 "groupedopts-filter-widget" not in _class:
                attr["_class"] = "%s groupedopts-filter-widget" % _class
            w = S3GroupedOptionsWidget(
                options=options,
                multiple=True,
                cols=opts["cols"],
                size=opts["size"] or 12,
                help_field=opts["help_field"],
            )
            widget = w(dummy_field, values, **attr)

        return TAG[""](any_all, widget)