grid refcator patch for ajax, thanks Niphlod
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 2.7.1-stable+timestamp.2013.10.04.21.30.48
|
Version 2.7.1-stable+timestamp.2013.10.05.08.50.58
|
||||||
|
|||||||
@@ -264,16 +264,6 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
trap_link: function (target) {
|
|
||||||
$('#' + target + ' a.w2p_trap').each(function (i) {
|
|
||||||
var link = $(this);
|
|
||||||
link.click(function (e) {
|
|
||||||
web2py.hide_flash();
|
|
||||||
web2py.ajax_page('get', link.attr('href'), [], target, $(this));
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
ajax_page: function (method, action, data, target, element) {
|
ajax_page: function (method, action, data, target, element) {
|
||||||
/* element is a new parameter, but should be put be put in front */
|
/* element is a new parameter, but should be put be put in front */
|
||||||
if(element == undefined) element = $(document);
|
if(element == undefined) element = $(document);
|
||||||
@@ -307,7 +297,6 @@
|
|||||||
web2py.fire(element, 'ajax:complete', [xhr, status], target);
|
web2py.fire(element, 'ajax:complete', [xhr, status], target);
|
||||||
web2py.updatePage(xhr, target); /* Parse and load the html received */
|
web2py.updatePage(xhr, target); /* Parse and load the html received */
|
||||||
web2py.trap_form(action, target);
|
web2py.trap_form(action, target);
|
||||||
web2py.trap_link(target);
|
|
||||||
web2py.ajax_init('#' + target);
|
web2py.ajax_init('#' + target);
|
||||||
web2py.after_ajax(xhr);
|
web2py.after_ajax(xhr);
|
||||||
}
|
}
|
||||||
@@ -692,10 +681,8 @@ collapse = jQuery.web2py.collapse;
|
|||||||
fade = jQuery.web2py.fade;
|
fade = jQuery.web2py.fade;
|
||||||
|
|
||||||
/* internals - shouldn't be needed
|
/* internals - shouldn't be needed
|
||||||
|
|
||||||
web2py_ajax_init = jQuery.web2py.ajax_init;
|
web2py_ajax_init = jQuery.web2py.ajax_init;
|
||||||
web2py_event_handlers = jQuery.web2py.event_handlers;
|
web2py_event_handlers = jQuery.web2py.event_handlers;
|
||||||
|
|
||||||
web2py_trap_link = jQuery.web2py.trap_link;
|
web2py_trap_link = jQuery.web2py.trap_link;
|
||||||
web2py_calc_entropy = jQuery.web2py.calc_entropy;
|
web2py_calc_entropy = jQuery.web2py.calc_entropy;
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -264,16 +264,6 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
trap_link: function (target) {
|
|
||||||
$('#' + target + ' a.w2p_trap').each(function (i) {
|
|
||||||
var link = $(this);
|
|
||||||
link.click(function (e) {
|
|
||||||
web2py.hide_flash();
|
|
||||||
web2py.ajax_page('get', link.attr('href'), [], target, $(this));
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
ajax_page: function (method, action, data, target, element) {
|
ajax_page: function (method, action, data, target, element) {
|
||||||
/* element is a new parameter, but should be put be put in front */
|
/* element is a new parameter, but should be put be put in front */
|
||||||
if(element == undefined) element = $(document);
|
if(element == undefined) element = $(document);
|
||||||
@@ -307,7 +297,6 @@
|
|||||||
web2py.fire(element, 'ajax:complete', [xhr, status], target);
|
web2py.fire(element, 'ajax:complete', [xhr, status], target);
|
||||||
web2py.updatePage(xhr, target); /* Parse and load the html received */
|
web2py.updatePage(xhr, target); /* Parse and load the html received */
|
||||||
web2py.trap_form(action, target);
|
web2py.trap_form(action, target);
|
||||||
web2py.trap_link(target);
|
|
||||||
web2py.ajax_init('#' + target);
|
web2py.ajax_init('#' + target);
|
||||||
web2py.after_ajax(xhr);
|
web2py.after_ajax(xhr);
|
||||||
}
|
}
|
||||||
@@ -692,10 +681,8 @@ collapse = jQuery.web2py.collapse;
|
|||||||
fade = jQuery.web2py.fade;
|
fade = jQuery.web2py.fade;
|
||||||
|
|
||||||
/* internals - shouldn't be needed
|
/* internals - shouldn't be needed
|
||||||
|
|
||||||
web2py_ajax_init = jQuery.web2py.ajax_init;
|
web2py_ajax_init = jQuery.web2py.ajax_init;
|
||||||
web2py_event_handlers = jQuery.web2py.event_handlers;
|
web2py_event_handlers = jQuery.web2py.event_handlers;
|
||||||
|
|
||||||
web2py_trap_link = jQuery.web2py.trap_link;
|
web2py_trap_link = jQuery.web2py.trap_link;
|
||||||
web2py_calc_entropy = jQuery.web2py.calc_entropy;
|
web2py_calc_entropy = jQuery.web2py.calc_entropy;
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -264,16 +264,6 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
trap_link: function (target) {
|
|
||||||
$('#' + target + ' a.w2p_trap').each(function (i) {
|
|
||||||
var link = $(this);
|
|
||||||
link.click(function (e) {
|
|
||||||
web2py.hide_flash();
|
|
||||||
web2py.ajax_page('get', link.attr('href'), [], target, $(this));
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
ajax_page: function (method, action, data, target, element) {
|
ajax_page: function (method, action, data, target, element) {
|
||||||
/* element is a new parameter, but should be put be put in front */
|
/* element is a new parameter, but should be put be put in front */
|
||||||
if(element == undefined) element = $(document);
|
if(element == undefined) element = $(document);
|
||||||
@@ -307,7 +297,6 @@
|
|||||||
web2py.fire(element, 'ajax:complete', [xhr, status], target);
|
web2py.fire(element, 'ajax:complete', [xhr, status], target);
|
||||||
web2py.updatePage(xhr, target); /* Parse and load the html received */
|
web2py.updatePage(xhr, target); /* Parse and load the html received */
|
||||||
web2py.trap_form(action, target);
|
web2py.trap_form(action, target);
|
||||||
web2py.trap_link(target);
|
|
||||||
web2py.ajax_init('#' + target);
|
web2py.ajax_init('#' + target);
|
||||||
web2py.after_ajax(xhr);
|
web2py.after_ajax(xhr);
|
||||||
}
|
}
|
||||||
@@ -692,10 +681,8 @@ collapse = jQuery.web2py.collapse;
|
|||||||
fade = jQuery.web2py.fade;
|
fade = jQuery.web2py.fade;
|
||||||
|
|
||||||
/* internals - shouldn't be needed
|
/* internals - shouldn't be needed
|
||||||
|
|
||||||
web2py_ajax_init = jQuery.web2py.ajax_init;
|
web2py_ajax_init = jQuery.web2py.ajax_init;
|
||||||
web2py_event_handlers = jQuery.web2py.event_handlers;
|
web2py_event_handlers = jQuery.web2py.event_handlers;
|
||||||
|
|
||||||
web2py_trap_link = jQuery.web2py.trap_link;
|
web2py_trap_link = jQuery.web2py.trap_link;
|
||||||
web2py_calc_entropy = jQuery.web2py.calc_entropy;
|
web2py_calc_entropy = jQuery.web2py.calc_entropy;
|
||||||
*/
|
*/
|
||||||
|
|||||||
+30
-19
@@ -45,11 +45,6 @@ except ImportError:
|
|||||||
table_field = re.compile('[\w_]+\.[\w_]+')
|
table_field = re.compile('[\w_]+\.[\w_]+')
|
||||||
widget_class = re.compile('^\w*')
|
widget_class = re.compile('^\w*')
|
||||||
|
|
||||||
|
|
||||||
def trap_class(_class=None, trap=True):
|
|
||||||
return (trap and 'w2p_trap' or '') + (_class and ' ' + _class or '')
|
|
||||||
|
|
||||||
|
|
||||||
def represent(field, value, record):
|
def represent(field, value, record):
|
||||||
f = field.represent
|
f = field.represent
|
||||||
if not callable(f):
|
if not callable(f):
|
||||||
@@ -1897,7 +1892,8 @@ class SQLFORM(FORM):
|
|||||||
callback=callback,
|
callback=callback,
|
||||||
delete=delete,
|
delete=delete,
|
||||||
noconfirm=noconfirm,
|
noconfirm=noconfirm,
|
||||||
_class=trap_class(ui.get('button'), trap))
|
_class=ui.get('button'),
|
||||||
|
cid=request.cid)
|
||||||
else:
|
else:
|
||||||
return A(SPAN(_class=ui.get(buttonclass)),
|
return A(SPAN(_class=ui.get(buttonclass)),
|
||||||
_href=buttonurl,
|
_href=buttonurl,
|
||||||
@@ -1905,7 +1901,8 @@ class SQLFORM(FORM):
|
|||||||
delete=delete,
|
delete=delete,
|
||||||
noconfirm=noconfirm,
|
noconfirm=noconfirm,
|
||||||
_title=T(buttontext),
|
_title=T(buttontext),
|
||||||
_class=trap_class(ui.get('buttontext'), trap))
|
_class=ui.get('buttontext'),
|
||||||
|
cid=request.cid)
|
||||||
|
|
||||||
dbset = db(query,ignore_common_filters=ignore_common_filters)
|
dbset = db(query,ignore_common_filters=ignore_common_filters)
|
||||||
tablenames = db._adapter.tables(dbset.query)
|
tablenames = db._adapter.tables(dbset.query)
|
||||||
@@ -2057,7 +2054,22 @@ class SQLFORM(FORM):
|
|||||||
if ondelete:
|
if ondelete:
|
||||||
ondelete(table, request.args[-1])
|
ondelete(table, request.args[-1])
|
||||||
record.delete_record()
|
record.delete_record()
|
||||||
redirect(referrer, client_side=client_side_delete)
|
if request.ajax:
|
||||||
|
#this means javascript is enabled, so we don't need to do
|
||||||
|
#a redirect
|
||||||
|
if not client_side_delete:
|
||||||
|
#if it's an ajax request and we don't need to reload the
|
||||||
|
#entire page, let's just inform that there have been no
|
||||||
|
#exceptions and don't regenerate the grid
|
||||||
|
raise HTTP(200)
|
||||||
|
else:
|
||||||
|
#if it's requested that the grid gets reloaded on delete
|
||||||
|
#on ajax, the redirect should be on the original location
|
||||||
|
newloc = request.env.http_web2py_component_location
|
||||||
|
redirect(newloc, client_side=client_side_delete)
|
||||||
|
else:
|
||||||
|
#we need to do a redirect because javascript is not enabled
|
||||||
|
redirect(referrer, client_side=client_side_delete)
|
||||||
|
|
||||||
exportManager = dict(
|
exportManager = dict(
|
||||||
csv_with_hidden_cols=(ExporterCSV, 'CSV (hidden cols)'),
|
csv_with_hidden_cols=(ExporterCSV, 'CSV (hidden cols)'),
|
||||||
@@ -2221,7 +2233,7 @@ class SQLFORM(FORM):
|
|||||||
marker = sorter_icons[1]
|
marker = sorter_icons[1]
|
||||||
header = A(header, marker, _href=url(vars=dict(
|
header = A(header, marker, _href=url(vars=dict(
|
||||||
keywords=request.vars.keywords or '',
|
keywords=request.vars.keywords or '',
|
||||||
order=key)), _class=trap_class())
|
order=key)), cid=request.cid)
|
||||||
headcols.append(TH(header, _class=ui.get('default')))
|
headcols.append(TH(header, _class=ui.get('default')))
|
||||||
|
|
||||||
toadd = []
|
toadd = []
|
||||||
@@ -2269,7 +2281,6 @@ class SQLFORM(FORM):
|
|||||||
cacheable=True,*table_fields)
|
cacheable=True,*table_fields)
|
||||||
next_cursor = dbset._db.get('_lastcursor', None)
|
next_cursor = dbset._db.get('_lastcursor', None)
|
||||||
else:
|
else:
|
||||||
# print('table_fields: %s' %([f_.name for f_ in table_fields],))
|
|
||||||
rows = dbset.select(left=left,orderby=orderby,
|
rows = dbset.select(left=left,orderby=orderby,
|
||||||
groupby=groupby,limitby=limitby,
|
groupby=groupby,limitby=limitby,
|
||||||
cacheable=True,*table_fields)
|
cacheable=True,*table_fields)
|
||||||
@@ -2303,7 +2314,7 @@ class SQLFORM(FORM):
|
|||||||
if order: d['order']=order
|
if order: d['order']=order
|
||||||
if request.vars.keywords: d['keywords']=request.vars.keywords
|
if request.vars.keywords: d['keywords']=request.vars.keywords
|
||||||
paginator.append(LI(
|
paginator.append(LI(
|
||||||
A('next',_href=url(vars=d),_class=trap_class())))
|
A('next',_href=url(vars=d),cid=request.cid)))
|
||||||
elif paginate and paginate<nrows:
|
elif paginate and paginate<nrows:
|
||||||
npages, reminder = divmod(nrows, paginate)
|
npages, reminder = divmod(nrows, paginate)
|
||||||
if reminder:
|
if reminder:
|
||||||
@@ -2319,7 +2330,7 @@ class SQLFORM(FORM):
|
|||||||
d['order'] = order
|
d['order'] = order
|
||||||
if request.vars.keywords:
|
if request.vars.keywords:
|
||||||
d['keywords'] = request.vars.keywords
|
d['keywords'] = request.vars.keywords
|
||||||
return A(name, _href=url(vars=d), _class=trap_class())
|
return A(name, _href=url(vars=d), cid=request.cid)
|
||||||
NPAGES = 5 # window is 2*NPAGES
|
NPAGES = 5 # window is 2*NPAGES
|
||||||
if page > NPAGES + 1:
|
if page > NPAGES + 1:
|
||||||
paginator.append(LI(self_link('<<', 0)))
|
paginator.append(LI(self_link('<<', 0)))
|
||||||
@@ -2329,7 +2340,7 @@ class SQLFORM(FORM):
|
|||||||
for p in pages:
|
for p in pages:
|
||||||
if p == page:
|
if p == page:
|
||||||
paginator.append(LI(A(p + 1, _onclick='return false'),
|
paginator.append(LI(A(p + 1, _onclick='return false'),
|
||||||
_class=trap_class('current')))
|
_class='current'))
|
||||||
else:
|
else:
|
||||||
paginator.append(LI(self_link(p + 1, p)))
|
paginator.append(LI(self_link(p + 1, p)))
|
||||||
if page < npages - NPAGES:
|
if page < npages - NPAGES:
|
||||||
@@ -2598,13 +2609,13 @@ class SQLFORM(FORM):
|
|||||||
name = format(db[referee],record)
|
name = format(db[referee],record)
|
||||||
breadcrumbs.append(
|
breadcrumbs.append(
|
||||||
LI(A(T(db[referee]._plural),
|
LI(A(T(db[referee]._plural),
|
||||||
_class=trap_class(),
|
cid=request.cid,
|
||||||
_href=url()),
|
_href=url()),
|
||||||
SPAN(divider, _class='divider'),
|
SPAN(divider, _class='divider'),
|
||||||
_class='w2p_grid_breadcrumb_elem'))
|
_class='w2p_grid_breadcrumb_elem'))
|
||||||
if kwargs.get('details', True):
|
if kwargs.get('details', True):
|
||||||
breadcrumbs.append(
|
breadcrumbs.append(
|
||||||
LI(A(name, _class=trap_class(),
|
LI(A(name, cid=request.cid,
|
||||||
_href=url(args=['view', referee, id])),
|
_href=url(args=['view', referee, id])),
|
||||||
SPAN(divider, _class='divider'),
|
SPAN(divider, _class='divider'),
|
||||||
_class='w2p_grid_breadcrumb_elem'))
|
_class='w2p_grid_breadcrumb_elem'))
|
||||||
@@ -2617,7 +2628,7 @@ class SQLFORM(FORM):
|
|||||||
# if isinstance(linked_tables, dict):
|
# if isinstance(linked_tables, dict):
|
||||||
# linked_tables = linked_tables.get(table._tablename, [])
|
# linked_tables = linked_tables.get(table._tablename, [])
|
||||||
if linked_tables is None or referee in linked_tables:
|
if linked_tables is None or referee in linked_tables:
|
||||||
field.represent = lambda id, r=None, referee=referee, rep=field.represent: A(callable(rep) and rep(id) or id, _class=trap_class(), _href=url(args=['view', referee, id]))
|
field.represent = lambda id, r=None, referee=referee, rep=field.represent: A(callable(rep) and rep(id) or id, cid=request.cid, _href=url(args=['view', referee, id]))
|
||||||
except (KeyError, ValueError, TypeError):
|
except (KeyError, ValueError, TypeError):
|
||||||
redirect(URL(args=table._tablename))
|
redirect(URL(args=table._tablename))
|
||||||
if nargs == len(args) + 1:
|
if nargs == len(args) + 1:
|
||||||
@@ -2668,7 +2679,7 @@ class SQLFORM(FORM):
|
|||||||
args0 = tablename + '.' + fieldname
|
args0 = tablename + '.' + fieldname
|
||||||
links.append(
|
links.append(
|
||||||
lambda row, t=t, nargs=nargs, args0=args0:
|
lambda row, t=t, nargs=nargs, args0=args0:
|
||||||
A(SPAN(t), _class=trap_class(), _href=url(
|
A(SPAN(t), cid=request.cid, _href=url(
|
||||||
args=[args0, row[id_field_name]])))
|
args=[args0, row[id_field_name]])))
|
||||||
|
|
||||||
grid = SQLFORM.grid(query, args=request.args[:nargs], links=links,
|
grid = SQLFORM.grid(query, args=request.args[:nargs], links=links,
|
||||||
@@ -2679,7 +2690,7 @@ class SQLFORM(FORM):
|
|||||||
header = table._plural
|
header = table._plural
|
||||||
next = grid.create_form or grid.update_form or grid.view_form
|
next = grid.create_form or grid.update_form or grid.view_form
|
||||||
breadcrumbs.append(LI(
|
breadcrumbs.append(LI(
|
||||||
A(T(header), _class=trap_class(),_href=url()),
|
A(T(header), cid=request.cid,_href=url()),
|
||||||
SPAN(divider, _class='divider') if next else '',
|
SPAN(divider, _class='divider') if next else '',
|
||||||
_class='active w2p_grid_breadcrumb_elem'))
|
_class='active w2p_grid_breadcrumb_elem'))
|
||||||
if grid.create_form:
|
if grid.create_form:
|
||||||
@@ -2694,7 +2705,7 @@ class SQLFORM(FORM):
|
|||||||
grid.view_form.record))
|
grid.view_form.record))
|
||||||
if next:
|
if next:
|
||||||
breadcrumbs.append(LI(
|
breadcrumbs.append(LI(
|
||||||
A(T(header), _class=trap_class(),_href=url()),
|
A(T(header), cid=request.cid,_href=url()),
|
||||||
_class='active w2p_grid_breadcrumb_elem'))
|
_class='active w2p_grid_breadcrumb_elem'))
|
||||||
grid.insert(
|
grid.insert(
|
||||||
0, DIV(UL(*breadcrumbs, **{'_class': breadcrumbs_class}),
|
0, DIV(UL(*breadcrumbs, **{'_class': breadcrumbs_class}),
|
||||||
|
|||||||
Reference in New Issue
Block a user