SP/web2py/applications/admin/models/plugin_statebutton.py
Saturneic 064f602b1a Add.
2018-10-25 23:33:13 +08:00

17 lines
735 B
Python

response.files.append(URL('static','plugin_statebutton/js/bootstrap-switch.js'))
response.files.append(URL('static','plugin_statebutton/css/bootstrap-switch.css'))
def stateWidget(field, value, data={'on-label':'Enabled', 'off-label':'Disabled', 'on':"primary", 'off':"default" }):
try:
fieldName = str(field).split('.')[1]
except:
fieldName = field
div = DIV(INPUT( _type='checkbox', _name='%s' % fieldName, _checked= 'checked' if value == 'true' else None, _value='true'),
_class='make-bootstrap-switch',
data=data)
script = SCRIPT("""
jQuery(".make-bootstrap-switch input[name='%s']").parent().bootstrapSwitch();
""" % fieldName)
return DIV(div, script)