/modules/mod_admin_config/actions/action_admin_config_config_toggle.erl

https://code.google.com/p/zotonic/ · Erlang · 48 lines · 21 code · 7 blank · 20 comment · 0 complexity · 1fd9966e26e8f916c5e59e811bccc320 MD5 · raw file

  1. %% @author Marc Worrell <marc@worrell.nl>
  2. %% @copyright 2010 Marc Worrell
  3. %% Date: 2010-09-07
  4. %% @doc Toggle the value of a config setting, set it to the value of the checkbox.
  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(action_admin_config_config_toggle).
  19. -author("Marc Worrell <marc@worrell.nl").
  20. %% interface functions
  21. -export([
  22. render_action/4,
  23. event/2
  24. ]).
  25. -include("zotonic.hrl").
  26. render_action(TriggerId, TargetId, Args, Context) ->
  27. Module = proplists:get_value(module, Args),
  28. Key = proplists:get_value(key, Args),
  29. Postback = {config_toggle, Module, Key},
  30. {PostbackMsgJS, _PickledPostback} = z_render:make_postback(Postback, click, TriggerId, TargetId, ?MODULE, Context),
  31. {PostbackMsgJS, Context}.
  32. %% @doc Change a config key.
  33. %% @spec event(Event, Context1) -> Context2
  34. event({postback, {config_toggle, Module, Key}, _TriggerId, _TargetId}, Context) ->
  35. case z_acl:is_allowed(use, mod_admin_config, Context) of
  36. true ->
  37. m_config:set_value(Module, Key, z_context:get_q("triggervalue", Context), Context),
  38. z_render:growl("Changed config setting.", Context);
  39. false ->
  40. z_render:growl_error("Only administrators can change configurations.", Context)
  41. end.