Popups
Folks,
a newbie question.
I have written a simple plugin. On each page (re)load it checks for certain conditions. and if one of them applies the user should be informed about it and be logged out after clicking a button.
I have been using the $Sender->InformMessage($String, 'Dismissable')
method/function to send the user the message, and it works fine in most cases. However, I haven't found out yet how to implement the 'Logout' button in there, and / or make it so that the user is logged out automatically if he clicks away the popup.
Also, if the error conditions already apply during login, the message flashes briefly in the lower left corner but before one even could read it disappears because the HOME page is loaded next. That potentially leaves a flabbergasted user, who logges in, sees something flashing in the lower left corner and then immediately is logged out again..
So, is there a more persistent built-in 'popup' method I can use? Any other suggestions are welcomed too.
Answers
chirp.. chirp.. ??
Somehow I get the impression I'm a bit alone here.. :-P..
Anyway, I just kept trying and have solved a bit more of this puzzle: you can set preferences in a session, using the
GDN::Session()->SetPreference
method and read their value with theGetPreference
method.This is kinda like setting an uebervariable, which seems to be persistent across sessions. I haven't figured out where Vanilla stores this stuff (cookie, database) - may do that later. For now I'm satisfied it works. In as far as I can see, you can use any name you like for a preference and it's contents can be anything too, e.g. booleans, strings etc.
So, what I do is I check for the error conditions, and if one or more apply I set a custom preference to 'false'. On loading pages, the preference is checked and if found to be false, a message is shown, using the aformentioned
InformMessage()
method. Additionally, I figured out that you can callInformMessage
with a parameter 'DismissCallbackUrl
', which can be set to an URL, which will be invoked if the user dismisses the message. The URL corresponds to a method which you can add to your plugin, e.g. when you define an URL like'/plugin/something'
this corresponds to public functionPluginController_SomeThing_Create($Sender)
being called. In which you can set the preference back to 'true', which will prevent the popup to show again.So, most of what I wanted to do - has been realized. However, I still haven't found out how to automatically log out the user and THEN show him a popup with an explanation why he was logged out. I found out about
$Authenticator = Gdn::Authenticator();
et al and so can create a link or button that makes the user log out. However, I want to log him out automatically while preserving the popup until he / she clicks it away. Problem is you can't have session context / preferences outside a session, I guess..Any ideas?
Nice find...I think I am going to use this in implementing a dynamic theme switcher which will give users the ability to easily change between themes.
If you can't solve your problem within the framework, I would try doing this in jquery. Logout the user inside of Vanilla but just before this, perhaps store a cookie via jquery cookiehttps://github.com/carhartl/jquery-cookie that will save the message.
Most of what I learned can be found on the Vanilla Wiki. If you haven't visited it yet, please take a look over there, it certainly is worth your while.
I haven not yet found out how to create a proper popup within the Garden framework, any ideas, folks?
just add the class, "Popup" to any link and it should display a popup
Can you give me an example?
O come on!
ok.... copy... paste... :
Remove the spaces between the < and > and the actual text.
There was an error rendering this rich post.
Thanks, UnderDog. And sure enough I could have this code somewhere in a page and then, when a user clicks the link, the popup would show. But that's not what I need. What I need is a function or method which I can call within the
public function Base_Render_Before($Sender)
(which is part of my plugin). My code checks for various conditions and if need be should show a pop up to inform the user about any problem(s). The popup should be in focus and clicking it away (and/or clicking a 'Logout' button which I intend to put on it) should log the user out.So, for example, say it's Wednesday and the user is not allowed to work on Wednesday. Say he started his session on a Tuesday, but now it's after midnight. So, on the next page load, my plugin code is executed, the condition 'it is Wednesday' applies, a popup should appear which says "I'm sorry, but it is now Wednesday and our policy forbids you to work on Wednesdays - you will be logged out [log out]". And when the user dismisses the message and/ or clicks the button he is logged out.
I've gotten the 'show message' part to work using the
InformMessage
method. I also have been able to display the 'log off' link in the aforementionedInformMessage
popup. The only thing I still haven't figured out is how to achieve what Is described above.bump..
You can do this using jquery. When it detects that the user has clicked out of the popup div, perform a POST to a function in your plugin that logs the user out and redirects to home page.
If condition true , popup display , else display none.
There was an error rendering this rich post.