Javascript calls through jQuery

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
20 messages Options
Reply | Threaded
Open this post in threaded view
|

Javascript calls through jQuery

Esteban A. Maringolo
Is there a way I can perform an AJAX call to get a JSON response and
pass it to a JavaScript function?

Now I'm gluing everying externally by means of a JS file, but the AJAX
calls are outside of the Seaside session (REST Filter), and I'd like
to get everything in the same session.

Thanks in advance,

Esteban A. Maringolo
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Javascript calls through jQuery

Esteban A. Maringolo
I'm bumping this.

Today I have a set of functions in a JavaScript file querying a
RESTFilter'ed component at a fixed URL. The REST path will return a
list of elements in a JSON response, which is passed to other js
function in the beforementioned js file.

I want to move as much as I can from the JS file to Seaside, because
now I need to add certain parameters to the request, and I thought it
would be simpler to do it with Seaside.

What I need is to be able to do is:
1. fill a form (a set of filters) which will send an ajax call to the
seaside component
2. The seaside component will process the form and decide what to
return (the JSON response)
3. Once the response arrives back at the client side, the json
response must be passed to another JS function as an argument
4. Must repeat item #3 every n seconds.

I can do this on the JS side, but I still don't get how the whole
jQuery machinery works in Seaside.
Seems to be utter powerful, but not as straightforward as simply
writing the JS :)


Regards!

Esteban A. Maringolo


2014-02-18 10:05 GMT-03:00 Esteban A. Maringolo <[hidden email]>:

> Is there a way I can perform an AJAX call to get a JSON response and
> pass it to a JavaScript function?
>
> Now I'm gluing everying externally by means of a JS file, but the AJAX
> calls are outside of the Seaside session (REST Filter), and I'd like
> to get everything in the same session.
>
> Thanks in advance,
>
> Esteban A. Maringolo
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Javascript calls through jQuery

Sven Van Caekenberghe-2
I am a beginner with the Seaside jQuery codebase myself, but I do like it.

I guess you know about http://book.seaside.st/book/web-20/jquery ?

For the more advanced stuff, you will have to either find it in the image, on the internet, in particular on this list, or ask in small increments.

On 02 Mar 2014, at 19:13, Esteban A. Maringolo <[hidden email]> wrote:

> I'm bumping this.
>
> Today I have a set of functions in a JavaScript file querying a
> RESTFilter'ed component at a fixed URL. The REST path will return a
> list of elements in a JSON response, which is passed to other js
> function in the beforementioned js file.
>
> I want to move as much as I can from the JS file to Seaside, because
> now I need to add certain parameters to the request, and I thought it
> would be simpler to do it with Seaside.
>
> What I need is to be able to do is:
> 1. fill a form (a set of filters) which will send an ajax call to the
> seaside component
> 2. The seaside component will process the form and decide what to
> return (the JSON response)
> 3. Once the response arrives back at the client side, the json
> response must be passed to another JS function as an argument
> 4. Must repeat item #3 every n seconds.
>
> I can do this on the JS side, but I still don't get how the whole
> jQuery machinery works in Seaside.
> Seems to be utter powerful, but not as straightforward as simply
> writing the JS :)
>
>
> Regards!
>
> Esteban A. Maringolo
>
>
> 2014-02-18 10:05 GMT-03:00 Esteban A. Maringolo <[hidden email]>:
>> Is there a way I can perform an AJAX call to get a JSON response and
>> pass it to a JavaScript function?
>>
>> Now I'm gluing everying externally by means of a JS file, but the AJAX
>> calls are outside of the Seaside session (REST Filter), and I'd like
>> to get everything in the same session.
>>
>> Thanks in advance,
>>
>> Esteban A. Maringolo
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Javascript calls through jQuery

Esteban A. Maringolo
I was reading that part of the book before sending the mail. But there
are several "ToDo" in the AJAX parts of the book :)

The http://demo.seaside.st/javascript/jquery/loadexternaljson #getJson
jquery object could do the trick. But it depends on a static URL.

I want to get the JSON response from the URL of the callback (whatever
black magic happens behind).

I was thinking in something like:

html jQuery ajax
  serializeForm;
  onComplete: (
     html jQuery getJson
         callback: [ self answerJsonWithNewFormParameters ];
         onSuccess: 'myJsFileFunction(arguments[0])' )


The problem is that I'm in the learning curve part where I'm fighting
against not understanding how it works instead of fighting why it
doesn't work :)

Regards!

Esteban A. Maringolo


2014-03-02 15:29 GMT-03:00 Sven Van Caekenberghe <[hidden email]>:

> I am a beginner with the Seaside jQuery codebase myself, but I do like it.
>
> I guess you know about http://book.seaside.st/book/web-20/jquery ?
>
> For the more advanced stuff, you will have to either find it in the image, on the internet, in particular on this list, or ask in small increments.
>
> On 02 Mar 2014, at 19:13, Esteban A. Maringolo <[hidden email]> wrote:
>
>> I'm bumping this.
>>
>> Today I have a set of functions in a JavaScript file querying a
>> RESTFilter'ed component at a fixed URL. The REST path will return a
>> list of elements in a JSON response, which is passed to other js
>> function in the beforementioned js file.
>>
>> I want to move as much as I can from the JS file to Seaside, because
>> now I need to add certain parameters to the request, and I thought it
>> would be simpler to do it with Seaside.
>>
>> What I need is to be able to do is:
>> 1. fill a form (a set of filters) which will send an ajax call to the
>> seaside component
>> 2. The seaside component will process the form and decide what to
>> return (the JSON response)
>> 3. Once the response arrives back at the client side, the json
>> response must be passed to another JS function as an argument
>> 4. Must repeat item #3 every n seconds.
>>
>> I can do this on the JS side, but I still don't get how the whole
>> jQuery machinery works in Seaside.
>> Seems to be utter powerful, but not as straightforward as simply
>> writing the JS :)
>>
>>
>> Regards!
>>
>> Esteban A. Maringolo
>>
>>
>> 2014-02-18 10:05 GMT-03:00 Esteban A. Maringolo <[hidden email]>:
>>> Is there a way I can perform an AJAX call to get a JSON response and
>>> pass it to a JavaScript function?
>>>
>>> Now I'm gluing everying externally by means of a JS file, but the AJAX
>>> calls are outside of the Seaside session (REST Filter), and I'd like
>>> to get everything in the same session.
>>>
>>> Thanks in advance,
>>>
>>> Esteban A. Maringolo
>> _______________________________________________
>> seaside mailing list
>> [hidden email]
>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Javascript calls through jQuery

Karsten Kusche
In reply to this post by Esteban A. Maringolo
Esteban, 
I want to move as much as I can from the JS file to Seaside, because
now I need to add certain parameters to the request, and I thought it
would be simpler to do it with Seaside.
in recent projects i’ve found it’s much easier to do it exactly the other way around. Keep as much code in a js file and configure it via Seaside. Doing jQuery inline in Seaside just makes things more complicated as you need to write the jQuery code in the Seaside style and not plain normal Javascript. It also has the benefits of being easier to debug as you can just set breakpoints at a line. The Seaside-generated Javascript code is typically pretty tight and not pretty-printed, making it extremely hard to debug.

The only places where i use Seaside-jQuery code is when i need to generate render-callbacks or other kinds of callbacks. But as Javascript objects can be assigned to any kind of DOM Object you can separate the callback-code from the other javascript code quite nicely.

Kind Regards
Karsten



What I need is to be able to do is:
1. fill a form (a set of filters) which will send an ajax call to the
seaside component
2. The seaside component will process the form and decide what to
return (the JSON response)
3. Once the response arrives back at the client side, the json
response must be passed to another JS function as an argument
4. Must repeat item #3 every n seconds.

I can do this on the JS side, but I still don't get how the whole
jQuery machinery works in Seaside.
Seems to be utter powerful, but not as straightforward as simply
writing the JS :)


Regards!

Esteban A. Maringolo


2014-02-18 10:05 GMT-03:00 Esteban A. Maringolo <[hidden email]>:
Is there a way I can perform an AJAX call to get a JSON response and
pass it to a JavaScript function?

Now I'm gluing everying externally by means of a JS file, but the AJAX
calls are outside of the Seaside session (REST Filter), and I'd like
to get everything in the same session.

Thanks in advance,

Esteban A. Maringolo
_______________________________________________
seaside mailing list


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Javascript calls through jQuery

Johan Brichau-2
In reply to this post by Esteban A. Maringolo
Hi Esteban,

I think there is something missing in the JQuery-Seaside binding here.
imho, what you need is a #json: value-rendering callback, in the style of the #script:, #html: or #text: callbacks.

In Seaside 3.0, the following would work:

JQGetJson>>json: aBlock
        "Defines a json rendering callback."

        self dataType: 'application/json'.
        self respond: [ :response |
                response
                        doNotCache;
                        contentType: (WAMimeType applicationJson
                                charset: self requestContext handler charSet).
                aBlock value: response stream ]

Your example would then become:

(html jQuery ajax
                serializeForm;
                onComplete: (
    html jQuery getJson
        json: [:str | ... ];
        onSuccess: 'myJsFileFunction(arguments[0])' ) );

However, with the new WAJsonCanvas in Seaside3.1, we would prefer to get a JSON canvas as the argument to the #json: callback.
In the code above, it's the response stream.
I think it should be possible, and I will take a look for that.

Johan

On 02 Mar 2014, at 19:51, Esteban A. Maringolo <[hidden email]> wrote:

> I was reading that part of the book before sending the mail. But there
> are several "ToDo" in the AJAX parts of the book :)
>
> The http://demo.seaside.st/javascript/jquery/loadexternaljson #getJson
> jquery object could do the trick. But it depends on a static URL.
>
> I want to get the JSON response from the URL of the callback (whatever
> black magic happens behind).
>
> I was thinking in something like:
>
> html jQuery ajax
>  serializeForm;
>  onComplete: (
>     html jQuery getJson
>         callback: [ self answerJsonWithNewFormParameters ];
>         onSuccess: 'myJsFileFunction(arguments[0])' )
>
>
> The problem is that I'm in the learning curve part where I'm fighting
> against not understanding how it works instead of fighting why it
> doesn't work :)
>
> Regards!
>
> Esteban A. Maringolo
>
>
> 2014-03-02 15:29 GMT-03:00 Sven Van Caekenberghe <[hidden email]>:
>> I am a beginner with the Seaside jQuery codebase myself, but I do like it.
>>
>> I guess you know about http://book.seaside.st/book/web-20/jquery ?
>>
>> For the more advanced stuff, you will have to either find it in the image, on the internet, in particular on this list, or ask in small increments.
>>
>> On 02 Mar 2014, at 19:13, Esteban A. Maringolo <[hidden email]> wrote:
>>
>>> I'm bumping this.
>>>
>>> Today I have a set of functions in a JavaScript file querying a
>>> RESTFilter'ed component at a fixed URL. The REST path will return a
>>> list of elements in a JSON response, which is passed to other js
>>> function in the beforementioned js file.
>>>
>>> I want to move as much as I can from the JS file to Seaside, because
>>> now I need to add certain parameters to the request, and I thought it
>>> would be simpler to do it with Seaside.
>>>
>>> What I need is to be able to do is:
>>> 1. fill a form (a set of filters) which will send an ajax call to the
>>> seaside component
>>> 2. The seaside component will process the form and decide what to
>>> return (the JSON response)
>>> 3. Once the response arrives back at the client side, the json
>>> response must be passed to another JS function as an argument
>>> 4. Must repeat item #3 every n seconds.
>>>
>>> I can do this on the JS side, but I still don't get how the whole
>>> jQuery machinery works in Seaside.
>>> Seems to be utter powerful, but not as straightforward as simply
>>> writing the JS :)
>>>
>>>
>>> Regards!
>>>
>>> Esteban A. Maringolo
>>>
>>>
>>> 2014-02-18 10:05 GMT-03:00 Esteban A. Maringolo <[hidden email]>:
>>>> Is there a way I can perform an AJAX call to get a JSON response and
>>>> pass it to a JavaScript function?
>>>>
>>>> Now I'm gluing everying externally by means of a JS file, but the AJAX
>>>> calls are outside of the Seaside session (REST Filter), and I'd like
>>>> to get everything in the same session.
>>>>
>>>> Thanks in advance,
>>>>
>>>> Esteban A. Maringolo
>>> _______________________________________________
>>> seaside mailing list
>>> [hidden email]
>>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>>
>> _______________________________________________
>> seaside mailing list
>> [hidden email]
>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Javascript calls through jQuery

Johan Brichau-2

On 02 Mar 2014, at 22:00, Johan Brichau <[hidden email]> wrote:

> However, with the new WAJsonCanvas in Seaside3.1, we would prefer to get a JSON canvas as the argument to the #json: callback.
> In the code above, it's the response stream.
> I think it should be possible, and I will take a look for that.

In Seaside 3.1, the following seems to work but I need to verify a bit more. In the meantime, this might help you.

JQGetJson>>json: aBlock
        "Defines a json rendering callback."

        self dataType: 'application/json'.
        self respond: [ :response |
                response
                        doNotCache;
                        contentType: (WAMimeType applicationJson
                                charset: self requestContext handler charSet);
                        nextPutAll: (WAJsonCanvas builder
                                render: aBlock)]


cheers
Johan_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Javascript calls through jQuery

Esteban A. Maringolo
In reply to this post by Karsten Kusche
2014-03-02 15:55 GMT-03:00 Karsten Kusche <[hidden email]>:

> Esteban,
>
> I want to move as much as I can from the JS file to Seaside, because
> now I need to add certain parameters to the request, and I thought it
> would be simpler to do it with Seaside.
>
> in recent projects i've found it's much easier to do it exactly the other
> way around. Keep as much code in a js file and configure it via Seaside.
> Doing jQuery inline in Seaside just makes things more complicated as you
> need to write the jQuery code in the Seaside style and not plain normal
> Javascript. It also has the benefits of being easier to debug as you can
> just set breakpoints at a line. The Seaside-generated Javascript code is
> typically pretty tight and not pretty-printed, making it extremely hard to
> debug.

I share the same approach with you, Today I'm doing exactly that.
Creating JS source from Smalltalk can be really convoluted. All the
Seaside jQuery implementation is really clever in terms of code
generation. But for custon JS you can't do that.

So now I only I want to call my own JS function at the end of the JSON callback.
The thing is that in this case I want to use the same Seaside session
for the ajax call, given the fact that URL routing with Seaside is not
as straightforward as you might like, having stateful components is
the counterpart of the URL management, and I could take advantage of
having everything at the server side to generate the JSON response
based on component state instead of request parameters.

> The only places where i use Seaside-jQuery code is when i need to generate
> render-callbacks or other kinds of callbacks. But as Javascript objects can
> be assigned to any kind of DOM Object you can separate the callback-code
> from the other javascript code quite nicely.

So far I'm using it only for this, but I want to move forward a few extra steps.

Regards!


Esteban A. Maringolo
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Javascript calls through jQuery

Esteban A. Maringolo
In reply to this post by Johan Brichau-2
Hi Johan,

I added the #json: method as you suggested.

It seems to be working (I put a halt in the #json: callback and it
halted), the only problem is that it is causing a full page reload (as
a normal callback), and then the success function callback is never
called on the client.

This is the code I'm using:

html form: [
"...snipped code"
  html button
    onClick:  (html jQuery ajax
                   serializeForm;
                   onComplete: (
                     html jQuery getJson
                       json: [:json | self renderJsonResponseOn: json ];
                       onSuccess: 'console.log(arguments[0])'));
    with: 'Filter!'
]


Any suggestion?

Thanks!

ps: Is there a way to generate pretty-printed JS and HTML source?
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Javascript calls through jQuery

Johan Brichau-2

On 03 Mar 2014, at 02:09, Esteban A. Maringolo <[hidden email]> wrote:

> Any suggestion?

That's because the button is triggering a submit. Change it to a push button as follows:

html form: [
"...snipped code"
 html button
   onClick:  (html jQuery ajax
                  serializeForm;
                  onComplete: (
                    html jQuery getJson
                      json: [:json | self renderJsonResponseOn: json ];
                      onSuccess: 'console.log(arguments[0])'));
   with: 'Filter!'
]

> ps: Is there a way to generate pretty-printed JS and HTML source?

afaik, you have to use the browser development tools for that:

https://plus.google.com/+AddyOsmani/posts/Q7t2U51G7YR

cheers
Johan_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Javascript calls through jQuery

Johan Brichau-2
Esteban,

Mind that you can combine these ajax calls in the following way:

html form: [
"...snipped code"
 html button
        bePush;
        onClick:  (html jQuery ajax
                  serializeForm;
                  json: [:json | json object: [ ] ];
                 onSuccess: 'console.log(arguments[0])');
   with: 'Filter!'
]

cheers
Johan

On 03 Mar 2014, at 07:21, Johan Brichau <[hidden email]> wrote:

>
> On 03 Mar 2014, at 02:09, Esteban A. Maringolo <[hidden email]> wrote:
>
>> Any suggestion?
>
> That's because the button is triggering a submit. Change it to a push button as follows:
>
> html form: [
> "...snipped code"
> html button
>   onClick:  (html jQuery ajax
>                  serializeForm;
>                  onComplete: (
>                    html jQuery getJson
>                      json: [:json | self renderJsonResponseOn: json ];
>                      onSuccess: 'console.log(arguments[0])'));
>   with: 'Filter!'
> ]
>
>> ps: Is there a way to generate pretty-printed JS and HTML source?
>
> afaik, you have to use the browser development tools for that:
>
> https://plus.google.com/+AddyOsmani/posts/Q7t2U51G7YR
>
> cheers
> Johan

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Javascript calls through jQuery

Esteban A. Maringolo
Good day Johan,

I thought WAButtonTag was push by default, I didn't check.

I moved the #json: method from JQGetJson to JQAjax, and chained
#serializeForm and #json: on the same ajax object and it worked.
Thanks!

I don't know how Seaside manages to read the serialized form values
from the query string, but in this very moment I don't care much
either :)

By now it works as expected. I'll surely come back later with more questions.


Thanks again.

ps: Is the #json: method going to be added to Seaside-Jquery main trunk?
Esteban A. Maringolo


2014-03-03 4:07 GMT-03:00 Johan Brichau <[hidden email]>:

> Esteban,
>
> Mind that you can combine these ajax calls in the following way:
>
> html form: [
> "...snipped code"
>  html button
>         bePush;
>         onClick:  (html jQuery ajax
>                   serializeForm;
>                   json: [:json | json object: [ ] ];
>                  onSuccess: 'console.log(arguments[0])');
>    with: 'Filter!'
> ]
>
> cheers
> Johan
>
> On 03 Mar 2014, at 07:21, Johan Brichau <[hidden email]> wrote:
>
>>
>> On 03 Mar 2014, at 02:09, Esteban A. Maringolo <[hidden email]> wrote:
>>
>>> Any suggestion?
>>
>> That's because the button is triggering a submit. Change it to a push button as follows:
>>
>> html form: [
>> "...snipped code"
>> html button
>>   onClick:  (html jQuery ajax
>>                  serializeForm;
>>                  onComplete: (
>>                    html jQuery getJson
>>                      json: [:json | self renderJsonResponseOn: json ];
>>                      onSuccess: 'console.log(arguments[0])'));
>>   with: 'Filter!'
>> ]
>>
>>> ps: Is there a way to generate pretty-printed JS and HTML source?
>>
>> afaik, you have to use the browser development tools for that:
>>
>> https://plus.google.com/+AddyOsmani/posts/Q7t2U51G7YR
>>
>> cheers
>> Johan
>
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Javascript calls through jQuery

Esteban A. Maringolo
Let's add a twist to this... I want to a have a recurrent polling to
the #json: callback I implemented above.

I had the following load script written in plain JS:

        (function getStoresStatus(){
                $.ajax({url: '/ps/rest/store-status', dataType: 'json'}).done(
                        function(response){
                                jQuery.each(response, function(index, value){
                                        updateStoreMarker(value)});
                                setTimeout(getStoresStatus,30000)
                        }
                );
        }());


How can I do the same using Seaside Jquery functions?

Regards!

Esteban A. Maringolo


2014-03-03 10:27 GMT-03:00 Esteban A. Maringolo <[hidden email]>:

> Good day Johan,
>
> I thought WAButtonTag was push by default, I didn't check.
>
> I moved the #json: method from JQGetJson to JQAjax, and chained
> #serializeForm and #json: on the same ajax object and it worked.
> Thanks!
>
> I don't know how Seaside manages to read the serialized form values
> from the query string, but in this very moment I don't care much
> either :)
>
> By now it works as expected. I'll surely come back later with more questions.
>
>
> Thanks again.
>
> ps: Is the #json: method going to be added to Seaside-Jquery main trunk?
> Esteban A. Maringolo
>
>
> 2014-03-03 4:07 GMT-03:00 Johan Brichau <[hidden email]>:
>> Esteban,
>>
>> Mind that you can combine these ajax calls in the following way:
>>
>> html form: [
>> "...snipped code"
>>  html button
>>         bePush;
>>         onClick:  (html jQuery ajax
>>                   serializeForm;
>>                   json: [:json | json object: [ ] ];
>>                  onSuccess: 'console.log(arguments[0])');
>>    with: 'Filter!'
>> ]
>>
>> cheers
>> Johan
>>
>> On 03 Mar 2014, at 07:21, Johan Brichau <[hidden email]> wrote:
>>
>>>
>>> On 03 Mar 2014, at 02:09, Esteban A. Maringolo <[hidden email]> wrote:
>>>
>>>> Any suggestion?
>>>
>>> That's because the button is triggering a submit. Change it to a push button as follows:
>>>
>>> html form: [
>>> "...snipped code"
>>> html button
>>>   onClick:  (html jQuery ajax
>>>                  serializeForm;
>>>                  onComplete: (
>>>                    html jQuery getJson
>>>                      json: [:json | self renderJsonResponseOn: json ];
>>>                      onSuccess: 'console.log(arguments[0])'));
>>>   with: 'Filter!'
>>> ]
>>>
>>>> ps: Is there a way to generate pretty-printed JS and HTML source?
>>>
>>> afaik, you have to use the browser development tools for that:
>>>
>>> https://plus.google.com/+AddyOsmani/posts/Q7t2U51G7YR
>>>
>>> cheers
>>> Johan
>>
>> _______________________________________________
>> seaside mailing list
>> [hidden email]
>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Javascript calls through jQuery

Esteban A. Maringolo
Answering myself, I found a semi-convoluted way of doing this.

But I had to extend JSFunction to support naming (it's optional):

html document
addLoadScript: (
 ((html jQuery getJson
     json: [ :r | self renderStoresJsonOn: r ];
     onSuccess: (JSStream on:
'updateStores(arguments[0]);setTimeout(updateMarkers,5000)')
asFunction
   ) asFunction name: 'updateMarkers') create call: #())

Produces:
new function updateMarkers() {
  $.getJSON("/ps/map", ["_s=W75cKXp9auCYja7o", "_k=cpawshsKuiBgsSoN",
"12"].join("&"), function () {
    updateStores(arguments[0]);
    setTimeout(updateMarkers, 5000)
   })
}();

The trick is in the naming of the function (and it's recurrent call
from within) and the #create decoration which followed by a #call: is
a way to implement "immediately invoked function expression" in JS
(IIFE for short).

I still have to learn how all the JavaScript/jQuery wrappers work, but
so far it's impressive how much you can do writing a few lines of
Smalltalk.

If there is a way of doing this without having to modify JSFunction
I'll be happy to use. Otherwise see attached changeset (and integrate
if necessary :) )


Regards!

Esteban A. Maringolo


2014-03-03 11:06 GMT-03:00 Esteban A. Maringolo <[hidden email]>:

> Let's add a twist to this... I want to a have a recurrent polling to
> the #json: callback I implemented above.
>
> I had the following load script written in plain JS:
>
>         (function getStoresStatus(){
>                 $.ajax({url: '/ps/rest/store-status', dataType: 'json'}).done(
>                         function(response){
>                                 jQuery.each(response, function(index, value){
>                                         updateStoreMarker(value)});
>                                 setTimeout(getStoresStatus,30000)
>                         }
>                 );
>         }());
>
>
> How can I do the same using Seaside Jquery functions?
>
> Regards!
>
> Esteban A. Maringolo
>
>
> 2014-03-03 10:27 GMT-03:00 Esteban A. Maringolo <[hidden email]>:
>> Good day Johan,
>>
>> I thought WAButtonTag was push by default, I didn't check.
>>
>> I moved the #json: method from JQGetJson to JQAjax, and chained
>> #serializeForm and #json: on the same ajax object and it worked.
>> Thanks!
>>
>> I don't know how Seaside manages to read the serialized form values
>> from the query string, but in this very moment I don't care much
>> either :)
>>
>> By now it works as expected. I'll surely come back later with more questions.
>>
>>
>> Thanks again.
>>
>> ps: Is the #json: method going to be added to Seaside-Jquery main trunk?
>> Esteban A. Maringolo
>>
>>
>> 2014-03-03 4:07 GMT-03:00 Johan Brichau <[hidden email]>:
>>> Esteban,
>>>
>>> Mind that you can combine these ajax calls in the following way:
>>>
>>> html form: [
>>> "...snipped code"
>>>  html button
>>>         bePush;
>>>         onClick:  (html jQuery ajax
>>>                   serializeForm;
>>>                   json: [:json | json object: [ ] ];
>>>                  onSuccess: 'console.log(arguments[0])');
>>>    with: 'Filter!'
>>> ]
>>>
>>> cheers
>>> Johan
>>>
>>> On 03 Mar 2014, at 07:21, Johan Brichau <[hidden email]> wrote:
>>>
>>>>
>>>> On 03 Mar 2014, at 02:09, Esteban A. Maringolo <[hidden email]> wrote:
>>>>
>>>>> Any suggestion?
>>>>
>>>> That's because the button is triggering a submit. Change it to a push button as follows:
>>>>
>>>> html form: [
>>>> "...snipped code"
>>>> html button
>>>>   onClick:  (html jQuery ajax
>>>>                  serializeForm;
>>>>                  onComplete: (
>>>>                    html jQuery getJson
>>>>                      json: [:json | self renderJsonResponseOn: json ];
>>>>                      onSuccess: 'console.log(arguments[0])'));
>>>>   with: 'Filter!'
>>>> ]
>>>>
>>>>> ps: Is there a way to generate pretty-printed JS and HTML source?
>>>>
>>>> afaik, you have to use the browser development tools for that:
>>>>
>>>> https://plus.google.com/+AddyOsmani/posts/Q7t2U51G7YR
>>>>
>>>> cheers
>>>> Johan
>>>
>>> _______________________________________________
>>> seaside mailing list
>>> [hidden email]
>>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

JSFunction.EstebanMaringolo.cs (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Javascript calls through jQuery

Bob Arning-2
just lurking, but perhaps this is what you need:


On 12/18/13 7:07 PM, Johan Brichau wrote:
The Javascript wrappers in Seaside (JSObject subclasses) provide a number of convenience methods to achieve this.
For example:

html script: ((html jQuery ajax callback:[ ]) asFunction assignTo: 'myfunction').

Then just call myfunction() from your javascripts.

cheers
Johan


On 3/3/14 10:38 AM, Esteban A. Maringolo wrote:
The trick is in the naming of the function (and it's recurrent call
from within) and the #create decoration which followed by a #call: is
a way to implement "immediately invoked function expression" in JS
(IIFE for short).

I still have to learn how all the JavaScript/jQuery wrappers work, but
so far it's impressive how much you can do writing a few lines of
Smalltalk.

If there is a way of doing this without having to modify JSFunction
I'll be happy to use. Otherwise see attached changeset (and integrate
if necessary :) )



_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Javascript calls through jQuery

Esteban A. Maringolo
Hi Bob,
2014-03-03 12:55 GMT-03:00 Bob Arning <[hidden email]>:

> just lurking, but perhaps this is what you need:
>
>
> On 12/18/13 7:07 PM, Johan Brichau wrote:
>
> The Javascript wrappers in Seaside (JSObject subclasses) provide a number of
> convenience methods to achieve this.
> For example:
>
> html script: ((html jQuery ajax callback:[ ]) asFunction assignTo:
> 'myfunction').
>
> Then just call myfunction() from your javascripts.

Thanks for your suggestion.
I changed my code to work like that and it worked.
I was obssesed with using IIFE, for no strict reason.

I guess if you wan to do IIFE, as long as the function is not
recurrent, you can do it without defining a function name.

Thanks again!

Esteban A. Maringolo
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Javascript calls through jQuery

jtuchel
In reply to this post by Bob Arning-2
wow, there is something new to learn about Seaside and JS/jQuery every day. Thanks for digging this out, I wasn't aware of the fact that you can define js functions and make them callable for the js side in Seaside...



Am 03.03.14 16:55, schrieb Bob Arning:
just lurking, but perhaps this is what you need:


On 12/18/13 7:07 PM, Johan Brichau wrote:
The Javascript wrappers in Seaside (JSObject subclasses) provide a number of convenience methods to achieve this.
For example:

html script: ((html jQuery ajax callback:[ ]) asFunction assignTo: 'myfunction').

Then just call myfunction() from your javascripts.

cheers
Johan


On 3/3/14 10:38 AM, Esteban A. Maringolo wrote:
The trick is in the naming of the function (and it's recurrent call
from within) and the #create decoration which followed by a #call: is
a way to implement "immediately invoked function expression" in JS
(IIFE for short).

I still have to learn how all the JavaScript/jQuery wrappers work, but
so far it's impressive how much you can do writing a few lines of
Smalltalk.

If there is a way of doing this without having to modify JSFunction
I'll be happy to use. Otherwise see attached changeset (and integrate
if necessary :) )




_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside


-- 
-----------------------------------------------------------------------
Objektfabrik Joachim Tuchel          [hidden email]
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


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Javascript calls through jQuery

Sven Van Caekenberghe-2
In reply to this post by Bob Arning-2

On 03 Mar 2014, at 16:55, Bob Arning <[hidden email]> wrote:

> just lurking, but perhaps this is what you need:
>
>
> On 12/18/13 7:07 PM, Johan Brichau wrote:
> The Javascript wrappers in Seaside (JSObject subclasses) provide a number of convenience methods to achieve this.
> For example:
>
> html script: ((html jQuery ajax callback:[ ]) asFunction assignTo: 'myfunction').
>
> Then just call myfunction() from your javascripts.
>
> cheers
> Johan

Someone, I think Johan (;-), has to take some time to write an 'Advanced JQuery' chapter for the Seaside book, or a whole new chapter, or new book, or whatever. There is so much to learn ...

>
> On 3/3/14 10:38 AM, Esteban A. Maringolo wrote:
>> The trick is in the naming of the function (and it's recurrent call
>> from within) and the #create decoration which followed by a #call: is
>> a way to implement "immediately invoked function expression" in JS
>> (IIFE for short).
>>
>> I still have to learn how all the JavaScript/jQuery wrappers work, but
>> so far it's impressive how much you can do writing a few lines of
>> Smalltalk.
>>
>> If there is a way of doing this without having to modify JSFunction
>> I'll be happy to use. Otherwise see attached changeset (and integrate
>> if necessary
>> :)
>>  )
>>
>>
>
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Javascript calls through jQuery

Johan Brichau-2

On 04 Mar 2014, at 09:01, Sven Van Caekenberghe <[hidden email]> wrote:

> Someone, I think Johan (;-), has to take some time to write an 'Advanced JQuery' chapter for the Seaside book, or a whole new chapter, or new book, or whatever. There is so much to learn ...

I hear you ;-)
Filling up the existing book would already be an achievement. But yes, it crossed my mind too that this information is not explicitly written down somewhere and it should be.
I will first to try to finalize the tasks I started for Seaside (jquery upgrade, automated tests, gemstone port) before starting this next task.

cheers
Johan_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Javascript calls through jQuery

Sven Van Caekenberghe-2

On 04 Mar 2014, at 10:38, Johan Brichau <[hidden email]> wrote:

>
> On 04 Mar 2014, at 09:01, Sven Van Caekenberghe <[hidden email]> wrote:
>
>> Someone, I think Johan (;-), has to take some time to write an 'Advanced JQuery' chapter for the Seaside book, or a whole new chapter, or new book, or whatever. There is so much to learn ...
>
> I hear you ;-)
> Filling up the existing book would already be an achievement. But yes, it crossed my mind too that this information is not explicitly written down somewhere and it should be.
> I will first to try to finalize the tasks I started for Seaside (jquery upgrade, automated tests, gemstone port) before starting this next task.

Thanks Johan, I think it will also help you: you can then point to more written documentation instead of answering each question individually. Looking forward to it !

> cheers
> Johan_______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside