Skip to content

Commit

Permalink
Update wf:flash/N so that you can add an optional FlashID that can be…
Browse files Browse the repository at this point in the history
… used to later manipulate or hide the flash panel.
  • Loading branch information
rustyio committed Dec 16, 2010
1 parent 8b32b39 commit 9471bb8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
10 changes: 6 additions & 4 deletions Quickstart/src/demos/demos_notices.erl
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,16 @@ event(show_flash) ->
wf:flash("This is a flash message.");

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

event(advanced_flash_click) ->
wf:flash("You clicked the button.");
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" });
Expand Down
11 changes: 7 additions & 4 deletions apps/nitrogen/src/elements/other/element_flash.erl
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,22 @@ update() ->
end.

add_flash(Term) ->
FlashID = wf:temp_id(),
add_flash(FlashID, Term).

add_flash(FlashID, Elements) ->
Flashes = case wf:session(flashes) of
undefined -> [];
X -> X
end,
wf:session(flashes, [Term|Flashes]).
wf:session(flashes, [{FlashID, Elements}|Flashes]).

get_flashes() ->
% Create terms for an individual flash...
F = fun(X) ->
FlashID = wf:temp_id(),
F = fun({FlashID, Elements}) ->
InnerPanel = #panel { class=flash, actions=#show { target=FlashID, effect=blind, speed=400 }, body=[
#link { class=flash_close_button, text="Close", actions=#event { type=click, target=FlashID, actions=#hide { effect=blind, speed=400 } } },
#panel { class=flash_content, body=X }
#panel { class=flash_content, body=Elements }
]},
#panel { id=FlashID, style="display: none;", body=InnerPanel}
end,
Expand Down
3 changes: 3 additions & 0 deletions apps/nitrogen/src/wf.erl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ remove(Target) ->
flash(Elements) ->
element_flash:add_flash(Elements).

flash(FlashID, Elements) ->
element_flash:add_flash(FlashID, Elements).

%%% EXPOSE WF_UTILS %%%

f(S) ->
Expand Down

0 comments on commit 9471bb8

Please sign in to comment.