[Seaside] Checkbox and AJAX?

Mariano Martinez Peck marianopeck at gmail.com
Tue Jul 8 13:06:55 UTC 2014


On Mon, Jul 7, 2014 at 6:02 PM, Johan Brichau <johan at inceptive.be> wrote:

> Hi Mariano,
>
> Unfortunately, the trick with capturing 'this' for later use is not going
> to work. The generated script (or the onSuccess callback) are not executed
> in the same scope as where you defined 'myself'.
>

Ok, I imagined that something like that could happen.


> I made that mistake in this thread earlier on, but I was just not thinking
> right. Sorry about that.
>
>
Np, it was a good try to avoid having an id for every row ;)


> The problem with the apply: is that the apply statement is added inside
> the function. I noticed that problem with JSFunction objects before but I
> don't know yet if it can be solved. It does act counter-intuitive though.
>
>
Indeed.


> Working with an id per row is the easiest solution here, I think.
>
>
OK, perfect.

Thank you very much guys,


> Johan
>
> On 07 Jul 2014, at 15:42, Mariano Martinez Peck <marianopeck at gmail.com>
> wrote:
>
> > Thank you all for the explanations. I do get it now. Now that I made the
> simplest case to work (adding an id per tr), I would like to make the Johan
> solution (finding the closest tr). I tried:
> >
> >       html form: [
> >               html label:[
> >                       html checkbox
> >                                onClick:  (((JSStream on: 'var myself =
> this'),
> >                                               (html jQuery ajax
> >
> serializeThisWithHidden;
> >                                                         script: [ :s | s
> << (((s jQuery expression:(JSStream on: 'myself')) closest: 'tr') addClass:
> 'selectedRow') ])) asFunction apply: #());
> >                               value: (self isSelected: anObject);
> >                               callback: [ :value | self selectRow:
> anObject value: value ]]]
> >
> > But I get: SyntaxError: function statement requires a name
> >
> >
> > The onClick is being generated like this:
> >
> > a JSFunction (function(){var myself =
> this;$.ajax({"url":"/reps","data":["_s=nHl8jzTmLkMbcOME","_k=2IH4kmR1ds-rEaua","accessMenu=Clients","activityMenu=Clients","65",$(this).next("input:hidden").andSelf().serialize()].join("&"),"dataType":"script"})}())
> >
> > Note that if I put a halt in #script, it doesn't even get call.
> >
> > I removed the asFunction apply:   letting only something like this:
> >
> >  onClick:  (((JSStream on: 'var myself = this'),
> >                 (html jQuery ajax
> >                           serializeThisWithHidden;
> >                           script: [ :s |  self halt. s << (((s jQuery
> expression:(JSStream on: 'myself')) closest: 'tr') addClass: 'selectedRow')
> ])) );
> >
> > This solved that problem, but my row doesn't get the css class yet. The
> #script: does halts, and generates a script like this one:
> >
> > a JSScript ($(myself).closest("tr").addClass("selectedRow"))
> >
> > Any ideas?
> >
> > Thanks in advance,
> >
> >
> >
> >
> >
> > On Sun, Jul 6, 2014 at 9:14 AM, Johan Brichau <johan at inceptive.be>
> wrote:
> > Hi,
> >
> > Both in the context of the #script: ajax callback-to-smalltalk and the
> ajax #onSuccess: javascript-callback option, the javascript's this variable
> will not hold anything related to the DOM.
> >
> > The difference between #script: and #onSuccess: is that the former
> defines a script rendering callback to be executed in Seaside and the
> latter is a jQuery ajax option to define a javascript callback (to be
> executed client-side) when the ajax call finishes successfully.
> >
> > The onSuccess parameter will accept both a string or a JSScript instance
> as a Javascript to be executed
> > In a #script callback, the block argument is a JSScript instance
> already. The script concatenation operator '<<' expects another JSScript
> instance (e.g. a JSStream instance). If you concatenate a Smalltalk string
> with a JSScript instance, the Smalltalk string is serialized as a
> Javascript string on the JSScript instance.
> >
> > cheers
> > Johan
> >
> > On 06 Jul 2014, at 01:06, carlo.t <snoobabk at yahoo.ie> wrote:
> >
> > > Hi
> > >
> > > I thick #script: does not work because this is a separate ajax call
> where
> > > the reference to 'this' is not known and is not the row you expect.
> > > #script would work if you reference a valid DOM id for the row e.g.
> > >                                       html checkbox
> > >                                               onClick: (html jQuery
> ajax serializeThisWithHidden;
> > >                                                               script:
> [:s | s
> > >
>         << (s jQuery: #idForRow) addClass: 'selectedRow']);
> > >
> > > #onSuccess is probably triggering a callback where the reference to
> 'this'
> > > is valid and so the following line will work:
> > >       (html jQuery this closest: 'tr') addClass: 'selectedRow'
> > >
> > > I'm a javascript newbie too but thats what I think is going on.
> > >
> > > Cheers
> > > Carlo
> > >
> > >
> > >
> > >
> > > --
> > > View this message in context:
> http://forum.world.st/Checkbox-and-AJAX-tp4731692p4766717.html
> > > Sent from the Seaside General mailing list archive at Nabble.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
> > _______________________________________________
> > 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/seaside/attachments/20140708/9cd4661a/attachment.htm


More information about the seaside mailing list