[Seaside] Basic question about AJAX and callbacks

Mariano Martinez Peck marianopeck at gmail.com
Fri Jul 11 16:20:21 UTC 2014


Ok.... since we are already in this thread....is there any Javascript
expert around?  What I need to do now goes outside my current limits...
I have the example I showed in this thread:

html anchor
class: 'btn btn-default btn-group-xs dropdown-toggle btn-xs';
onClick:
                (html jQuery ajax
                        serialize: (html jQuery: '#reportTableForm');
script: [ :s |
self doSomethingThin: anObject.
s << ((s jQuery id: ('tr',(self report indexFor: anObject) asString))
replaceWith:[:r |
"here...can I get the text of the href of my THs of the TR of the
tableHead?"
self report reRenderRow: anObject on: r.
 ]).
  ])

That is an anchor inside a cell of row, that serializes the form, then I do
something with the row (anObject) and finally I re-render the row. OK?
Now....the question is...I also have some Javascript lib rendering the
table (DataTables) which provides some plugins to, for example, re-order
the columns, hide-show columns, etc... The same tool also allows to keep in
the session, the "modifications" (columns reorder, hide/show columns etc),
so....if the user has reordered columns or hide-show some, when I re-render
the row, it is bad because in the server I have the "old" order etc.  The
lib may provide a callback or hook to be send whenever the columns are
reordered or hidden/shown but that is more complex to implement....

My columns have href as the "title" (sorting), hence I already have this
function:

var getCellText = function (elem) {
                    //get only the element text
                    return elem.contents().filter(function() {
                        return this.nodeValue;
                    }).text();
                };

Note that I do know the id of the TR. So I guess I should get the
tableHead, then its TR, then get the list of TH and for each call that
function. In any case....what I would need is that list and send it as
argument to "self report reRenderRow: anObject on: r.".
The problem is that I need to EXECUTE that javascript, get the return and
use that for my re-render.

Maybe this is not possible...

Thanks in advance!




On Fri, Jul 11, 2014 at 11:10 AM, Mariano Martinez Peck <
marianopeck at gmail.com> wrote:

>
>
>
> On Fri, Jul 11, 2014 at 10:37 AM, Winfried Jacobs <news at winfried-jacobs.de
> > wrote:
>
>> (sorry if this message comes up multiple times)
>>
>> Hello Mariano,
>>
>> JQAjax>>script: ist a callback, so you don't need both #callback: and
>> #script: .
>> Instead, you should merge both of your callback blocks into one:
>>
>>      html jQuery ajax
>>          serializeChildren: (html jQuery: '#myFormID');
>>          script: [ :s |
>>                  "code from your first #callback: goes in here."
>>                  "..."
>>
>>                  self halt. s << (s jQuery id: ('tr1')) replaceWith:[:r |
>> r
>> html: 'mariano' ]
>>                  ]
>>
>>
>>
> Hi Winfried,
>
> You know...yesterday night, just before going to sleep, I realized that
> indeed, I could put by "callback code" inside the very same #script: and
> then from there re-render (replaceWith...) from there.
>
>
>>
>> One possible reason why your code doesn't work: #callback: and #script:
>> are
>> primary callbacks, but you can only register one primary callback for an
>> ajax
>> object.
>>
>>
> OK, I see.
>
>
>> However, you could register multiple secondary callbacks like
>> #callback:value:
>> #callback:json: etc.  But in your case, a secondary
>> callback is unnecessary.
>>
>>
> OK, thanks for the explanation. I will read the web 2.0 chapter of the
> Dynamic Web Development..otherwise...why did I buy it? hahaha.
>
> Thanks,
>
>
>>
>>
>> Cheers
>> Winfried
>>
>>
>>
>> > Mariano Martinez Peck <marianopeck at gmail.com> hat am 11. Juli 2014 um
>> 04:23
>> > geschrieben:
>> >
>> >  Well...not there yet...now I am able to render the new table row with
>> all the
>> >'mariano'. And the row itself seems to reflect changes (the callback of
>> the
>> >ajax is really executed). The problem now is that I don't know how to
>> make my
>> >render script to happen AFTER the callback of the ajax. I tried
>> #script:  ,
>> >#onComplete: and #onSuccess:  (just in case). What I need is to make the
>> ajax
>> >call, serialize the form, execute the ajax callback, and then do the
>> replace of
>> >the tr (with a script).
>> >
>> >  The only one that seems to be executed later is #script: but when I do
>> this,
>> >the callback of the ajax is not executed.
>> >
>> >  Any ideas?
>> >
>> >  Thanks,
>> >
>> >
>> >  On Thu, Jul 10, 2014 at 6:22 PM, Mariano Martinez Peck <
>> marianopeck at gmail.com
>> ><mailto:marianopeck at gmail.com> > wrote:
>> >    > >    ouuuuch
>> > >
>> > >    sorrryyyy by bad hahahhaha. Very funny. I will explain later.
>> Don't loose
>> > >your time.
>> > >
>> > >    Best,
>> > >
>> > >
>> > >
>> > >    On Thu, Jul 10, 2014 at 6:00 PM, Esteban A. Maringolo
>> > ><emaringolo at gmail.com <mailto:emaringolo at gmail.com> > wrote:
>> > >      > > > Maybe you should use #onComplete: instead of #script: in
>> your
>> > >JQAjax object.
>> > > >      _______________________________________________
>> > > >      seaside mailing list
>> > > >      seaside at lists.squeakfoundation.org
>> > > ><mailto:seaside at lists.squeakfoundation.org>
>> > > >
>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>> > > >    > >
>> > >
>> > >
>> > >    --
>> > >    Mariano
>> > >    http://marianopeck.wordpress.com
>> > >  >
>> >
>> >
>> >  --
>> >  Mariano
>> >  http://marianopeck.wordpress.com
>> >  _______________________________________________
>> >  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
>>
>
>
>
> --
> Mariano
> http://marianopeck.wordpress.com
>



-- 
Mariano
http://marianopeck.wordpress.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/seaside/attachments/20140711/3d94e74e/attachment-0001.htm


More information about the seaside mailing list