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

Esteban A. Maringolo emaringolo at gmail.com
Wed May 28 03:34:08 UTC 2014


Thank you Bob!

I used your solution, with a minor tweak, but does the same thing:

First I'm adding the eventClick detector to the document (will end up
in an external js file).

html document addLoadScript: (((JSStream on: 'return(
        ($(target).offset().top < window.event.pageY)
        && ($(target).offset().top + $(target).height() > window.event.pageY)
        && ($(target).offset().left < window.event.pageX)
        && ($(target).offset().left + $(target).width() >
window.event.pageX))') asFunction: #('target')) assignTo:
'eventClickTest')


I add the following event handler to the table #onClick event.
html jQuery ajax
  callback: [ :value | self doSomethingWith: value ]
  value: (((html jQuery: '#', tableId, ' tr') filter:
'return(eventClickTest(this))' asFunction) first attributeAt: 'id')

And then I render the rows of the table data using the id of my
element as the key:
aCollection do:[:each |
   html tableRow
     id: 'o-', each id asString;
     with: [ html tableData "..." ]
 ]

It is the same thing you did, but instead of relying on text of the
cell, I'm relying on a, hidden, id of the row.

Now I have to find how to transform that callback into something
useful to create an ajax load.

tl;dr I want to open a Bootstrap modal with the, custom rendered,
details of the object clicked in the table.


Regards!


Esteban.

ps: I also renamed bobclicktest ;-)
Esteban A. Maringolo


2014-05-27 22:08 GMT-03:00 Bob Arning <arning315 at comcast.net>:
> Well, as for using a single callback to cover lots of click targets, I use
> something like this
>
> --- a single onClick: for the table---
>     html table
>         onClick: (
>             html jQuery ajax
>             callback: [ :value |
>                 selIndex _ myNums findFirst: [ :each | each asString =
> value].
>             ]
>             value: ((html jQuery: '.',id1) filter:
> 'return(bobclicktest(this))' asFunction) first html;
> ...
>
> --- each cell in table that you want to be clickable has the class id1 ---
>             html tableRow: [
>                 myNums do: [ :e |
>                     html tableData
>                         class: id1;
> ...
>
> --- and bobclicktest checks if the event occurred in a particular element---
> function bobclicktest(target) {
>     return(
>         ($(target).offset().top < window.event.pageY)
>         && ($(target).offset().top + $(target).height() >
> window.event.pageY)
>         && ($(target).offset().left < window.event.pageX)
>         && ($(target).offset().left + $(target).width() >
> window.event.pageX)
>     )
> }
> On 5/27/14 8:25 PM, Esteban A. Maringolo wrote:
>
> Additionally to this, is it possible to pass an argument to such callback?
>
> I'm dealing with a data table on the browser and want to show details
> of the selected item once clicked. Instead of creating hundreds of
> callbacks (one per row), I'd like to pass an identifier of such item
> to the callback, in order to be able to retrieve it from the
> datasource. Is it possible?
>
> Is there a better way to register a callback that does exactly the same?
>
> something to replace this:
> collection do: [:each | html anchor callback: [self edit: each]; with:
> 'Edit' ]
>
> Into a reutilizable callback with an added parameter.
>
> I looked into the WAListTag class and it seems there is no other way
> other than creating a single callback per item.
> Maybe it is cheap in terms of memory and I worrying about an non
> existing problem. But there should be other way.
>
> Regards!
>
> Esteban A. Maringolo
>
>
> 2014-05-27 19:46 GMT-03:00 Esteban A. Maringolo <emaringolo at gmail.com>:
>
> I'm struggling to find a clean way of generating an url to be used for
> external reference from a javascript library/plugin, such as
> crossfilter or DataTables.
>
> E.g the constructor configuration object has a dataUrl parameter,
> which will be used by the plugin to retrieve the data.
>
> $('element').plugin({dataUrl: "..."});
>
> I can generate the expression to retrieve it from anywhere, but what I
> want is to associate an url with a callback that will answer the data
> requested.
>
> Today I'm assigning results to a local variable using a predefined
> callback function, and then initializing my data dependent function
> assuming there is going to be data in that variable.
>
> Ej:
> html document addLoadScript: (
>   ((html jQuery getJson
>      json: [ :json | self renderItemsOnJson: json ];
>      onSuccess: (JSStream on: 'myCallbackFunction(arguments[0]);')
> asFunction) asFunction assignTo: 'loadCrossfilterData')).
>
> html document addLoadScript: (JSStream on: 'loadCrossfilterData()').
>
> I want some way to create a url callback in the way of:
>
> callbackUrl :=  html magicalCallbackRegister: [ :json | self
> renderItemsOnJson: json ]. "answers a url"
>
> JSStream on: '$(''#element'').plugin({dataUrl:"', callbackUrl, '"})'.
>
> which once rendered as JS would be:
>
> $('#element').plugin({dataUrl:"/app/_s=...&_k=...&n"});
>
> I know this must be possible, because Seaside does it for all the
> callbacks, but I don't know how to create a simple callback and then
> get it's url to pass it around.
>
> I hope all I wrote is intelligible. Otherwise I can rephrase it in
> other unintelligible way. :)
>
> Esteban A. Maringolo
>
> _______________________________________________
> seaside mailing list
> 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
>


More information about the seaside mailing list