/modules/mod_logging/actions/action_logging_addlog.erl

https://code.google.com/p/zotonic/ · Erlang · 41 lines · 20 code · 6 blank · 15 comment · 0 complexity · eeadb23edb5168e675d756b15a2391f1 MD5 · raw file

  1. %% @author Arjan Scherpenisse <arjan@scherpenisse.net>
  2. %% @copyright 2010 Arjan Scherpenisse <arjan@scherpenisse.net>
  3. %% Copyright 2010 Arjan Scherpenisse <arjan@scherpenisse.net>
  4. %%
  5. %% Licensed under the Apache License, Version 2.0 (the "License");
  6. %% you may not use this file except in compliance with the License.
  7. %% You may obtain a copy of the License at
  8. %%
  9. %% http://www.apache.org/licenses/LICENSE-2.0
  10. %%
  11. %% Unless required by applicable law or agreed to in writing, software
  12. %% distributed under the License is distributed on an "AS IS" BASIS,
  13. %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. %% See the License for the specific language governing permissions and
  15. %% limitations under the License.
  16. -module(action_logging_addlog).
  17. -include("zotonic.hrl").
  18. -export([
  19. render_action/4
  20. ]).
  21. render_action(_TriggerId, TargetId, Args, Context) ->
  22. SignalProps = proplists:get_value(signal_props, Args),
  23. Type = proplists:get_value(type, SignalProps),
  24. {Tpl, Context1} = z_template:render_to_iolist(proplists:get_value(template, Args, "_admin_log_row.tpl"), Args, Context),
  25. Tpl2 = lists:flatten(z_string:line(erlang:iolist_to_binary(Tpl))),
  26. {[], z_script:add_script([
  27. "$('", z_utils:js_escape(Tpl2),
  28. "').hide().insertBefore('#", TargetId, " li:first').fadeIn().css({backgroundColor:'",
  29. log_color(Type), "'}).animate({backgroundColor:'",
  30. log_color(bg), "'}, 8000, 'linear');"], Context1)}.
  31. log_color(debug) -> "#ffffff";
  32. log_color(info) -> "#ffff99";
  33. log_color(warning) -> "#ffcc99";
  34. log_color(bg) -> "#f1f1f1";
  35. log_color(_) -> "#f1f1f1".