-module (demos_notices).
-include_lib ("nitrogen_core/include/wf.hrl").

main() -> #template { file="./templates/demos46.html" }.

title() -> "User Notices".

headline() -> "User Notices". 

left() -> 
        Nitrogen provides you with a variety of ways to notify a user
        of information.

        <h2>Flash Message</h2>

        A flash message is an HTML box that slides into the page at a
        point specified by the <code>#flash{}</code> element. The flash
        message can be a simple text-message, or can contain other controls. 
        To display a flash message, call <code>wf:flash(TextOrElements)</code>.
        Flash messages are stored in session until they are displayed. This
        allows your application to set a flash message on one page in response 
        to user action and then redirect the user to another page, at which 
        the message is displayed.

        <h2>Alert Box</h2>
        The <code>#alert {}</code> action displays a simple
        Javascript alert to the user.

        <h2>Confirm Box</h2>

        The <code>#confirm {}</code> action displays a Javascript
        confirm box to the user, and posts back if the 'OK' button is

right() -> 

  #button { text="Show Flash Message", postback=show_flash },

  #button { text="Show Advanced Flash Message", postback=show_advanced_flash },

  #button { text="Show Javascript Alert", postback=show_alert },

  #button { text="Show Javascript Confirm", postback=show_confirm }  

event(show_flash) ->
    wf:flash("This is a flash message.");

event(show_advanced_flash) ->
    FlashID = wf:temp_id(),
    wf:flash(FlashID, [
        #span { text="Flash messages can contain nested controls." },
        #button { text="Click Me", postback={advanced_flash_click, FlashID} }

event({advanced_flash_click, FlashID}) ->
    wf:flash("You clicked the button."),
    wf:wire(FlashID, #hide { effect=blind, speed=100 });

event(show_alert) ->
    wf:wire(#alert { text="This is a Javascript Alert" });

event(show_confirm) ->
    wf:wire(#confirm { text="This is a Javascript Confirm", postback=confirm_ok });

event(confirm_ok) ->
    wf:wire(#alert { text="You pressed the OK button." });

event(_) -> ok.