def widget(self, field, value, **attributes): attr = OptionsWidget._attributes(field, {'value': value}, **attributes) opts = [OPTION('')] + [ OPTGROUP(_label=group, *[OPTION(v, _value=k) for (k, v) in options.items()]) for group, options in self.groups.items() ] #d_id = "multiselect-" + str(uuid.uuid4())[:8] #wrapper = DIV(_id=d_id) wrapper = SELECT(*opts, **attr) #inp = SELECT(*opts, **attr) scr = SCRIPT('$(".selectpicker").selectpicker();') #opts = 'minLength: %s, delay: %s, disabled: %s' % \ # (self.min_length,self.delay,str(self.disabled).lower()) #if self.url: #scr = SCRIPT('jQuery("#%s input").autocomplete({source: "%s", %s});' % \ # (d_id, self.url, opts)) #else: # rows = f._db(f._table['id']>0).select(f,distinct=True) # itms = [str(t[f.name]) for t in rows] # scr = SCRIPT('var data = "%s".split("|");'\ # 'jQuery("#%s input").autocomplete({source: data, %s});' % \ # ("|".join(itms),d_id,opts)) #wrapper.append(inp) wrapper.append(scr) 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 widget(self, field, value,**attributes): attr = OptionsWidget._attributes(field, {'value':value}, **attributes) opts = [OPTION('')] + [ OPTGROUP( _label=group, *[OPTION(v, _value=k) for (k, v) in options.items()]) for group, options in self.groups.items() ] #d_id = "multiselect-" + str(uuid.uuid4())[:8] #wrapper = DIV(_id=d_id) wrapper = SELECT(*opts, **attr) #inp = SELECT(*opts, **attr) scr = SCRIPT('$(".selectpicker").selectpicker();') #opts = 'minLength: %s, delay: %s, disabled: %s' % \ # (self.min_length,self.delay,str(self.disabled).lower()) #if self.url: #scr = SCRIPT('jQuery("#%s input").autocomplete({source: "%s", %s});' % \ # (d_id, self.url, opts)) #else: # rows = f._db(f._table['id']>0).select(f,distinct=True) # itms = [str(t[f.name]) for t in rows] # scr = SCRIPT('var data = "%s".split("|");'\ # 'jQuery("#%s input").autocomplete({source: data, %s});' % \ # ("|".join(itms),d_id,opts)) #wrapper.append(inp) wrapper.append(scr) 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 widget(field, value, **attributes): """ generates a TABLE tag, including INPUT checkboxes (multiple allowed) see also: :meth:`FormWidget.widget` """ # was values = re.compile('[\w\-:]+').findall(str(value)) if isinstance(value, (list, tuple)): values = [str(v) for v in value] else: values = [str(value)] attr = OptionsWidget._attributes(field, {}, **attributes) requires = field.requires if not isinstance(requires, (list, tuple)): requires = [requires] if requires: if hasattr(requires[0], 'options'): options = requires[0].options() else: raise SyntaxError('widget cannot determine options of %s' % field) options = [(k, v) for k, v in options if k != ''] opts = [] cols = attributes.get('cols', 1) totals = len(options) mods = totals % cols rows = totals / cols if mods: rows += 1 for r_index in range(rows): tds = [] for k, v in options[r_index * cols:(r_index + 1) * cols]: if k in values: r_value = k else: r_value = [] tds.append( LI( INPUT(_type='checkbox', _id='%s%s' % (field.name, k), _name=field.name, requires=attr.get('requires', None), hideerror=True, _value=k, value=r_value), LABEL(v, _for='%s%s' % (field.name, k)))) opts.append(UL(tds, _style='list-style-type: none;')) if opts: opts[-1][0][0]['hideerror'] = False return DIV(*opts, **attr)
def widget(field, value, **attributes): """ generates a TABLE tag, including INPUT checkboxes (multiple allowed) see also: :meth:`FormWidget.widget` """ # was values = re.compile('[\w\-:]+').findall(str(value)) if isinstance(value, (list, tuple)): values = [str(v) for v in value] else: values = [str(value)] attr = OptionsWidget._attributes(field, {}, **attributes) requires = field.requires if not isinstance(requires, (list, tuple)): requires = [requires] if requires: if hasattr(requires[0], 'options'): options = requires[0].options() else: raise SyntaxError('widget cannot determine options of %s' % field) options = [(k, v) for k, v in options if k != ''] opts = [] cols = attributes.get('cols', 1) totals = len(options) mods = totals % cols rows = totals / cols if mods: rows += 1 for r_index in range(rows): tds = [] for k, v in options[r_index * cols:(r_index + 1) * cols]: if k in values: r_value = k else: r_value = [] tds.append(LI(INPUT(_type='checkbox', _id='%s%s' % (field.name, k), _name=field.name, requires=attr.get('requires', None), hideerror=True, _value=k, value=r_value), LABEL(v, _for='%s%s' % (field.name, k)))) opts.append(UL(tds, _style='list-style-type: none;')) if opts: opts[-1][0][0]['hideerror'] = False return DIV(*opts, **attr)
def widget(field, value, **attributes): """ generates a TABLE tag, including INPUT radios (only 1 option allowed) see also: :meth:`FormWidget.widget` """ attr = OptionsWidget._attributes(field, {}, **attributes) requires = field.requires if not isinstance(requires, (list, tuple)): requires = [requires] if requires: if hasattr(requires[0], 'options'): options = requires[0].options() else: raise SyntaxError('widget cannot determine options of %s' % field) options = [(k, v) for k, v in options if str(v)] opts = [] cols = attributes.get('cols', 1) totals = len(options) mods = totals % cols rows = totals / cols if mods: rows += 1 for r_index in range(rows): tds = [] for k, v in options[r_index * cols:(r_index + 1) * cols]: checked = {'_checked': 'checked'} if k == value else {} tds.append( LI( INPUT(_type='radio', _id='%s%s' % (field.name, k), _name=field.name, requires=attr.get('requires', None), hideerror=True, _value=k, value=value, **checked), LABEL(v, _for='%s%s' % (field.name, k)))) opts.append(UL(tds, _style='list-style-type: none;')) if opts: opts[-1][0][0]['hideerror'] = False return DIV(*opts, **attr)
def widget(field, value, **attributes): """ generates a TABLE tag, including INPUT radios (only 1 option allowed) see also: :meth:`FormWidget.widget` """ attr = OptionsWidget._attributes(field, {}, **attributes) requires = field.requires if not isinstance(requires, (list, tuple)): requires = [requires] if requires: if hasattr(requires[0], 'options'): options = requires[0].options() else: raise SyntaxError('widget cannot determine options of %s' % field) options = [(k, v) for k, v in options if str(v)] opts = [] cols = attributes.get('cols', 1) totals = len(options) mods = totals % cols rows = totals / cols if mods: rows += 1 for r_index in range(rows): tds = [] for k, v in options[r_index * cols:(r_index + 1) * cols]: checked = {'_checked': 'checked'} if k == value else {} tds.append(LI(INPUT(_type='radio', _id='%s%s' % (field.name, k), _name=field.name, requires=attr.get('requires', None), hideerror=True, _value=k, value=value, **checked ), LABEL(v, _for='%s%s' % (field.name, k)))) opts.append(UL(tds, _style='list-style-type: none;')) if opts: opts[-1][0][0]['hideerror'] = False return DIV(*opts, **attr)