We build. You grow.

Get best community software here

Start a social network, a fan-site, an education project with oxwall - free opensource community software

message timing (error, warning, info) | Forum

dave Leader
dave Feb 1 '20
Hi, does anyone happen to know how oxwall times their info, error, and warning messages.  It has to be some kind of animation or fadeOut in css but i have found nothing for those two items that has anything to do with messages.  I want to set my messages to stay longer on the page.  Im still digging :)   
dave Leader
dave Feb 1 '20
got it.... the sneaky devil....  its in ow/static/plugins/base/js/ow.js and its set to 3000 milliseconds which is about 3 seconds...  but since im not that good with js im not sure how to change the value per plugin...  its not like css where you can just re value the element... 


yes thats it as i changed it to 10000 from 3000 and the message stayed longer..  


so line 13 shows it has 3 params  message, type and paramTime


So i assume that the message and the type it gets from OW::getFeedback()  so what im trying is to add 1000 someplace in OW::getFeedback()  to see if i can set the paramTime from the plugin. 


OW::getFeedback()->warning($language->text('pluginname', 'plugin lang key goes here'));  


so there has to be a place in there somewhere to set the paramTime  parameter.  At least that sounds logical to me....  


SD do you have any idea since your awesome at JS :)



I dont see where they ever submit any time to the js function, they just let it fall through to the default var of 3000.  nothing i have seen so far does anything with that attribute...  


I was able to add the time to the message getFeedback array, but the time was not any longer..  So i will say i tried and leave this for someone else lol ....  its not that critical although would be nice to have the messages stay longer. 

The Forum post is edited by dave Feb 1 '20
dave Leader
dave Feb 1 '20
Maybe the best way for now is to just have customers change the time to lets say 9000 and that way 9 seconds is enough to read before they fade out.  
The Forum post is edited by dave Feb 1 '20
Senior Developer Leader
Senior Developer Feb 2 '20
If you want your plugin's toast alerts to stay longer, here is what you need to do:


In some cases we just add a JavaScript code in ajax calls, so lets start understanding what can we do in JS. Having this JavaScript code:

<script>

$( document ).ready(function() {  //we need this to make sure ow.js  is loaded by browser.        

  OW.warning( "this is a warning message" );         

  OW.error( "this is a error message" );        

  OW.info( "this is a info message" );

});

</script>

We can change them for:

<script>

$( document ).ready(function() {         

   OW.message("this is a warning message", 'warning', 1000); //here timer is set  to 1000 milliseconds.    

   OW.message("this is a warning message", 'error',5000); //50000 milliseconds = 5 seconds   

   OW.message("this is a warning message", 'info',10000); // 10 seconds

});

</script>


Both snippets do the same, but the messages from the second snippet stays longer.


As you can see,  OW.warning( "message" );
Is a shortcut for: OW.message("message", 'warning', 1000);


That's the javascript part to understand how it works.


Now lets see the PHP part of your plugin.

Let's say you save a form, display a message and add this feedback info:


OW::getFeedback()->info($language->text('pluginname',  'settings_changed'));


Previous code works perfectly always.


We can replace it for:

        $message = "This is the message";        

        $messageType = "warning"; // info | error        

         OW::getDocument()->addOnloadScript("OW.message(" . json_encode($message) . ", '" . $messageType . "', 9000);");


// 9000 = 9 seconds



But this will only work if THE USER IS NOT REDIRECTED after making the action (saving form data or something). This works in ajax calls as well.


If you already tested previous code and it works, stop reading, your problem is solved. 


If the user is redirected this script won't work as the message will be lost, in that case what you must do is this:

1 - *Save the message in a session's array var

2 - Add an event listener in your event_handler file which listens for OW_EventManager::ON_FINALIZE

3 - Inside your listener, get your session array with all saved messages, loop on each message, then add the code from above inside the loop.


*One easy way to To achieve this step 1 is extending OW_Feedback CLASS file, 

overriding  the __construct()   and  __destruct() methods to change the session's var name to avoid conflicts with the default feedback. 

Then you can add a message like this: MYPLUGIN_CLASS_Feedback::getInstance()->info($language->text('pluginname',  'settings_changed'));


In step 3, you get the messages calling this method:

$messages = MYPLUGIN_CLASS_Feedback::getInstance()->getFeedback();


That's it.


I hope I was clear enough, In case you need more detailed info please let me know.


Senior Developer.

The Forum post is edited by Senior Developer Feb 2 '20
Senior Developer Leader
Senior Developer Feb 2 '20

Quote from dave Maybe the best way for now is to just have customers change the time to lets say 9000 and that way 9 seconds is enough to read before they fade out.  
That's the easy way for us (developers), but it is not the best for the website's users as every toast will last 9 seconds, that kind of changes make the users feel or think that the website is slow, if you only need some toasts to last longer, making all toasts slower is not good in usability terms.
dave Leader
dave Feb 2 '20
thats excellent tutorial SD thanks so much.... i knew there was a way..  i never considered loading the ow.js   BRILLIANT  man...  thanks so much... :)  


However my earlier efforts was not all a lost cause, in the process i did finally figure out that you cant return a value from an ajax call..  but you can call another function and have that function do what you want....  So tonight is certainly a learning experience all round...


Thanks for the reply SD, it means alot to everyone :)


The Forum post is edited by dave Feb 2 '20
dave Leader
dave Feb 2 '20
Something came to me last night as i was resting... I dont remember the exact command but there was way back in the day to pass something inside the DOM itself, it was something like getvalue or setvalue and you could pass it from page to page almost like a DOM session but not quite that fancy, it was pretty raw but it did the job.   I would have to pull up an old script of mine to find it but i do remember it was pretty handy at the time.  


Also i know its not fancy but for just simple onclick events i usually use the alert for user notification.. I know its not standard to use it but for simple stuff it does the job just fine. 


I have also been told for security never to use innerHTML, you never want to give the user the ability to directly put anything in the document.   I have been watching alot of hack videos lately from people that used to hack but now work for law enforcment and they show you how hackers do it.  Its an eye opener for sure.  The point is you  cant beat them unless you know what they exploit and so education is the key to stopping things like that. 


I have even gone as far as to use a honey pot on some of my forms in another project. 


The Forum post is edited by dave Feb 2 '20
Senior Developer Leader
Senior Developer Feb 2 '20
At this point now I'm not really sure what exactly are you trying to do.


Do you need this custom time for displaying the message after an ajax call to your plugin?

If you can share (in public or private) some of the code that you already have, I can help you faster and save you some time.


Senior Developer.

The Forum post is edited by Senior Developer Feb 2 '20
dave Leader
dave Feb 3 '20
Sorry for the dribble drabble off topic, no i got it handled thanks...  I appreciate the offer so much...  :)


Yes it was about the message and redirect during the ajax check when the user runs out of credits while on the page already loaded (ie playing vids). But i got the redirect (page refresh) done by calling an external function from the ajax file when the user runs out of credits. 

 
And the message deal for play (using a listener) and download (onclick event) i just passed the message to an alert from the ajax file which does the job.  Would i like the user to have a fancy message, sure i would, but honestly im not sure how to pass values from ajax back to php after success or failed (i assume via a different function since returning values from ajax is not possible).    But you have this plugin so after the update if you would like to take a look you can, your call :) 


Now as to the longer message thats just something i always wanted to add since a few of my message have some text to them. 


The reason i was talking about innerHTML is because i use it just twice in my progress bar to check a value, i have been told that its better to use appendChild with createTextNode instead.    So since i am just checking a value and not adding a value to the document using innerHTML i think its fine as is,   but i might play with replacing it at some point. 

The Forum post is edited by dave Feb 3 '20