def widget_radio(field, value): table = field.type[10:] widget = treeview(db, auth, table, checkbox='radio', key=field.name, selected=value) return widget
def widget_tree(field, value): db = current.globalenv['db'] auth = current.globalenv['auth'] if not value: value = [] if field.type[:14] == 'list:reference': table = field.type[15:] checkbox = 'checkbox' elif field.type[:9] == 'reference': table = field.type[10:] checkbox = 'radio' else: return None if table == 'auth_group': name = 'role' query = db[table].atype.belongs(['org', 'group', 'auth']) else: name = 'name' query = (db[table].id > 0) rows = db((db[table].parent == None) & query).select( orderby=db[table].display_order | db[table][name]) tr = TR() for row in rows: pnode = XML( str( INPUT(_type=checkbox, _name=field.name, _value=row.id, _checked=(row.id in value), _class='check_all')) + ' ' + row[name]) tree = treeview(db, auth, table, parent=row.id, depth=1, checkbox=checkbox, pnode=pnode, query=query, key=field.name, field=name, selected=value, orderby=db[table].display_order | db[table][name], tree=field.name + str(row.id)) tr.append(TD(tree)) script = '''<script type="text/javascript"> $(document).ready(function(){ $('.check_all').click(function(){ if ($(this).is(':checked')) { $(this).parent().find('input:checkbox').attr('checked', true); } else{ $(this).parent().find('input:checkbox').attr('checked', false); } }); }); </script>''' return DIV(XML(script), TABLE(tr))
def widget_checkbox(field, value): db = current.globalenv['db'] auth = current.globalenv['auth'] table = field.type[15:] widget = treeview(db, auth, table, checkbox='checkbox', key=field.name, selected=value) return widget
def widget_danh_muc(field, value): from plugin_app import treeview from plugin_cms import CmsModel cms = CmsModel() cms.define_folder() db = cms.db auth = cms.auth if not value: value = [] tr = TR() row = db.folder[246] pnode = XML( str( INPUT(_type='checkbox', _name=field.name, _value=row.id, _checked=(row.id in value), _class='check_all')) + ' ' + row.label) tree = treeview(db, auth, 'folder', parent=row.id, checkbox='checkbox', pnode=pnode, field='label', key=field.name, selected=value, orderby=db.folder.display_order | db.folder.name, tree=field.name + str(row.id)) tr.append(TD(tree)) script = '''<script type="text/javascript"> $(document).ready(function(){ $('.check_all').click(function(){ if ($(this).is(':checked')) { $(this).parent().find('input:checkbox').attr('checked', true); } else{ $(this).parent().find('input:checkbox').attr('checked', false); } }); }); </script>''' return DIV(XML(script), TABLE(tr))
def widget_folders(field, value): db = current.globalenv['db'] auth = current.globalenv['auth'] if not value: value = [] rows = db(db.folder.parent == None).select(orderby=db.folder.display_order | db.folder.name) tr = TR() for row in rows: pnode = XML( str( INPUT(_type='checkbox', _name=field.name, _value=row.id, _checked=(row.id in value), _class='check_all')) + ' ' + row.name) tree = treeview(db, auth, 'folder', parent=row.id, checkbox='checkbox', pnode=pnode, key=field.name, selected=value, orderby=db.folder.display_order | db.folder.name, tree=field.name + str(row.id)) tr.append(TD(tree)) script = '''<script type="text/javascript"> $(document).ready(function(){ $('.check_all').click(function(){ if ($(this).is(':checked')) { $(this).parent().find('input:checkbox').attr('checked', true); } else{ $(this).parent().find('input:checkbox').attr('checked', false); } }); }); </script>''' return DIV(XML(script), TABLE(tr))
def widget_org_tree(field, value): db = current.globalenv['dbprocess'] auth = current.globalenv['auth'] if not value: row = db(db.org.auth_group == auth.auth_org).select().first() if row: if not auth.has_membership(role='admin'): if current.request.function == 'create': if current.request.vars.procedure_id: from plugin_process import define_procedure procedure = define_procedure(db, auth) if procedure(current.request.vars.procedure_id): if procedure(current.request.vars.procedure_id ).type == 'out': db[field.tablename][ field.name].readable = False db[field.tablename][ field.name].writable = False db[field.tablename][ field.name].default = row.id return B(row.name) url = URL(r=current.request, c='plugin_app', f='get_signer', extension='load') ajax = "ajax('%s', ['org'], 'org_signer')" % (url) widget = treeview(db, auth, 'org', checkbox='checkbox', depth=2, key=field.name, selected=value, ajax=ajax, check='org_tree', orderby=db.org.display_order | db.org.name, tree=field.name) return widget