[Seaside] Rendering Callbacks during an Ajax callback

jtuchel at objektfabrik.de jtuchel at objektfabrik.de
Sat Feb 11 09:41:41 UTC 2017


Hi Johan


Am 11.02.17 um 10:19 schrieb Johan Brichau:
> Hey Joachim,
>
> You can use a normal seaside callback and register it to capture 
> delegated events.
> No magic ;)
>
> html orderedList
> script: (html jQuery this
> on: ‘click’
> selector: ‘.mylistItemClass’
> do: ((html jQuery ajax
> callback: [:listitemId |  … ]
> value: (((html javascript alias: ‘event’) access: ‘target’) access: ‘id’))
> asFunction: #(event))
>
> This registers the callback on the list to capture clicks on the items 
> below it, while passing the id of the element on which the click 
> happened to the callback.
> If you register passengers on each of the listitems, it’s more intuitive:
>
> html orderedList
> script: (html jQuery this
> on: ‘click’
> selector: ‘.mylistItemClass’
> do: ((html jQuery ajax
> callback: [:passenger |  … ]
> passengers: ((html javascript alias: ‘event’) access: ‘target’)
> asFunction: #(event))
>
> Obviously, this does not render anything yet. So, we need to add that 
> functionality to the callback:
>
> | idToReRender |
> html orderedList
> script: (html jQuery this
> on: ‘click’
> selector: ‘.mylistItemClass’
> do: ((html jQuery ajax
> callback: [:listitemId |  … idToReRender := listitemId ... ]
> value: (((html javascript alias: ‘event’) access: ‘target’) access: 
> ‘id’));
> script: [:s | s << ((s jQuery id: idToReRender) html: [:h | self 
> renderMyRowWithId: idToReRender ]) ]
> asFunction: #(event))
>
I seem to understand. This will call the server twice, once for the 
setting id of which item to rerender, and a second time for the actual 
rendering, right? My attempt tried to use the first ajax callback to do 
both: process the business code and answer the re-rendered row to the 
client, so that it just does a .replaceWith() for the row with the 
re-rendered one. That is why I needed to have a builder that the 
component could render itself onto.

But since your aproach  just registers one single callback for the whole 
list, it still is an improvement compared to registering the very same 
callback for each row - which takes a lot of time on both the server and 
the client. And apart from the double ajax calls, it is exactly what I 
want to achieve. I guess my reason for hand-written javascript here is 
that I like to be able to debug it and I know way too little about 
JQAjax' many options... time to study

My brain is working on this, and I am really grateful for your time and 
help. I guess we should negotiate your reward in Maribor ;-)


Joachim


-- 
-----------------------------------------------------------------------
Objektfabrik Joachim Tuchel          mailto:jtuchel at objektfabrik.de
Fliederweg 1                         http://www.objektfabrik.de
D-71640 Ludwigsburg                  http://joachimtuchel.wordpress.com
Telefon: +49 7141 56 10 86 0         Fax: +49 7141 56 10 86 1

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/seaside/attachments/20170211/9e10b176/attachment.html>


More information about the seaside mailing list