PageRenderTime 38ms CodeModel.GetById 23ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

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