liquid_feedback_frontend

view app/main/initiative/_action/create.lua @ 898:ae9ab3edff89

Added polling support
author bsw
date Mon Aug 20 03:54:20 2012 +0200 (2012-08-20)
parents 75ce92899049
children f3d6d08b0125
line source
1 local tmp = db:query({ "SELECT text_entries_left, initiatives_left FROM member_contingent_left WHERE member_id = ?", app.session.member.id }, "opt_object")
2 if tmp then
3 if tmp.initiatives_left and tmp.initiatives_left < 1 then
4 slot.put_into("error", _"Sorry, your contingent for creating initiatives has been used up. Please try again later.")
5 return false
6 end
7 if tmp.text_entries_left and tmp.text_entries_left < 1 then
8 slot.put_into("error", _"Sorry, you have reached your personal flood limit. Please be slower...")
9 return false
10 end
11 end
13 local issue
14 local area
16 local issue_id = param.get("issue_id", atom.integer)
17 if issue_id then
18 issue = Issue:new_selector():add_where{"id=?",issue_id}:single_object_mode():exec()
19 if issue.closed then
20 slot.put_into("error", _"This issue is already closed.")
21 return false
22 elseif issue.fully_frozen then
23 slot.put_into("error", _"Voting for this issue has already begun.")
24 return false
25 end
26 area = issue.area
27 else
28 local area_id = param.get("area_id", atom.integer)
29 area = Area:new_selector():add_where{"id=?",area_id}:single_object_mode():exec()
30 if not area.active then
31 slot.put_into("error", "Invalid area.")
32 return false
33 end
34 end
36 if not app.session.member:has_voting_right_for_unit_id(area.unit_id) then
37 error("access denied")
38 end
40 local name = param.get("name")
42 local name = util.trim(name)
44 if #name < 3 then
45 slot.put_into("error", _"This name is really too short!")
46 return false
47 end
49 local formatting_engine = param.get("formatting_engine")
51 local formatting_engine_valid = false
52 for fe, dummy in pairs(config.formatting_engine_executeables) do
53 if formatting_engine == fe then
54 formatting_engine_valid = true
55 end
56 end
57 if not formatting_engine_valid then
58 error("invalid formatting engine!")
59 end
61 if param.get("preview") then
62 return
63 end
66 local initiative = Initiative:new()
68 if not issue then
69 local policy_id = param.get("policy_id", atom.integer)
70 if policy_id == -1 then
71 slot.put_into("error", _"Please choose a policy")
72 return false
73 end
74 local policy = Policy:by_id(policy_id)
75 if not policy.active then
76 slot.put_into("error", "Invalid policy.")
77 return false
78 end
79 if policy.polling and not app.session.member:has_polling_right_for_unit_id(area.unit_id) then
80 error("no polling right for this unit")
81 end
83 if not area:get_reference_selector("allowed_policies")
84 :add_where{ "policy.id = ?", policy_id }
85 :optional_object_mode()
86 :exec()
87 then
88 error("policy not allowed")
89 end
90 issue = Issue:new()
91 issue.area_id = area.id
92 issue.policy_id = policy_id
94 if policy.polling then
95 issue.accepted = 'now'
96 issue.state = 'discussion'
97 initiative.polling = true
98 end
100 issue:save()
102 if config.etherpad then
103 local result = net.curl(
104 config.etherpad.api_base
105 .. "api/1/createGroupPad?apikey=" .. config.etherpad.api_key
106 .. "&groupID=" .. config.etherpad.group_id
107 .. "&padName=Issue" .. tostring(issue.id)
108 .. "&text=" .. request.get_absolute_baseurl() .. "issue/show/" .. tostring(issue.id) .. ".html"
109 )
110 end
111 end
113 if param.get("polling", atom.boolean) and app.session.member:has_polling_right_for_unit_id(area.unit_id) then
114 initiative.polling = true
115 end
116 initiative.issue_id = issue.id
117 initiative.name = name
118 param.update(initiative, "discussion_url")
119 initiative:save()
121 local draft = Draft:new()
122 draft.initiative_id = initiative.id
123 draft.formatting_engine = formatting_engine
124 draft.content = param.get("draft")
125 draft.author_id = app.session.member.id
126 draft:save()
128 local initiator = Initiator:new()
129 initiator.initiative_id = initiative.id
130 initiator.member_id = app.session.member.id
131 initiator.accepted = true
132 initiator:save()
134 local supporter = Supporter:new()
135 supporter.initiative_id = initiative.id
136 supporter.member_id = app.session.member.id
137 supporter.draft_id = draft.id
138 supporter:save()
140 slot.put_into("notice", _"Initiative successfully created")
142 request.redirect{
143 module = "initiative",
144 view = "show",
145 id = initiative.id
146 }

Impressum / About Us