PageRenderTime 23ms CodeModel.GetById 15ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 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
19-module(resource_admin_mailinglist_recipients).
20-author("Marc Worrell <marc@worrell.nl>").
21
22-export([
23    is_authorized/2,
24	event/2
25]).
26
27-include_lib("resource_html.hrl").
28
29is_authorized(ReqData, Context) ->
30	z_acl:wm_is_authorized(use, mod_mailinglist, ReqData, Context).
31
32html(Context) ->
33    Vars = [
34        {page_admin_mailinglist, true},
35		{id, z_convert:to_integer(z_context:get_q("id", Context))}
36    ],
37	Html = z_template:render("admin_mailinglist_recipients.tpl", Vars, Context),
38	z_context:output(Html, Context).
39
40event(#postback{message={dialog_recipient_add, [{id,Id}]}}, Context) ->
41	Vars = [
42		{id, Id}
43	],
44	z_render:dialog("Add recipient.", "_dialog_mailinglist_recipient.tpl", Vars, Context);
45
46event(#postback{message={dialog_recipient_edit, [{id,Id}, {recipient_id, RcptId}]}}, Context) ->
47	Vars = [
48            {id, Id},
49            {recipient_id, RcptId}
50	],
51	z_render:dialog("Edit recipient.", "_dialog_mailinglist_recipient.tpl", Vars, Context);
52
53event(#postback{message={recipient_is_enabled_toggle, [{recipient_id, RcptId}]}, target=TargetId}, Context) ->
54	m_mailinglist:recipient_is_enabled_toggle(RcptId, Context),
55	z_script:add_script(
56		["$(\"#", TargetId, "\").parents(\"li:first\").toggleClass(\"unpublished\"); "], 
57		Context);
58
59event(#postback{message={recipient_change_email, [{recipient_id, RcptId}]}}, Context) ->
60    Email = z_context:get_q("triggervalue", Context),
61    m_mailinglist:update_recipient(RcptId, [{email, Email}], Context),
62    z_render:growl(?__("E-mail address updated", Context), Context);
63
64event(#postback{message={recipient_delete, [{recipient_id, RcptId}]}}, Context) ->
65	m_mailinglist:recipient_delete_quiet(RcptId, Context),
66	z_render:wire([ {growl, [{text, ?__("Recipient deleted.", Context)}]},
67					{slide_fade_out, [{target, "recipient-"++integer_to_list(RcptId)}]}
68				], Context);
69
70event(#postback{message={recipients_clear, [{id, Id}]}}, Context) ->
71	m_mailinglist:recipients_clear(Id, Context),
72	z_render:wire([{reload, []}], Context);
73
74event(#postback{message={dialog_recipient_upload, [{id,_Id}]}}, Context) ->
75	Context.