/modules/mod_mailinglist/actions/action_mailinglist_mailing_page_test.erl

http://github.com/zotonic/zotonic · Erlang · 54 lines · 28 code · 6 blank · 20 comment · 0 complexity · 607e5df8dae15d441e9ff4a26ee514d4 MD5 · raw file

  1. %% @author Marc Worrell <marc@worrell.nl>
  2. %% @copyright 2009 Marc Worrell
  3. %% Date: 2009-11-29
  4. %% @doc Post a message to the test mailing list.
  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_mailinglist_mailing_page_test).
  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 = {mailing_page_test, Id, OnSuccess},
  30. {PostbackMsgJS, _PickledPostback} = z_render:make_postback(Postback, click, TriggerId, TargetId, ?MODULE, Context),
  31. {PostbackMsgJS, Context}.
  32. event(#postback{message={mailing_page_test, PageId, OnSuccess}}, Context) ->
  33. case m_rsc:name_to_id(mailinglist_test, Context) of
  34. {ok, ListId} ->
  35. case z_acl:rsc_visible(ListId, Context) of
  36. true ->
  37. %% Reset the recepient stats for the test list
  38. m_mailinglist:reset_log_email(ListId, PageId, Context),
  39. %% And send.
  40. z_notifier:notify(#mailinglist_mailing{list_id=ListId, page_id=PageId}, Context),
  41. Context1 = z_render:growl(?__("Sending the page to the test mailing list...", Context), Context),
  42. z_render:wire(OnSuccess, Context1);
  43. false ->
  44. z_render:growl_error(?__("You are not allowed to send mail to the test mailing list.", Context), Context)
  45. end;
  46. {error, _} ->
  47. z_render:growl_error(?__("There is no mailing list with the name ‘mailinglist_test’.", Context), Context)
  48. end.