w2p_trap

77 views
Skip to first unread message

Niphlod

unread,
Sep 30, 2013, 5:44:23 PM9/30/13
to web2py-d...@googlegroups.com
in the constant refinement of the grid (and web2py.js), I'm trying to understand what is the purpose of .w2p_trap .
Seems to me that the behaviour of the A elements with the w2p_trap class is undocumented (and a little bit off sync with the usual handling of A elements).
I really don't know why it was inserted in the code, but A links can surely be generated with cid=request.cid to enable the exact same behaviour.
If so, can we strip trap_links() from web2py.js, remove references of web2py_trap and add cid=request.cid in grid's code generating the buttons (and header, and paginator) ?
Can you foresee any collateral issues ?

Niphlod

unread,
Oct 2, 2013, 2:15:30 AM10/2/13
to web2py-d...@googlegroups.com
sending a PR on the weekend if anyone didn't raise any issues.

Massimo DiPierro

unread,
Oct 2, 2013, 9:23:25 AM10/2/13
to web2py-d...@googlegroups.com
Right now if a component contains a form, the form is trapped. Links are not. If you click on a link on the component, it loads the linked page, it does not replace the component. Unless the link has a "w2p_trap" class. Some links in the grid are designed so that they reload the grid, while other links are designed so that they reload the host page.

I am not opposed to a refactoring as long the behavior does not change.

I agree we do not need to different functions to trap forms and links but the one functions should still have a way to distinguish between links (and form) that want to be trapped (for links w2p_trap) and for forms (no_trap).

Massimo

--
-- mail from:GoogleGroups "web2py-developers" mailing list
make speech: web2py-d...@googlegroups.com
unsubscribe: web2py-develop...@googlegroups.com
details : http://groups.google.com/group/web2py-developers
the project: http://code.google.com/p/web2py/
official : http://www.web2py.com/
---
You received this message because you are subscribed to the Google Groups "web2py-developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py-develop...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Niphlod

unread,
Oct 2, 2013, 10:01:26 AM10/2/13
to web2py-d...@googlegroups.com
my point was more or less:
if a component contains a form, the form is trapped. this is handled by the LOAD()   (ajax_trap) .
if it contains a link, it's not given automatically the class "w2p_trap" (grid is another matter) .... so users in the need to trap links use cid=something explicitely anyway.
unless I lost something in the process (I'll review carefully) the only link in grid that shouldn't reload the component is the delete one, but I'm not sure if it does or not right now (because of potential "no records found" to be updated).

Massimo DiPierro

unread,
Oct 2, 2013, 10:15:50 AM10/2/13
to web2py-d...@googlegroups.com
On Oct 2, 2013, at 9:01 AM, Niphlod wrote:

my point was more or less:
if a component contains a form, the form is trapped. this is handled by the LOAD()   (ajax_trap) .
if it contains a link, it's not given automatically the class "w2p_trap" (grid is another matter) .... so users in the need to trap links use cid=something explicitely anyway.

Can you show an example.

unless I lost something in the process (I'll review carefully) the only link in grid that shouldn't reload the component is the delete one, but I'm not sure if it does or not right now (because of potential "no records found" to be updated).

There may be links in the representation of values. By default they should not be trapped. Right now I can do

db.table.field.represent = lambda v,r: A(v,_class='w2p_trap')

How would it work in your case? The represent does not know the cid?

Niphlod

unread,
Oct 2, 2013, 10:24:24 AM10/2/13
to web2py-d...@googlegroups.com


On Oct 2, 2013, at 9:01 AM, Niphlod wrote:

my point was more or less:
if a component contains a form, the form is trapped. this is handled by the LOAD()   (ajax_trap) .
if it contains a link, it's not given automatically the class "w2p_trap" (grid is another matter) .... so users in the need to trap links use cid=something explicitely anyway.
unless I lost something in the process (I'll review carefully) the only link in grid that shouldn't reload the component is the delete one, but I'm not sure if it does or not right now (because of potential "no records found" to be updated).

There may be links in the representation of values. By default they should not be trapped. Right now I can do

db.table.field.represent = lambda v,r: A(v,_class='w2p_trap')

only if you know that decorating links with w2p_trap actually traps links. and it's not documented anywhere. 
 

How would it work in your case? The represent does not know the cid?


why does it need to know the cid ? if it must be loaded in the same component, cid is in request.cid. If it must load in another component, cid must be known beforehand. 

Massimo DiPierro

unread,
Oct 2, 2013, 10:38:49 AM10/2/13
to web2py-d...@googlegroups.com
OK. Let's see the patch.

Niphlod

unread,
Oct 2, 2013, 4:46:19 PM10/2/13
to web2py-d...@googlegroups.com
here's the patch.
PS: remember to comment out the code in trap_links() on web2py.js (final goal is get rid of it)
PS2: there has been also a refactor of the code in the delete process
PS3: test it carefully
web2py.grid_refactor.patch

Niphlod

unread,
Oct 5, 2013, 8:14:12 AM10/5/13
to web2py-d...@googlegroups.com
did anyone noticed errors in this patch ?

Massimo DiPierro

unread,
Oct 5, 2013, 8:18:52 AM10/5/13
to web2py-d...@googlegroups.com
I did not review it yet.

Massimo DiPierro

unread,
Oct 5, 2013, 9:50:49 AM10/5/13
to web2py-d...@googlegroups.com
Seems to work well in my tests. I am pushing it.

Massimo



On Oct 5, 2013, at 7:14 AM, Niphlod wrote:

Reply all
Reply to author
Forward
0 new messages