Hi, I want to achieve the following: In a list of objects you can click on one of them in order to delete it. I want to show an ajax confirm dialog, which calls an ajax callback if the user clicks on OK and then redraw the list. The deletion will affect more than just an object not being in the list any more, so I'd like to redraw the whole list once the object is deleted on the server side. So far, I've come up with this onClick: code: (s jQuery ajax confirm: 'Do you really want to delete this object?'; callback: [self deleteObject: obj]) onComplete: ( s jQuery this load html: [:t | self renderListOn: t]) And it seems to work fine on Firefox, but not on Safari and Chrome (But maybe it also is just a timing issue). It seems like the onComplete: callback is being called as soon as the confirm: has completed, not after the deletion on the server has finished. So on Chrome and Safari the redraw is done too early and the object is still being rendered in the list. So I need to wait with the #renderListOn: until 'callback: [self deleteObject: obj]' has finished. So can somebody please * confirm that the way I try above is wrong and the onComplete is not related to the confirm:'s callback? * shed some light on how I would attach an onComplete callback to the result of ' callback: [self deleteObject: obj])' I guess it's simple, but I cannot find the right solution on my own... Any help is appreciated. Joachim |
Funnily, the code Seaside generates looks as if it does what I want:
if(confirm("Do you really want to delete this object?")) { $.ajax({ "url":"/MyApp", "data":["_s=XON7moFvT7ejEWMY","_k=OBzPflVTFHdzvNyy","20"].join("&"), "complete":function(){ $(this).load("/MyApp",["_s=XON7moFvT7ejEWMY","_k=OBzPflVTFHdzvNyy","21"].join("&")) } }) } I read this as if user clicks OK, call the ajax callback which deletes on the server side, and when that is complete, load the contents of the list again and have it rendered by the server. So maybe I am not really hunting for the complete event, but what else? Or is it so that the ajax call to a server side callback does not wait for the server side to finish? Does Seaside return an HTTP response immediately? If so, what tricks are there to wait for the server to finish deleting and redraw after that? Thanks for reading Joachim |
Hi Joachim,
I do it like this: (html jQuery post confirm: 'Do you really want to delete this object?'; script: [ :s | self deleteObject: obj. s << s jQuery this load html: [:t | self renderListOn: t] ]); The #script: is a script rendering callback that only gets run if the confirm is confirmed (accepted?). You might have to change the send of #this to the specific #id you mean to load into. But I'm not sure if its the best way. And would love to learn how to make it better/safer if there are obvious errors. Good luck Paul On 07/19/2012 05:21 AM, jtuchel wrote: > Funnily, the code Seaside generates looks as if it does what I want: > > if(confirm("Do you really want to delete this object?")) > { > $.ajax({ > "url":"/MyApp", > > "data":["_s=XON7moFvT7ejEWMY","_k=OBzPflVTFHdzvNyy","20"].join("&"), > "complete":function(){ > > $(this).load("/MyApp",["_s=XON7moFvT7ejEWMY","_k=OBzPflVTFHdzvNyy","21"].join("&")) > } > }) > } > > I read this as if user clicks OK, call the ajax callback which deletes on > the server side, and when that is complete, load the contents of the list > again and have it rendered by the server. > > So maybe I am not really hunting for the complete event, but what else? > Or is it so that the ajax call to a server side callback does not wait for > the server side to finish? Does Seaside return an HTTP response immediately? > If so, what tricks are there to wait for the server to finish deleting and > redraw after that? > > Thanks for reading > > Joachim > > -- > View this message in context: http://forum.world.st/Jquery-Ajax-confirm-callback-problem-tp4640695p4640697.html > Sent from the Seaside General mailing list archive at Nabble.com. > _______________________________________________ > 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 |
Paul,
thanks for answering.
Unfortunately, it doesn't work for me. It leaves me with a blank page on Chrome and a text-only page containing teh html of the complete page re-rendered. Even if I replace the jQuery this with the concrete ID of my list, it doesn't work.
Wouldn't a POST request reload the whole page anyways?
Joachim
Paul DeBruicker <[hidden email]> hat am 19. Juli 2012 um 17:11 geschrieben: > Hi Joachim, > > I do it like this: > > (html jQuery post > confirm: 'Do you really want to delete this object?'; > script: [ :s | > self deleteObject: obj. > s << s jQuery this load html: [:t | self renderListOn: t] ]); > > > The #script: is a script rendering callback that only gets run if the > confirm is confirmed (accepted?). You might have to change the send of > #this to the specific #id you mean to load into. > > But I'm not sure if its the best way. And would love to learn how to > make it better/safer if there are obvious errors. > > > > Good luck > > Paul > > > > > > > > On 07/19/2012 05:21 AM, jtuchel wrote: > > Funnily, the code Seaside generates looks as if it does what I want: > > > > if(confirm("Do you really want to delete this object?")) > > { > > $.ajax({ > > "url":"/MyApp", > > > > "data":["_s=XON7moFvT7ejEWMY","_k=OBzPflVTFHdzvNyy","20"].join("&"), > > "complete":function(){ > > > > $(this).load("/MyApp",["_s=XON7moFvT7ejEWMY","_k=OBzPflVTFHdzvNyy","21"].join("&")) > > } > > }) > > } > > > > I read this as if user clicks OK, call the ajax callback which deletes on > > the server side, and when that is complete, load the contents of the list > > again and have it rendered by the server. > > > > So maybe I am not really hunting for the complete event, but what else? > > Or is it so that the ajax call to a server side callback does not wait for > > the server side to finish? Does Seaside return an HTTP response immediately? > > If so, what tricks are there to wait for the server to finish deleting and > > redraw after that? > > > > Thanks for reading > > > > Joachim > > > > -- > > View this message in context: http://forum.world.st/Jquery-Ajax-confirm-callback-problem-tp4640695p4640697.html > > Sent from the Seaside General mailing list archive at Nabble.com. > > _______________________________________________ > > 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 |
I would try moving the code from the callback: block into the load html: block but leave everything else the same as in the original code.
On Fri, Jul 20, 2012 at 2:22 AM, Joachim Tuchel (objektfabrik) <[hidden email]> wrote:
_______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
I think you want to change as follows: post -> ajax jQuery this -> jQuery id: someId load html: -> replaceWith: & properly parenthesize such that: s << (...) I'll try to remember posting a complete answer when I get back as well.
_______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
In reply to this post by jtuchel
On 07/19/2012 11:22 PM, Joachim Tuchel (objektfabrik) wrote:
> Unfortunately, it doesn't work for me. It leaves me with a blank page on > Chrome and a text-only page containing teh html of the complete page > re-rendered. Even if I replace the jQuery this with the concrete ID of > my list, it doesn't work. > > Wouldn't a POST request reload the whole page anyways? > Sorry that didn't work. I think Johan was right about my missing parens. The ajax POST doesn't reload the whole page. It just sends the info to the server as a POST rather than GET which I'd thought was the thing to do if you were deleting something and a DELETE wasn't a supported part of the library. See: http://www.cs.tut.fi/~jkorpela/forms/methods.html & http://stackoverflow.com/questions/715335/get-vs-post-in-ajax#715355 jQuery's ajax post docs are here: http://docs.jquery.com/Post I'll try to think of why else its not correct and get back to you. _______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
Paul, Johan,
so this is what my code looks like right now: s jQuery ajax confirm: 'Do you really want to delete this object?'; script: [:t| self deleteObject: obj. t << (t jQuery id: link id) load "link is the anchor tag" html: [:q | self renderChildrenOn: q]] Which is a mix of your suggestions. It does work perfectly on Firefox: I get asked if I want to delete, and only if I click OK the object is deleted and the list is re-rendered. On Chrome, however, I get the confirmation dialog and it does nothing if I click cancel, but it also does nothing if I hit OK. A breakpoint in #deleteObject: never fires. So it seems like the script: doesn't work on Chrome (which I cannot believe). Joachim Am 20.07.12 19:00, schrieb Paul DeBruicker: > On 07/19/2012 11:22 PM, Joachim Tuchel (objektfabrik) wrote: >> Unfortunately, it doesn't work for me. It leaves me with a blank page on >> Chrome and a text-only page containing teh html of the complete page >> re-rendered. Even if I replace the jQuery this with the concrete ID of >> my list, it doesn't work. >> >> Wouldn't a POST request reload the whole page anyways? >> > > > Sorry that didn't work. I think Johan was right about my missing parens. > > The ajax POST doesn't reload the whole page. It just sends the info > to the server as a POST rather than GET which I'd thought was the > thing to do if you were deleting something and a DELETE wasn't a > supported part of the library. > > > See: http://www.cs.tut.fi/~jkorpela/forms/methods.html & > http://stackoverflow.com/questions/715335/get-vs-post-in-ajax#715355 > > jQuery's ajax post docs are here: http://docs.jquery.com/Post > > > I'll try to think of why else its not correct and get back to you. -- ----------------------------------------------------------------------- Objektfabrik Joachim Tuchel mailto:[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 smime.p7s (7K) Download Attachment |
Joachim Tuchel <jtuchel <at> objektfabrik.de> writes:
> > Paul, Johan, > > so this is what my code looks like right now: > > s jQuery ajax > > confirm: 'Do you really want to delete this object?'; > script: [:t| > self deleteObject: obj. > t << (t jQuery id: link id) load "link is the anchor tag" > html: [:q | self renderChildrenOn: q]] > Would you share your entire code as a pastebin (http://paste.ubuntu.com/). I think there is a race condition with the confirm. Chrome and Safari may show different behavior from Firefox. Thanks _______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
In reply to this post by jtuchel
Hi again,
I gave up on this and wrote a little jQuery plugin. It works on both Firefox and Chrome. This confirm: stuff took too much time to understand and test... Nevertheless, thank you for your help. Joachim Am 23.07.12 14:33, schrieb Joachim Tuchel: > Paul, Johan, > > so this is what my code looks like right now: > > s jQuery ajax > > confirm: 'Do you really want to delete this object?'; > script: [:t| > self deleteObject: obj. > t << (t jQuery id: link id) load "link is the anchor tag" > html: [:q | self renderChildrenOn: q]] > > > Which is a mix of your suggestions. It does work perfectly on Firefox: > I get asked if I want to delete, and only if I click OK the object is > deleted and the list is re-rendered. > > On Chrome, however, I get the confirmation dialog and it does nothing > if I click cancel, but it also does nothing if I hit OK. > A breakpoint in #deleteObject: never fires. So it seems like the > script: doesn't work on Chrome (which I cannot believe). > > > Joachim > > > > > Am 20.07.12 19:00, schrieb Paul DeBruicker: >> On 07/19/2012 11:22 PM, Joachim Tuchel (objektfabrik) wrote: >>> Unfortunately, it doesn't work for me. It leaves me with a blank >>> page on >>> Chrome and a text-only page containing teh html of the complete page >>> re-rendered. Even if I replace the jQuery this with the concrete ID of >>> my list, it doesn't work. >>> >>> Wouldn't a POST request reload the whole page anyways? >>> >> >> >> Sorry that didn't work. I think Johan was right about my missing parens. >> >> The ajax POST doesn't reload the whole page. It just sends the info >> to the server as a POST rather than GET which I'd thought was the >> thing to do if you were deleting something and a DELETE wasn't a >> supported part of the library. >> >> >> See: http://www.cs.tut.fi/~jkorpela/forms/methods.html & >> http://stackoverflow.com/questions/715335/get-vs-post-in-ajax#715355 >> >> jQuery's ajax post docs are here: http://docs.jquery.com/Post >> >> >> I'll try to think of why else its not correct and get back to you. > > > > _______________________________________________ > seaside mailing list > [hidden email] > http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside -- ----------------------------------------------------------------------- Objektfabrik Joachim Tuchel mailto:[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 smime.p7s (7K) Download Attachment |
Hi Joachim,
Sorry it did not work that easily. Strange that it worked on FF and not on Chrome but I could make it work just fine in both like this: renderContentOn: html | id | html anchor id: (id := html nextId); onClick: (html jQuery ajax confirm: 'Do you really want to replace me?'; script: [:s| linkText := 'I am the replaced one'. s << ((s jQuery id: id) replaceWith: [:h | self renderOn: h])]); with: linkText. linkText is an instance variable of the component, first initialized like this: initialize super initialize. linkText := 'I am the original one' Mind that #load is a specific ajax request that will replace the inner contents of the receiving jQuery selector with the rendering done by its 'html: aBlock' argument. It's not useful to launch it from within another ajax callback block, especially because you can more easily use a replaceWith: (or innerReplaceWith:). You *could* return a script that executes an ajax load, but that means 2 ajax callbacks (one for the delete + load script and one for the actual load of the new html). There are many ways to puzzle together ajax calls. An (untested) variant using an ajax load where only a single ajax callback occurs might be: renderContentOn: html | id | html anchor id: (id := html nextId); onClick: (html jQuery ajax confirm: 'Do you really want to replace me?'; script: ((html jQuery id: id) load html:[:h | linkText := 'I am the replaced one'. self renderOn: h])); with: linkText. Obviously, you should insert your actual statements (deleteObject) where needed in the callback. Hope this still helps you somewhat! Cheers Johan On 23 Jul 2012, at 21:02, Joachim Tuchel wrote: > Hi again, > > I gave up on this and wrote a little jQuery plugin. It works on both Firefox and Chrome. > This confirm: stuff took too much time to understand and test... > Nevertheless, thank you for your help. > > Joachim > > > Am 23.07.12 14:33, schrieb Joachim Tuchel: >> Paul, Johan, >> >> so this is what my code looks like right now: >> >> s jQuery ajax >> >> confirm: 'Do you really want to delete this object?'; >> script: [:t| >> self deleteObject: obj. >> t << (t jQuery id: link id) load "link is the anchor tag" >> html: [:q | self renderChildrenOn: q]] >> >> >> Which is a mix of your suggestions. It does work perfectly on Firefox: I get asked if I want to delete, and only if I click OK the object is deleted and the list is re-rendered. >> >> On Chrome, however, I get the confirmation dialog and it does nothing if I click cancel, but it also does nothing if I hit OK. >> A breakpoint in #deleteObject: never fires. So it seems like the script: doesn't work on Chrome (which I cannot believe). >> >> >> Joachim >> >> >> >> >> Am 20.07.12 19:00, schrieb Paul DeBruicker: >>> On 07/19/2012 11:22 PM, Joachim Tuchel (objektfabrik) wrote: >>>> Unfortunately, it doesn't work for me. It leaves me with a blank page on >>>> Chrome and a text-only page containing teh html of the complete page >>>> re-rendered. Even if I replace the jQuery this with the concrete ID of >>>> my list, it doesn't work. >>>> >>>> Wouldn't a POST request reload the whole page anyways? >>>> >>> >>> >>> Sorry that didn't work. I think Johan was right about my missing parens. >>> >>> The ajax POST doesn't reload the whole page. It just sends the info to the server as a POST rather than GET which I'd thought was the thing to do if you were deleting something and a DELETE wasn't a supported part of the library. >>> >>> >>> See: http://www.cs.tut.fi/~jkorpela/forms/methods.html & http://stackoverflow.com/questions/715335/get-vs-post-in-ajax#715355 >>> >>> jQuery's ajax post docs are here: http://docs.jquery.com/Post >>> >>> >>> I'll try to think of why else its not correct and get back to you. >> >> >> >> _______________________________________________ >> seaside mailing list >> [hidden email] >> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside > > -- > -- > ----------------------------------------------------------------------- Objektfabrik Joachim Tuchel mailto:[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 _______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
Free forum by Nabble | Edit this page |