/modules/mod_comment/resources/resource_admin_comments.erl

https://code.google.com/p/zotonic/ · Erlang · 72 lines · 42 code · 11 blank · 19 comment · 0 complexity · 8d549e58cd5428346740643db4255a10 MD5 · raw file

  1. %% @author Marc Worrell <marc@worrell.nl>
  2. %% @copyright 2010 Marc Worrell
  3. %% Date: 2010-01-19
  4. %% @doc Creates an editable overview of all categories.
  5. %% Copyright 2010 Marc Worrell
  6. %%
  7. %% Licensed under the Apache License, Version 2.0 (the "License");
  8. %% you may not use this file except in compliance with the License.
  9. %% You may obtain a copy of the License at
  10. %%
  11. %% http://www.apache.org/licenses/LICENSE-2.0
  12. %%
  13. %% Unless required by applicable law or agreed to in writing, software
  14. %% distributed under the License is distributed on an "AS IS" BASIS,
  15. %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. %% See the License for the specific language governing permissions and
  17. %% limitations under the License.
  18. -module(resource_admin_comments).
  19. -author("Marc Worrell <marc@worrell.nl>").
  20. -export([
  21. is_authorized/2,
  22. event/2
  23. ]).
  24. -include_lib("resource_html.hrl").
  25. is_authorized(ReqData, Context) ->
  26. z_acl:wm_is_authorized(use, mod_comment, ReqData, Context).
  27. html(Context) ->
  28. Html = z_template:render("admin_comments.tpl", [{page_admin_comments, true}], Context),
  29. z_context:output(Html, Context).
  30. event({postback, {comment_delete, Args}, _TriggerId, _TargetId}, Context) ->
  31. CommentId = proplists:get_value(id, Args),
  32. case m_comment:delete(CommentId, Context) of
  33. ok ->
  34. OnSuccess = proplists:get_all_values(on_success, Args),
  35. Context1 = z_render:wire(OnSuccess, Context),
  36. z_render:growl(?__("The comment has been deleted.", Context1), Context1);
  37. {error, _Reason} ->
  38. %% Assume permission problem.
  39. z_render:growl_error(?__("You are not allowed to delete the comment.", Context), Context)
  40. end;
  41. event({postback, {comment_toggle, Args}, _TriggerId, _TargetId}, Context) ->
  42. CommentId = proplists:get_value(id, Args),
  43. case m_comment:toggle(CommentId, Context) of
  44. {ok, IsVisible} ->
  45. OnSuccess = proplists:get_all_values(on_success, Args),
  46. Context1 = z_render:wire(OnSuccess, Context),
  47. case proplists:get_value(element, Args) of
  48. undefined ->
  49. Context1;
  50. ElementId ->
  51. case IsVisible of
  52. true ->
  53. z_render:wire({remove_class, [{target, ElementId},{class,"unpublished"}]}, Context1);
  54. false ->
  55. z_render:wire({add_class, [{target, ElementId},{class,"unpublished"}]}, Context1)
  56. end
  57. end;
  58. {error, _Reason} ->
  59. %% Assume permission problem.
  60. z_render:growl_error(?__("You are not allowed to toggle the comment.", Context), Context)
  61. end.