liquid_feedback_frontend
view app/main/initiative/_action/add_support.lua @ 1031:489cb972466c
Going to version 2.2.4
author | bsw |
---|---|
date | Mon Aug 12 21:39:05 2013 +0200 (2013-08-12) |
parents | 1997cf1da04b |
children | 701a5cf6b067 |
line source
1 local initiative = Initiative:new_selector():add_where{ "id = ?", param.get_id()}:single_object_mode():exec()
2 local auto_support = param.get("auto_support", atom.boolean)
4 -- TODO important m1 selectors returning result _SET_!
5 local issue = initiative:get_reference_selector("issue"):for_share():single_object_mode():exec()
7 if not app.session.member:has_voting_right_for_unit_id(issue.area.unit_id) then
8 error("access denied")
9 end
11 if issue.closed then
12 slot.put_into("error", _"This issue is already closed.")
13 return false
14 elseif issue.fully_frozen then
15 slot.put_into("error", _"Voting for this issue has already begun.")
16 return false
17 elseif
18 (issue.half_frozen and issue.phase_finished) or
19 (not issue.accepted and issue.phase_finished)
20 then
21 slot.put_into("error", _"Current phase is already closed.")
22 return false
23 end
25 if initiative.revoked then
26 slot.put_into("error", _"This initiative is revoked")
27 return false
28 end
30 local member = app.session.member
32 local supporter = Supporter:by_pk(initiative.id, member.id)
34 local last_draft = Draft:new_selector()
35 :add_where{ "initiative_id = ?", initiative.id }
36 :add_order_by("id DESC")
37 :limit(1)
38 :single_object_mode()
39 :exec()
41 if not supporter then
42 supporter = Supporter:new()
43 supporter.member_id = member.id
44 supporter.initiative_id = initiative.id
45 supporter.draft_id = last_draft.id
46 if config.auto_support and auto_support ~= nil then
47 supporter.auto_support = auto_support
48 end
49 supporter:save()
50 -- slot.put_into("notice", _"Your support has been added to this initiative")
51 elseif supporter.draft_id ~= last_draft.id then
52 supporter.draft_id = last_draft.id
53 supporter:save()
54 -- slot.put_into("notice", _"Your support has been updated to the latest draft")
55 else
56 -- slot.put_into("notice", _"You are already supporting the latest draft")
57 end