/modules/mod_admin_identity/actions/action_admin_identity_dialog_delete_username.erl

https://code.google.com/p/zotonic/ · Erlang · 57 lines · 30 code · 7 blank · 20 comment · 0 complexity · 05b0db094fd88f3ec6419e50f02b6ecd MD5 · raw file

  1. %% @author Marc Worrell <marc@worrell.nl>
  2. %% @copyright 2009 Marc Worrell
  3. %% Date: 2009-04-28
  4. %% @doc Open a dialog that asks confirmation to delete user credentials.
  5. %% Copyright 2009 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_identity_dialog_delete_username).
  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. Id = z_convert:to_integer(proplists:get_value(id, Args)),
  28. OnSuccess = proplists:get_all_values(on_success, Args),
  29. Postback = {dialog_delete_username, Id, OnSuccess},
  30. {PostbackMsgJS, _PickledPostback} = z_render:make_postback(Postback, click, TriggerId, TargetId, ?MODULE, Context),
  31. {PostbackMsgJS, Context}.
  32. %% @doc Fill the dialog with the delete confirmation template. The next step will ask to delete the username from the user id.
  33. %% @spec event(Event, Context1) -> Context2
  34. event({postback, {dialog_delete_username, Id, OnSuccess}, _TriggerId, _TargetId}, Context) ->
  35. case z_acl:is_allowed(delete, Id, Context) of
  36. true ->
  37. case m_identity:get_username(Id, Context) of
  38. undefined ->
  39. z_render:growl("There is no username coupled to this person.", Context);
  40. Username ->
  41. Vars = [
  42. {on_success, OnSuccess},
  43. {id, Id},
  44. {username, Username}
  45. ],
  46. z_render:dialog("Confirm user deletion.", "_action_dialog_delete_username.tpl", Vars, Context)
  47. end;
  48. false ->
  49. z_render:growl_error("Only an administrator can delete usernames.", Context)
  50. end.