add parameter to settings onAjaxError/ajaxErrorHandler

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

add parameter to settings onAjaxError/ajaxErrorHandler

Sabine Manaa
Hi,

I have a working solution for redirect the user to the login page as described here [1][2][3].

In short words:
I add addLoadScript: html jQuery document onAjaxError: (self ajaxErrorHandler asFunction: #('event' 'jqxhr' 'settings' 'exception')))
with >>ajaxErrorHandler
^ ' if (jqxhr.status == 403) {
   alert("Logoff text.......");
   window.location.href = settings.url.split("?")[0].replace("help","");
   } else {
   if (jqxhr.status == 200) { } else {  
   alert("error text.....: " + exception +"jqxhr.status:"+jqxhr.status); }}'

I want to add one more point as described here:
http://stackoverflow.com/a/7462590/2611391

I want to suppress this error message dialog in one certain case with something like this:
 if(settings.suppressErrors) {
        return;
    }

So my question is how can I add a value like 'suppressErrors' to my settings object so that in the ajaxErrorHandler I can ask for 'settings.suppressErrors'...

Regards
Sabine

[1]http://forum.world.st/Custom-error-handler-for-Seaside-expiration-and-AJAX-errors-WAS-Re-Seaside-AJAX-script-amp-html-vs-o-td4916950.html
[2]http://forum.world.st/Improved-HTML-error-handler-td4927552.html#a4927734
[3]http://forum.world.st/Ajax-requests-not-redirecting-to-Login-page-after-session-timeout-td4802509.html#a4802521

After logoff AND deleting the users account
Reply | Threaded
Open this post in threaded view
|

Re: add parameter to settings onAjaxError/ajaxErrorHandler

Johan Brichau-2
Hi Sabine,

The settings object you get in the global ajax error handler is the one passed to the ajax call that is the origin of the error.
From Seaside, this object is in the ‘options’ instVar of any JQAjax instance. Hence:

html jQuery ajax
        …
        optionAt: ‘suppressErrors’ put: <someJavaScriptValue>;

would do the trick.

Mind that this means the value for ‘suppressErrors’ is being generated when your page is rendered.
So, if the value depends on a runtime value, registering a function and calling that will be necessary.

Hope this helps
Johan

> On 6 Feb 2017, at 11:57, Sabine Manaa <[hidden email]> wrote:
>
> Hi,
>
> I have a working solution for redirect the user to the login page as
> described here [1][2][3].
>
> In short words:
> I add addLoadScript: html jQuery document onAjaxError: (self
> ajaxErrorHandler asFunction: #('event' 'jqxhr' 'settings' 'exception')))
> with >>ajaxErrorHandler
> ^ ' if (jqxhr.status == 403) {
>   alert("Logoff text.......");
>   window.location.href = settings.url.split("?")[0].replace("help","");
>   } else {
>   if (jqxhr.status == 200) { } else {  
>   alert("error text.....: " + exception +"jqxhr.status:"+jqxhr.status); }}'
>
> I want to add one more point as described here:
> http://stackoverflow.com/a/7462590/2611391
>
> I want to suppress this error message dialog in one certain case with
> something like this:
> if(settings.suppressErrors) {
>        return;
>    }
>
> So my question is how can I add a value like 'suppressErrors' to my settings
> object so that in the ajaxErrorHandler I can ask for
> 'settings.suppressErrors'...
>
> Regards
> Sabine
>
> [1]http://forum.world.st/Custom-error-handler-for-Seaside-expiration-and-AJAX-errors-WAS-Re-Seaside-AJAX-script-amp-html-vs-o-td4916950.html
> [2]http://forum.world.st/Improved-HTML-error-handler-td4927552.html#a4927734
> [3]http://forum.world.st/Ajax-requests-not-redirecting-to-Login-page-after-session-timeout-td4802509.html#a4802521
>
> After logoff AND deleting the users account
>
>
>
> --
> View this message in context: http://forum.world.st/add-parameter-to-settings-onAjaxError-ajaxErrorHandler-tp4933109.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
Reply | Threaded
Open this post in threaded view
|

Re: add parameter to settings onAjaxError/ajaxErrorHandler

Sabine Manaa
Hi Johan,

thank you for your answer! (I saw that you answered Joachims very interesting question and was hoping that you would come to mine, too, and, yeah, I have an answer :-))

I tried it with a simple example and can reproduce it.

Unfortunately, my case has one more problem/step where I ask you for help.

The situation is: My user decided to delete its account by click on a button. Then I delete the user from database, remove his session and transfer him to a page where I ask for the reason why he wants to leave (I hope this will be needed never haha). In this situation, there is no session anymore and normally, my error handler dialog (onAjaxError) would pop up ("There is no session, please log in again bla bla").

I do it as suggested by you:
onClick:
        (html jQuery ajax
                optionAt: 'supressErrors' put: 'true';
                script: [ :script |
                        "delete user, session etc "
                        script << (script jQuery id: self pageID) replaceWith: [ :h | RKADeletedAccountView new renderContentOn: h ] ]);
with: 'Ja'.

If I would not transfer the user to the RKADeletedAccountView but would stay at the current page, the supressErrors variable would be available.

But within the RKADeletedAccountView, the variable is not visible. Is there a way to have this information also in the new rendered RKADeletedAccountView/avoid that the Ajax error handler pops up?

(BTW: I render the RKADeletedAccountView within the existing html head by replacing my node "pageID" by the form for requesting the info from the user. So, I save loading all css etc head stuff again, this is how my whole application works. If there is no other alternative, I think I could also load all and do not register the error handler. But having the  "supressErrors" solution seems to be smarter to me.)

Regards
Sabine

Reply | Threaded
Open this post in threaded view
|

Re: add parameter to settings onAjaxError/ajaxErrorHandler

Johan Brichau-2
Hi Sabine,

The ‘suppressErrors’ setting is added only to the ajax request in your code snippet.
Do you mean the callbacks generated inside RKADeletedAccountView are missing the ‘supressErrors’ setting?

Since it’s a setting of an individual ajax request, my understanding is you need to add it to every ajax request you need it.
Maybe I’m not entirely understanding what you mean with "the supressErrors variable would be available” ?
Do you mean on the client-side or on the server-side?

The way you work with replacing a page using an ajax request is certainly viable.
What element of the page is your pageID attached to? <body>?

cheers
Johan

> On 11 Feb 2017, at 12:25, Sabine Manaa <[hidden email]> wrote:
>
> Hi Johan,
>
> thank you for your answer! (I saw that you answered Joachims very
> interesting question and was hoping that you would come to mine, too, and,
> yeah, I have an answer :-))
>
> I tried it with a simple example and can reproduce it.
>
> Unfortunately, my case has one more problem/step where I ask you for help.
>
> The situation is: My user decided to delete its account by click on a
> button. Then I delete the user from database, remove his session and
> transfer him to a page where I ask for the reason why he wants to leave (I
> hope this will be needed never haha). In this situation, there is no session
> anymore and normally, my error handler dialog (onAjaxError) would pop up
> ("There is no session, please log in again bla bla").
>
> I do it as suggested by you:
> onClick:
> (html jQuery ajax
> optionAt: 'supressErrors' put: 'true';
> script: [ :script |
> "delete user, session etc "
> script << (script jQuery id: self pageID) replaceWith: [ :h |
> RKADeletedAccountView new renderContentOn: h ] ]);
> with: 'Ja'.
>
> If I would not transfer the user to the RKADeletedAccountView but would stay
> at the current page, the supressErrors variable would be available.
>
> But within the RKADeletedAccountView, the variable is not visible. Is there
> a way to have this information also in the new rendered
> RKADeletedAccountView/avoid that the Ajax error handler pops up?
>
> (BTW: I render the RKADeletedAccountView within the existing html head by
> replacing my node "pageID" by the form for requesting the info from the
> user. So, I save loading all css etc head stuff again, this is how my whole
> application works. If there is no other alternative, I think I could also
> load all and do not register the error handler. But having the
> "supressErrors" solution seems to be smarter to me.)
>
> Regards
> Sabine
>
>
>
>
>
> --
> View this message in context: http://forum.world.st/add-parameter-to-settings-onAjaxError-ajaxErrorHandler-tp4933109p4933917.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
Reply | Threaded
Open this post in threaded view
|

Re: add parameter to settings onAjaxError/ajaxErrorHandler

Sabine Manaa
Hi Johan,

sorry for not being clear enough. The supressErrors variable is available in the Ajax request of  my code snippet but not in the callbacks generated inside RKADeletedAccountView and this was my problem. While writing the answer I came to the point, that I have to add the suppressErrors option also in the RKADeletedAccountViews Ajax requests. Silly. I was missing that because I use one method with parameters for all my form elements and so I forgot that I have Ajax requests there, too (onFocus, onBlur, serialize). So, the problem is solved and it works perfect!

Thanks for your help again and I certainly would try to join the seaside course for Joachim, too :-)

The pageID is attached to the body:
<body id="page" onload="onLoad()" style="">

BTW: did you proceed in the "back button" topic? I once (3 years now) asked and also found a working solution ([1]). But now the history.js is no longer supported and I am looking for another solution. I don't need to show old data, I only want to show the pages in the order they were called...with the newest data.

Regards and have a nice Sunday.

Sabine