[Seaside] Execute jQuery script upon #onAjaxComplete?

Mariano Martinez Peck marianopeck at gmail.com
Fri Sep 23 20:58:54 UTC 2016


Well, with help from Esteban the (via chat), this ended up working as I
expected:


html document addLoadScript: (
html jQuery document onAjaxComplete:(
html jQuery
ajax
global: false; "to avoid inifite recursion"
script: [ :s | s <<  ( (html jQuery id: self classicMenuComponent
systemMessageNotifier mainDivId)
replaceWith: [:r | self classicMenuComponent systemMessageNotifier
renderContentOn: r ]
) ]
)
)



Thanks for the help!

On Fri, Sep 23, 2016 at 5:30 PM, Esteban A. Maringolo <emaringolo at gmail.com>
wrote:

> Try this:
>
> html document addLoadScript: (
>   html jQuery document onAjaxComplete: (
>     (html jQuery id: self  systemMessageNotifier mainDivId)
>        load
>          global: false; "to avoid infinite recursion see [1]"
>          html: [:r | self systemMessageNotifier renderContentOn: r ]
>      )
> ).
>
> [1] If $.ajax() or $.ajaxSetup() is called with the global option set
> to false, the .ajaxComplete() method will not fire.
> <http://api.jquery.com/ajaxComplete/>
> Esteban A. Maringolo
>
>
> 2016-09-23 16:07 GMT-03:00 Mariano Martinez Peck <marianopeck at gmail.com>:
> >
> >
> > On Fri, Sep 23, 2016 at 3:23 PM, Esteban A. Maringolo <
> emaringolo at gmail.com>
> > wrote:
> >>
> >> 2016-09-23 12:21 GMT-03:00 Mariano Martinez Peck <marianopeck at gmail.com
> >:
> >> > The problem, as usual, is all ajax requests (and my app is now almost
> >> > everything with ajax).
> >> > I need to hook on ajax calls so that I could also re-render the
> >> > notifications components as
> >> > there could have been new notifications since the last rendering.
> >>
> >> > html
> >> > document
> >> > addLoadScript: (html jQuery document
> >> >                      onAjaxComplete: (
> >> >   (html jQuery id: self  systemMessageNotifier mainDivId)
> replaceWith:
> >> > [:r |
> >> > self systemMessageNotifier renderContentOn: r.
> >> > ]
> >> > )).
> >>
> >> > What I don't know how to do is what I want hahhaa.
> >> >I would try to avoid WebSockets for the moment. I
> >> > thought maybe doing some jQuery polling ?
> >>
> >> I don't understand what you want to implement.
> >
> >
> > Let's say... an admin user of the app, fires a broadcast message. This
> is a
> > message object stored in the DB. All logged users, should render the
> active
> > messages on the main header of the app. Something like "server is going
> to
> > be restarted in 10 minutes". Or whatever. So what I wanted to do is that
> > whenever the user "uses" the app, I would check if there are
> notifications
> > and show them. With normal requests this is easy as the main messages
> header
> > is re-rendered together with the whole page.
> >
> > My problem is how to re-render that component (of the main header) on
> > EACH/ALL ajax callbacks. Why? Because most of my app is now with ajax,
> none
> > of the ajax calls will re-render the "header" nor the component that
> renders
> > the alerts. So.. no alert is shown until I do a normal request.
> >
> > So...what I don't know how to do is a generic way in which I can
> re-render
> > the messages component on each ajax callback.
> >
> >>
> >>
> >> If you want to notify something, then such notification should come as
> >> a response of the xhr and implement the ajaxComplete function handler
> >> to parse the response searching for the notification you want to
> >> display.
> >
> >
> > The notifications comes from a query in the DB. There could be
> notifications
> > still valid and the user just entered to the app for example.
> >
> >>
> >>
> >> The alternative is to include a <script> in every ajax response to
> >> update the notification on the client side.
> >
> >
> >
> > And how could I do this in a generic way (not on every ajax response) ?
> >
> > Thanks in advance!
> >
> >>
> >>
> >> I also don't see how you using websockets would benefit you unless you
> >> hook the socket to an announcer.
> >>
> >> Regards,
> >>
> >> --
> >> Esteban
> >> _______________________________________________
> >> 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/20160923/6461dbd9/attachment.htm


More information about the seaside mailing list