liquid_feedback_frontend
view app/main/initiative/_action/add_support.lua @ 1045:701a5cf6b067
Imported LiquidFeedback Frontend 3.0 branch
author | bsw |
---|---|
date | Thu Jul 10 01:19:48 2014 +0200 (2014-07-10) |
parents | 1997cf1da04b |
children | 32cc544d5a5b |
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 local draft_id = param.get("draft_id", atom.integer)
6 -- TODO important m1 selectors returning result _SET_!
7 local issue = initiative:get_reference_selector("issue"):for_share():single_object_mode():exec()
9 if not app.session.member:has_voting_right_for_unit_id(issue.area.unit_id) then
10 error("access denied")
11 end
13 if issue.closed then
14 slot.put_into("error", _"This issue is already closed.")
15 return false
16 elseif issue.fully_frozen then
17 slot.put_into("error", _"Voting for this issue has already begun.")
18 return false
19 elseif
20 (issue.half_frozen and issue.phase_finished) or
21 (not issue.accepted and issue.phase_finished)
22 then
23 slot.put_into("error", _"Current phase is already closed.")
24 return false
25 end
27 if initiative.revoked then
28 slot.put_into("error", _"This initiative is revoked")
29 return false
30 end
32 local member = app.session.member
34 local supporter = Supporter:by_pk(initiative.id, member.id)
36 local last_draft = Draft:new_selector()
37 :add_where{ "initiative_id = ?", initiative.id }
38 :add_order_by("id DESC")
39 :limit(1)
40 :single_object_mode()
41 :exec()
43 if draft_id and draft_id ~= last_draft.id then
44 slot.select("error", function()
45 ui.tag{ content = _"The initiative draft has been updated again in the meanwhile, support not updated!" }
46 end)
47 return false
48 end
50 if not supporter then
51 supporter = Supporter:new()
52 supporter.member_id = member.id
53 supporter.initiative_id = initiative.id
54 supporter.draft_id = last_draft.id
55 if config.auto_support and auto_support ~= nil then
56 supporter.auto_support = auto_support
57 end
58 supporter:save()
59 elseif supporter.draft_id ~= last_draft.id then
60 supporter.draft_id = last_draft.id
61 supporter:save()
62 slot.put_into("notice", _"Your support has been updated to the latest draft")
63 else
64 slot.put_into("notice", _"You are already supporting the latest draft")
65 end