allow LOADing multiple grids, thanks Niphlod
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 2.3.0 (2012-12-11 20:49:33) rc1
|
Version 2.3.0 (2012-12-12 21:13:40) rc1
|
||||||
|
|||||||
+38
-21
@@ -1559,8 +1559,16 @@ class SQLFORM(FORM):
|
|||||||
return smart_query(fields, key)
|
return smart_query(fields, key)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def search_menu(fields, search_options=None):
|
def search_menu(fields,
|
||||||
|
search_options=None,
|
||||||
|
prefix='w2p'
|
||||||
|
):
|
||||||
T = current.T
|
T = current.T
|
||||||
|
panel_id='%s_query_panel' % prefix
|
||||||
|
fields_id='%s_query_fields' % prefix
|
||||||
|
keywords_id='%s_keywords' % prefix
|
||||||
|
field_id='%s_field' % prefix
|
||||||
|
value_id='%s_value' % prefix
|
||||||
search_options = search_options or {
|
search_options = search_options or {
|
||||||
'string': ['=', '!=', '<', '>', '<=', '>=', 'starts with', 'contains', 'in', 'not in'],
|
'string': ['=', '!=', '<', '>', '<=', '>=', 'starts with', 'contains', 'in', 'not in'],
|
||||||
'text': ['=', '!=', '<', '>', '<=', '>=', 'starts with', 'contains', 'in', 'not in'],
|
'text': ['=', '!=', '<', '>', '<=', '>=', 'starts with', 'contains', 'in', 'not in'],
|
||||||
@@ -1592,53 +1600,57 @@ class SQLFORM(FORM):
|
|||||||
value_input = SELECT(
|
value_input = SELECT(
|
||||||
OPTION(T("True"), _value="T"),
|
OPTION(T("True"), _value="T"),
|
||||||
OPTION(T("False"), _value="F"),
|
OPTION(T("False"), _value="F"),
|
||||||
_id="w2p_value_" + name)
|
_id="%s_%s" % (value_id,name))
|
||||||
else:
|
else:
|
||||||
value_input = INPUT(_type='text',
|
value_input = INPUT(_type='text',
|
||||||
_id="w2p_value_" + name,
|
_id="%s_%s" % (value_id,name),
|
||||||
_class=field.type)
|
_class=field.type)
|
||||||
new_button = INPUT(
|
new_button = INPUT(
|
||||||
_type="button", _value=T('New'), _class="btn",
|
_type="button", _value=T('New'), _class="btn",
|
||||||
_onclick="w2p_build_query('new','%s')" % field)
|
_onclick="%s_build_query('new','%s')" % (prefix,field))
|
||||||
and_button = INPUT(
|
and_button = INPUT(
|
||||||
_type="button", _value=T('And'), _class="btn",
|
_type="button", _value=T('And'), _class="btn",
|
||||||
_onclick="w2p_build_query('and','%s')" % field)
|
_onclick="%s_build_query('and','%s')" % (prefix, field))
|
||||||
or_button = INPUT(
|
or_button = INPUT(
|
||||||
_type="button", _value=T('Or'), _class="btn",
|
_type="button", _value=T('Or'), _class="btn",
|
||||||
_onclick="w2p_build_query('or','%s')" % field)
|
_onclick="%s_build_query('or','%s')" % (prefix, field))
|
||||||
close_button = INPUT(
|
close_button = INPUT(
|
||||||
_type="button", _value=T('Close'), _class="btn",
|
_type="button", _value=T('Close'), _class="btn",
|
||||||
_onclick="jQuery('#w2p_query_panel').slideUp()")
|
_onclick="jQuery('#%s').slideUp()" % panel_id)
|
||||||
|
|
||||||
criteria.append(DIV(
|
criteria.append(DIV(
|
||||||
operators, value_input, new_button,
|
operators, value_input, new_button,
|
||||||
and_button, or_button, close_button,
|
and_button, or_button, close_button,
|
||||||
_id='w2p_field_%s' % name,
|
_id='%s_%s' % (field_id, name),
|
||||||
_class='w2p_query_row hidden',
|
_class='w2p_query_row hidden',
|
||||||
_style='display:inline'))
|
_style='display:inline'))
|
||||||
|
|
||||||
criteria.insert(0, SELECT(
|
criteria.insert(0, SELECT(
|
||||||
_id="w2p_query_fields",
|
_id=fields_id,
|
||||||
_onchange="jQuery('.w2p_query_row').hide();jQuery('#w2p_field_'+jQuery('#w2p_query_fields').val().replace('.','-')).show();",
|
_onchange="jQuery('.w2p_query_row').hide();jQuery('#%s_'+jQuery('#%s').val().replace('.','-')).show();" % (field_id,fields_id),
|
||||||
_style='float:left',
|
_style='float:left',
|
||||||
*selectfields))
|
*selectfields))
|
||||||
|
|
||||||
fadd = SCRIPT("""
|
fadd = SCRIPT("""
|
||||||
jQuery('#w2p_query_panel input,#w2p_query_panel select').css(
|
jQuery('#%(fields_id)s input,#%(fields_id)s select').css(
|
||||||
'width','auto');
|
'width','auto');
|
||||||
jQuery(function(){web2py_ajax_fields('#w2p_query_panel');});
|
jQuery(function(){web2py_ajax_fields('#%(fields_id)s');});
|
||||||
function w2p_build_query(aggregator,a) {
|
function %(prefix)s_build_query(aggregator,a) {
|
||||||
var b=a.replace('.','-');
|
var b=a.replace('.','-');
|
||||||
var option = jQuery('#w2p_field_'+b+' select').val();
|
var option = jQuery('#%(field_id)s_'+b+' select').val();
|
||||||
var value = jQuery('#w2p_value_'+b).val().replace('"','\\\\"');
|
var value = jQuery('#%(value_id)s_'+b).val().replace('"','\\\\"');
|
||||||
var s=a+' '+option+' "'+value+'"';
|
var s=a+' '+option+' "'+value+'"';
|
||||||
var k=jQuery('#web2py_keywords');
|
var k=jQuery('#%(keywords_id)s');
|
||||||
var v=k.val();
|
var v=k.val();
|
||||||
if(aggregator=='new') k.val(s); else k.val((v?(v+' '+ aggregator +' '):'')+s);
|
if(aggregator=='new') k.val(s); else k.val((v?(v+' '+ aggregator +' '):'')+s);
|
||||||
}
|
}
|
||||||
""")
|
""" % dict(
|
||||||
|
prefix=prefix,fields_id=fields_id,keywords_id=keywords_id,
|
||||||
|
field_id=field_id,value_id=value_id
|
||||||
|
)
|
||||||
|
)
|
||||||
return CAT(
|
return CAT(
|
||||||
DIV(_id="w2p_query_panel", _class='hidden', *criteria), fadd)
|
DIV(_id=panel_id, _class='hidden', *criteria), fadd)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def grid(query,
|
def grid(query,
|
||||||
@@ -1993,13 +2005,18 @@ class SQLFORM(FORM):
|
|||||||
if isinstance(search_widget, dict):
|
if isinstance(search_widget, dict):
|
||||||
search_widget = search_widget[tablename]
|
search_widget = search_widget[tablename]
|
||||||
if search_widget == 'default':
|
if search_widget == 'default':
|
||||||
search_menu = SQLFORM.search_menu(sfields)
|
prefix = formname == 'web2py_grid' and 'w2p' or 'w2p_%s' % formname
|
||||||
|
search_menu = SQLFORM.search_menu(sfields, prefix=prefix)
|
||||||
|
spanel_id = '%s_query_fields' % prefix
|
||||||
|
sfields_id = '%s_query_panel' % prefix
|
||||||
|
skeywords_id = '%s_keywords' % prefix
|
||||||
search_widget = lambda sfield, url: CAT(FORM(
|
search_widget = lambda sfield, url: CAT(FORM(
|
||||||
INPUT(_name='keywords', _value=request.vars.keywords,
|
INPUT(_name='keywords', _value=request.vars.keywords,
|
||||||
_id='web2py_keywords', _onfocus="jQuery('#w2p_query_fields').change();jQuery('#w2p_query_panel').slideDown();"),
|
_id=skeywords_id,
|
||||||
|
_onfocus="jQuery('#%s').change();jQuery('#%s').slideDown();" % (spanel_id, sfields_id)),
|
||||||
INPUT(_type='submit', _value=T('Search'), _class="btn"),
|
INPUT(_type='submit', _value=T('Search'), _class="btn"),
|
||||||
INPUT(_type='submit', _value=T('Clear'), _class="btn",
|
INPUT(_type='submit', _value=T('Clear'), _class="btn",
|
||||||
_onclick="jQuery('#web2py_keywords').val('');"),
|
_onclick="jQuery('#%s').val('');" % skeywords_id),
|
||||||
_method="GET", _action=url), search_menu)
|
_method="GET", _action=url), search_menu)
|
||||||
form = search_widget and search_widget(sfields, url()) or ''
|
form = search_widget and search_widget(sfields, url()) or ''
|
||||||
console.append(add)
|
console.append(add)
|
||||||
|
|||||||
Reference in New Issue
Block a user