Skip to content

Commit

Permalink
Merged
Browse files Browse the repository at this point in the history
  • Loading branch information
Arjan Scherpenisse committed Dec 11, 2009
2 parents d5d6461 + 46401dd commit a4d42bd
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
2 changes: 1 addition & 1 deletion include/zotonic.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
-record(email, {to=[], from=[], subject, text, html, text_tpl, html_tpl, vars=[], queue=false}).

%% @doc Broadcast notification.
-record(broadcast, {title=[], message=[], is_html=false}).
-record(broadcast, {title=[], message=[], is_html=false, stay=true, type="error"}).

%% @doc Check if an assumption is true
-define(ASSERT(A,E), z_utils:assert(A,E)).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ event({submit, broadcast, _TriggerId, _TargetId}, Context) ->
true ->
Title = z_context:get_q_validated("title", Context),
Message = z_context:get_q_validated("message", Context),
z_notifier:notify1(#broadcast{title=Title, message=Message}, Context),
Type = z_context:get_q_validated("type", Context),
Stay = case Type of
"notice" -> false;
_ -> true
end,
z_notifier:notify1(#broadcast{title=Title, message=Message, type=Type, stay=Stay}, Context),
z_render:dialog_close(Context);
false ->
z_render:growl_error("Only admins can broadcast messages.", Context)
Expand Down
12 changes: 4 additions & 8 deletions modules/mod_broadcast/mod_broadcast.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,10 @@


%% @doc Notification handler for sending broadcasts.
broadcast(#broadcast{title=Title, message=Message, is_html=IsHtml}, Context) ->
Message1 = case IsHtml of
true -> [ <<"<strong>">>, Title, <<"</strong> ">>, Message ];
false -> [ <<"<strong>">>, z_html:escape(Title), <<"</strong> ">>, z_html:escape(Message) ]
end,
Context1 = z_context:prune_for_scomp(?ACL_VIS_PUBLIC, Context),
z_session_manager:add_script(z_render:growl(Message1, "error", true, Context1)),
ok.
broadcast(B=#broadcast{}, Context) ->
z_session_manager:broadcast(B, Context),
ok.


%%====================================================================
%% API
Expand Down
11 changes: 10 additions & 1 deletion modules/mod_broadcast/templates/_action_dialog_broadcast.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,18 @@
{% validate id=#title name="title" type={presence} %}
</div>

<div class="form-item clearfix">
<label for="{{ #type }}">Type</label>
<select id="{{ #type }}" name="type">
<option value="notice" selected="selected">Notice</option>
<option value="error">Error / warning</option>
</select>
{% validate id=#type name="type" type={presence} %}
</div>

<div class="form-item clearfix">
<label for="{{ #message }}">Message</label>
<input type="text" id="{{ #message }}" name="message" value="" />
<textarea id="{{ #message }}" name="message"></textarea>
{% validate id=#message name="message" type={presence} %}
</div>

Expand Down
14 changes: 13 additions & 1 deletion src/support/z_session_manager.erl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
add_script/2,
count/1,
dump/1,
tick/1
tick/1,
broadcast/2
]).

-include_lib("zotonic.hrl").
Expand Down Expand Up @@ -100,6 +101,17 @@ dump(#context{session_manager=SessionManager}) ->
tick(Pid) when is_pid(Pid) ->
gen_server:cast(Pid, tick).

%% @spec broadcast(#broadcast, Context) -> ok
%% @doc Broadcast a notification message to all open sessions.
broadcast(#broadcast{title=Title, message=Message, is_html=IsHtml, type=Type, stay=Stay}, Context) ->
Message1 = case IsHtml of
true -> [ <<"<strong>">>, Title, <<"</strong> ">>, Message ];
false -> [ <<"<strong>">>, z_html:escape(Title), <<"</strong> ">>, z_html:escape(Message) ]
end,
Context1 = z_context:prune_for_scomp(?ACL_VIS_PUBLIC, Context),
add_script(z_render:growl(Message1, Type, Stay, Context1)),
ok.


%% gen_server callbacks

Expand Down

0 comments on commit a4d42bd

Please sign in to comment.