PageRenderTime 26ms CodeModel.GetById 14ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 1ms

/modules/mod_admin_predicate/actions/action_admin_predicate_predicate_delete.erl

https://code.google.com/p/zotonic/
Erlang | 53 lines | 26 code | 7 blank | 20 comment | 0 complexity | 4c0c0264acea37dd1675acba58a99cce MD5 | raw file
 1%% @author Marc Worrell <marc@worrell.nl>
 2%% @copyright 2009 Marc Worrell
 3%% Date: 2009-04-28
 4%% @doc Delete a predicate, no confirmation.
 5
 6%% Copyright 2009 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(action_admin_predicate_predicate_delete).
21-author("Marc Worrell <marc@worrell.nl").
22
23%% interface functions
24-export([
25    render_action/4,
26    event/2
27]).
28
29-include("zotonic.hrl").
30
31render_action(TriggerId, TargetId, Args, Context) ->
32    Id = z_convert:to_integer(proplists:get_value(id, Args)),
33    OnSuccess = proplists:get_all_values(on_success, Args),
34    Postback = {predicate_delete, Id, OnSuccess},
35	{PostbackMsgJS, _PickledPostback} = z_render:make_postback(Postback, click, TriggerId, TargetId, ?MODULE, Context),
36	{PostbackMsgJS, Context}.
37
38
39%% @doc Delete a predicate.
40%% @spec event(Event, Context1) -> Context2
41event({postback, {predicate_delete, Id, OnSuccess}, _TriggerId, _TargetId}, Context) ->
42    case z_acl:is_allowed(delete, Id, Context) of
43        true ->
44            ok = m_rsc:delete(Id, Context),
45            lists:foldl(
46                fun (Act, Ctx) ->
47                    z_render:wire(Act, Ctx)
48                end,
49                Context,
50                lists:flatten(OnSuccess));
51        false ->
52            z_render:growl_error("Only administrators can delete predicates.", Context)
53    end.