simplified grid console logic and style
This commit is contained in:
@@ -1 +1 @@
|
||||
Version 2.0.7 (2012-09-04 15:32:23) stable
|
||||
Version 2.0.7 (2012-09-04 17:58:46) stable
|
||||
|
||||
+32
-23
@@ -1498,11 +1498,10 @@ class SQLFORM(FORM):
|
||||
selectfields = []
|
||||
for field in fields:
|
||||
name = str(field).replace('.','-')
|
||||
criterion = []
|
||||
options = search_options.get(field.type,None)
|
||||
if options:
|
||||
label = isinstance(field.label,str) and T(field.label) or field.label
|
||||
selectfields.append((str(field),label))
|
||||
selectfields.append(OPTION(label, _value=str(field)))
|
||||
operators = SELECT(*[T(option) for option in options])
|
||||
if field.type=='boolean':
|
||||
value_input = SELECT(
|
||||
@@ -1510,30 +1509,39 @@ class SQLFORM(FORM):
|
||||
OPTION(T("False"),_value="F"),
|
||||
_id="w2p_value_"+name)
|
||||
else:
|
||||
value_input = INPUT(_type='text',_id="w2p_value_"+name,
|
||||
value_input = INPUT(_type='text',
|
||||
_id="w2p_value_"+name,
|
||||
_class=field.type)
|
||||
new_button = INPUT(
|
||||
_type="button", _value=T('New'),_class="btn",
|
||||
_onclick="w2p_build_query('new','"+str(field)+"')")
|
||||
_onclick="w2p_build_query('new','%s')" % field)
|
||||
and_button = INPUT(
|
||||
_type="button", _value=T('And'),_class="btn",
|
||||
_onclick="w2p_build_query('and','"+str(field)+"')")
|
||||
_onclick="w2p_build_query('and','%s')" % field)
|
||||
or_button = INPUT(
|
||||
_type="button", _value=T('Or'),_class="btn",
|
||||
_onclick="w2p_build_query('or','"+str(field)+"')")
|
||||
_onclick="w2p_build_query('or','%s')" % field)
|
||||
close_button = INPUT(
|
||||
_type="button", _value=T('Close'),_class="btn",
|
||||
_onclick="jQuery('#w2p_query_panel').slideUp()")
|
||||
|
||||
criterion.extend([operators,value_input,new_button,and_button,or_button])
|
||||
criteria.append(DIV(criterion, _id='w2p_field_%s' % name,
|
||||
_class='w2p_query_row hidden'))
|
||||
criteria.append(DIV(
|
||||
operators,value_input,new_button,
|
||||
and_button,or_button,close_button,
|
||||
_id='w2p_field_%s' % name,
|
||||
_class='w2p_query_row hidden',
|
||||
_style='display:inline'))
|
||||
|
||||
criteria.insert(0,SELECT(
|
||||
_id="w2p_query_fields",
|
||||
_onchange="jQuery('.w2p_query_row').hide();jQuery('#w2p_field_'+jQuery('#w2p_query_fields').val().replace('.','-')).show();",
|
||||
*[OPTION(label, _value=fname) for fname,label in selectfields]))
|
||||
_style='float:left',
|
||||
*selectfields))
|
||||
|
||||
fadd = SCRIPT("""
|
||||
jQuery('#w2p_query_panel input,#w2p_query_panel select').css(
|
||||
'width','auto').css('float','left');
|
||||
jQuery('#w2p_query_panel input,#w2p_query_panel select').css('width','auto');
|
||||
jQuery(function(){web2py_ajax_fields('#w2p_query_panel');});
|
||||
function w2p_build_query(aggregator,a){
|
||||
function w2p_build_query(aggregator,a) {
|
||||
var b=a.replace('.','-');
|
||||
var option = jQuery('#w2p_field_'+b+' select').val();
|
||||
var value = jQuery('#w2p_value_'+b).val().replace('"','\\\\"');
|
||||
@@ -1541,10 +1549,11 @@ class SQLFORM(FORM):
|
||||
var k=jQuery('#web2py_keywords');
|
||||
var v=k.val();
|
||||
if(aggregator=='new') k.val(s); else k.val((v?(v+' '+ aggregator +' '):'')+s);
|
||||
jQuery('#w2p_query_panel').slideUp();
|
||||
}
|
||||
""")
|
||||
return CAT(DIV(_id="w2p_query_panel",_class='hidden',*criteria),fadd)
|
||||
return CAT(
|
||||
DIV(_id="w2p_query_panel",_class='hidden',*criteria),fadd)
|
||||
|
||||
|
||||
|
||||
@staticmethod
|
||||
@@ -1855,12 +1864,6 @@ class SQLFORM(FORM):
|
||||
|
||||
session['_web2py_grid_referrer_'+formname] = url2(vars=request.vars)
|
||||
console = DIV(_class='web2py_console %(header)s %(cornertop)s' % ui)
|
||||
if create:
|
||||
console.append(gridbutton(
|
||||
buttonclass='buttonadd',
|
||||
buttontext='Add',
|
||||
buttonurl=url(args=['new',tablename])))
|
||||
|
||||
error = None
|
||||
if searchable:
|
||||
sfields = reduce(lambda a,b:a+b,
|
||||
@@ -1869,13 +1872,13 @@ class SQLFORM(FORM):
|
||||
search_widget = search_widget[tablename]
|
||||
if search_widget=='default':
|
||||
search_menu = SQLFORM.search_menu(sfields)
|
||||
search_widget = lambda sfield, url: FORM(
|
||||
search_widget = lambda sfield, url: DIV(FORM(
|
||||
INPUT(_name='keywords',_value=request.vars.keywords,
|
||||
_id='web2py_keywords',_onfocus="jQuery('#w2p_query_fields').change();jQuery('#w2p_query_panel').slideDown();"),
|
||||
INPUT(_type='submit',_value=T('Search'),_class="btn"),
|
||||
INPUT(_type='submit',_value=T('Clear'),_class="btn",
|
||||
_onclick="jQuery('#web2py_keywords').val('');"),
|
||||
search_menu,_method="GET",_action=url)
|
||||
_method="GET",_action=url),search_menu)
|
||||
form = search_widget and search_widget(sfields,url()) or ''
|
||||
console.append(form)
|
||||
keywords = request.vars.get('keywords','')
|
||||
@@ -1889,6 +1892,12 @@ class SQLFORM(FORM):
|
||||
error = T('Invalid query')
|
||||
else:
|
||||
subquery = None
|
||||
if create:
|
||||
console.append(gridbutton(
|
||||
buttonclass='buttonadd',
|
||||
buttontext='Add',
|
||||
buttonurl=url(args=['new',tablename])))
|
||||
|
||||
if subquery:
|
||||
dbset = dbset(subquery)
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user