Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Popups

edited March 2012 in Vanilla 2.0 - 2.8

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

  • Options

    chirp.. chirp.. ??

  • Options

    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 the GetPreference 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 call InformMessage 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 function PluginController_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?

  • Options
    mcu_hqmcu_hq yippie ki-yay ✭✭✭

    fortean said:
    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 the GetPreference method.

    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.

  • Options

    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?

  • Options
    mcu_hqmcu_hq yippie ki-yay ✭✭✭

    just add the class, "Popup" to any link and it should display a popup

  • Options

    Can you give me an example?

  • Options
    UnderDogUnderDog MVP
    edited March 2012

    fortean said:
    Can you give me an example?

    O come on!

    ok.... copy... paste... :

    < a href="http://vanillaforums.org/discussion/19455/popups" class="Popup" >Link< /a >

    Remove the spaces between the < and > and the actual text.

    There was an error rendering this rich post.

  • Options
    edited March 2012

    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 aforementioned InformMessage popup. The only thing I still haven't figured out is how to achieve what Is described above.

  • Options

    bump..

  • Options
    mcu_hqmcu_hq yippie ki-yay ✭✭✭
    edited March 2012

    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.

    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.

  • Options
    422422 Developer MVP

    If condition true , popup display , else display none.

    There was an error rendering this rich post.

Sign In or Register to comment.