liquid_feedback_frontend

view app/main/initiative/_action/add_support.lua @ 1499:f8a4260841df

Removed auto-support
author bsw
date Tue Mar 24 16:50:16 2020 +0100 (2020-03-24)
parents 32cc544d5a5b
children 71f54c43d7cb
line source
1 local initiative = Initiative:new_selector():add_where{ "id = ?", param.get_id()}:single_object_mode():exec()
3 local draft_id = param.get("draft_id", atom.integer)
5 -- TODO important m1 selectors returning result _SET_!
6 local issue = initiative:get_reference_selector("issue"):for_share():single_object_mode():exec()
8 if not app.session.member:has_voting_right_for_unit_id(issue.area.unit_id) then
9 return execute.view { module = "index", view = "403" }
10 end
12 if issue.closed then
13 slot.put_into("error", _"This issue is already closed.")
14 return false
15 elseif issue.fully_frozen then
16 slot.put_into("error", _"Voting for this issue has already begun.")
17 return false
18 elseif
19 (issue.half_frozen and issue.phase_finished) or
20 (not issue.accepted and issue.phase_finished)
21 then
22 slot.put_into("error", _"Current phase is already closed.")
23 return false
24 end
26 if initiative.revoked then
27 slot.put_into("error", _"This initiative is revoked")
28 return false
29 end
31 local member = app.session.member
33 local supporter = Supporter:by_pk(initiative.id, member.id)
35 local last_draft = Draft:new_selector()
36 :add_where{ "initiative_id = ?", initiative.id }
37 :add_order_by("id DESC")
38 :limit(1)
39 :single_object_mode()
40 :exec()
42 if draft_id and draft_id ~= last_draft.id then
43 slot.select("error", function()
44 ui.tag{ content = _"The initiative draft has been updated again in the meanwhile, support not updated!" }
45 end)
46 return false
47 end
49 if not supporter then
50 supporter = Supporter:new()
51 supporter.member_id = member.id
52 supporter.initiative_id = initiative.id
53 supporter.draft_id = last_draft.id
54 supporter:save()
55 elseif supporter.draft_id ~= last_draft.id then
56 supporter.draft_id = last_draft.id
57 supporter:save()
58 slot.put_into("notice", _"Your support has been updated to the latest draft")
59 else
60 slot.put_into("notice", _"You are already supporting the latest draft")
61 end

Impressum / About Us