/modules/mod_mailinglist/resources/resource_admin_mailinglist_recipients.erl

http://github.com/zotonic/zotonic · Erlang · 75 lines · 46 code · 13 blank · 16 comment · 0 complexity · 26b6accc8959b435ae717d820bcce133 MD5 · raw file

  1. %% @author Marc Worrell <marc@worrell.nl>
  2. %% @copyright 2009 Marc Worrell
  3. %% @doc List all mailing lists, enable adding and deleting mailing lists.
  4. %% Copyright 2009 Marc Worrell
  5. %%
  6. %% Licensed under the Apache License, Version 2.0 (the "License");
  7. %% you may not use this file except in compliance with the License.
  8. %% You may obtain a copy of the License at
  9. %%
  10. %% http://www.apache.org/licenses/LICENSE-2.0
  11. %%
  12. %% Unless required by applicable law or agreed to in writing, software
  13. %% distributed under the License is distributed on an "AS IS" BASIS,
  14. %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. %% See the License for the specific language governing permissions and
  16. %% limitations under the License.
  17. -module(resource_admin_mailinglist_recipients).
  18. -author("Marc Worrell <marc@worrell.nl>").
  19. -export([
  20. is_authorized/2,
  21. event/2
  22. ]).
  23. -include_lib("resource_html.hrl").
  24. is_authorized(ReqData, Context) ->
  25. z_acl:wm_is_authorized(use, mod_mailinglist, ReqData, Context).
  26. html(Context) ->
  27. Vars = [
  28. {page_admin_mailinglist, true},
  29. {id, z_convert:to_integer(z_context:get_q("id", Context))}
  30. ],
  31. Html = z_template:render("admin_mailinglist_recipients.tpl", Vars, Context),
  32. z_context:output(Html, Context).
  33. event(#postback{message={dialog_recipient_add, [{id,Id}]}}, Context) ->
  34. Vars = [
  35. {id, Id}
  36. ],
  37. z_render:dialog("Add recipient.", "_dialog_mailinglist_recipient.tpl", Vars, Context);
  38. event(#postback{message={dialog_recipient_edit, [{id,Id}, {recipient_id, RcptId}]}}, Context) ->
  39. Vars = [
  40. {id, Id},
  41. {recipient_id, RcptId}
  42. ],
  43. z_render:dialog("Edit recipient.", "_dialog_mailinglist_recipient.tpl", Vars, Context);
  44. event(#postback{message={recipient_is_enabled_toggle, [{recipient_id, RcptId}]}, target=TargetId}, Context) ->
  45. m_mailinglist:recipient_is_enabled_toggle(RcptId, Context),
  46. z_script:add_script(
  47. ["$(\"#", TargetId, "\").parents(\"li:first\").toggleClass(\"unpublished\"); "],
  48. Context);
  49. event(#postback{message={recipient_change_email, [{recipient_id, RcptId}]}}, Context) ->
  50. Email = z_context:get_q("triggervalue", Context),
  51. m_mailinglist:update_recipient(RcptId, [{email, Email}], Context),
  52. z_render:growl(?__("E-mail address updated", Context), Context);
  53. event(#postback{message={recipient_delete, [{recipient_id, RcptId}]}}, Context) ->
  54. m_mailinglist:recipient_delete_quiet(RcptId, Context),
  55. z_render:wire([ {growl, [{text, ?__("Recipient deleted.", Context)}]},
  56. {slide_fade_out, [{target, "recipient-"++integer_to_list(RcptId)}]}
  57. ], Context);
  58. event(#postback{message={recipients_clear, [{id, Id}]}}, Context) ->
  59. m_mailinglist:recipients_clear(Id, Context),
  60. z_render:wire([{reload, []}], Context);
  61. event(#postback{message={dialog_recipient_upload, [{id,_Id}]}}, Context) ->
  62. Context.