[Seaside] Rendering Callbacks during an Ajax callback
jtuchel at objektfabrik.de
jtuchel at objektfabrik.de
Sat Feb 11 12:54:13 UTC 2017
Hi Johan,
Am 11.02.17 um 10:51 schrieb Johan Brichau:
> Hi Joachim,
>
> Glad to hear you are decrypting all of this.
>
I hope my comment wasn't offending you. Just an expression of me not
understanding immediately...
> Just to add: the code I sent really only does 1 ajax request from the
> client to the server.
> The trick is that there are two callbacks attached to the same request.
So this is something I really need to understand, besides all those
little alias:/access: and other helpers....
Maybe this time ;-)
>
> Of course, you can only attach a single callback that produces a
> response (a primary callback).
> But you can attach as many secondary callbacks as you want (i.e.
> callback:value or callback:passengers:) to a single ajax request.
I really need to play with this. So far, I tried doing as much as
possible in hand-written JS because it is easier to read and debug than
Seasides code-renderer-helpers. But as my case shows, there are
situations in which you cannot get away with this approach...
>
> Have a nice weekend!
Same to you. You've had your Seaside Doctor's shift today ;-)
Joachim
> Johan
>
>> On 11 Feb 2017, at 10:41, jtuchel at objektfabrik.de
>> <mailto:jtuchel at objektfabrik.de> wrote:
>>
>> 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 Tuchelmailto:jtuchel at objektfabrik.de
>> Fliederweg 1http://www.objektfabrik.de
>> D-71640 Ludwigsburghttp://joachimtuchel.wordpress.com
>> Telefon: +49 7141 56 10 86 0 Fax: +49 7141 56 10 86 1
>>
>> _______________________________________________
>> seaside mailing list
>> seaside at lists.squeakfoundation.org
>> <mailto:seaside at lists.squeakfoundation.org>
>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>
>
>
> _______________________________________________
> seaside mailing list
> seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
--
-----------------------------------------------------------------------
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/31865b48/attachment.html>
More information about the seaside
mailing list