[Seaside] Generating an callback URL for third-party use

Esteban A. Maringolo emaringolo at gmail.com
Wed May 28 14:40:30 UTC 2014

Just for the record, I'm sharing what I did..

>>#renderContentOn: html
html document addLoadScript: (self dataTableCreationScriptOn: html)
html document addLoadScript: (self tableClickHandler: html)

"Bind the datatable with the jsonResponse"
>>#dataTableCreationScriptOn: html

| actionUrl |
  actionUrl := html actionUrl withField: (html callbacks store:
(JSAjaxCallback on: [self jsonResponse])).
 ^((JSStream on: '$(''#' , tableId , ''')', '.dataTable({
        "ajax": "', actionUrl asString, '",
        "columns": [...]})') assignTo: 'datatable')

"Bind the row click with an ajax callback that sets the selected item in
the component and then performs a JQLoad based on the id passed through the
>>#tableClickHandler: html
^ (html jQuery: '#' , tableId , ' tbody')
on: 'click'
 selector: 'tr'
(html jQuery ajax
 callback: [ :value | selectedItemId := value ] value: html jQuery this
onSuccess: (self renderAjaxModalLoadOn: html) asFunction)

"Loads the new html, and then invokes the show of the modal."
>>#renderAjaxModalLoadOn: html
^ (html jQuery: '#' , self idModalContainer) load
 html: [ :ajaxHtml | self renderModalOn: ajaxHtml ];
onComplete: ((html jQuery: '#', self idModal) call: 'modal' with: 'show')

I wish there was a way to simply call the JQLoad passing the argument as I
do with the callback:value:, that would save me one round-trip plus not
being dependant on the state.

Thank you!

Esteban A. Maringolo

2014-05-28 10:31 GMT-03:00 Esteban A. Maringolo <emaringolo at gmail.com>:

> Johan,
> 2014-05-28 3:12 GMT-03:00 Johan Brichau <johan at inceptive.be>:
> > Bob's answer is similar, but I prefer to explicitly use jQuery's
> on:selector:do: method.
> >
> > The full documentation is here: http://api.jquery.com/on/
> >
> > This way of working with delegated events is really necessary if you
> have hundreds of callbacks to attach. That never scales and your
> performance will be horrible (large response size, large seaside session,
> ...)
> Thanks for the advice. I looked into jQuery's docs and it's exactly
> what I was needing. In fact they use a dataTable as example.
> I added the handler this way:
> html document addLoadScript: ((html jQuery: '#', tableId, ' tbody')
>   on: 'click'
>   selector: 'tr'
>   do: (
>     html jQuery ajax
>       callback: [ :value | Transcript show: 'Clicked row: ', value; cr. ]
>       value: (html jQuery this text) ) asFunction)
> Now I need to transform that single ajax call into something more
> convoluted :)
> Thank you!
> Esteban A. Maringolo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/seaside/attachments/20140528/f40445e5/attachment.htm

More information about the seaside mailing list