PageRenderTime 18ms CodeModel.GetById 10ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/mod_admin_config/actions/action_admin_config_dialog_config_delete.erl

https://code.google.com/p/zotonic/
Erlang | 49 lines | 22 code | 7 blank | 20 comment | 0 complexity | 6afe1e6498c69337b492cf906331edda MD5 | raw file
 1%% @author Marc Worrell <marc@worrell.nl>
 2%% @copyright 2009 Marc Worrell
 3%% Date: 2009-08-07
 4%% @doc Open a dialog that asks confirmation to delete a configuration.
 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_config_dialog_config_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    Module = proplists:get_value(module, Args),
33    Key = proplists:get_value(key, Args),
34    OnSuccess = proplists:get_all_values(on_success, Args),
35    Postback = {delete_config_dialog, Module, Key, OnSuccess},
36	{PostbackMsgJS, _PickledPostback} = z_render:make_postback(Postback, click, TriggerId, TargetId, ?MODULE, Context),
37	{PostbackMsgJS, Context}.
38
39
40%% @doc Fill the dialog with the delete confirmation template. The next step will ask to delete the config.
41%% @spec event(Event, Context1) -> Context2
42event({postback, {delete_config_dialog, Module, Key, OnSuccess}, _TriggerId, _TargetId}, Context) ->
43    case z_acl:is_allowed(use, mod_admin_config, Context) of
44        true ->
45            Vars = [ {on_success, OnSuccess}, {module, Module}, {key, Key} ],
46            z_render:dialog("Confirm delete.", "_action_dialog_config_delete.tpl", Vars, Context);
47        false ->
48            z_render:growl_error("Only administrators can delete configurations.", Context)
49    end.