liquid_feedback_frontend

view env/util/add_support.lua @ 1800:b87997219042

Updated spanish translation
author bsw
date Thu Oct 21 15:22:29 2021 +0200 (2021-10-21)
parents 87e2a58bef9e
children
line source
1 function util.add_support(initiative_id, draft_id)
3 local initiative = Initiative:new_selector():add_where{ "id = ?", initiative_id }:single_object_mode():exec()
5 -- TODO important m1 selectors returning result _SET_!
6 local issue = initiative:get_reference_selector("issue"):for_share():single_object_mode():exec()
8 local member = app.access_token and app.access_token.member or app.session and app.session.member
9 if not member then
10 slot.put_into("error", "no valid session")
11 return false
12 end
14 if not member:has_voting_right_for_unit_id(issue.area.unit_id) then
15 slot.put_into("error", _"No voting rights.")
16 return false
17 end
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 elseif
26 (issue.half_frozen and issue.phase_finished) or
27 (not issue.accepted and issue.phase_finished)
28 then
29 slot.put_into("error", _"Current phase is already closed.")
30 return false
31 end
33 if initiative.revoked then
34 slot.put_into("error", _"This initiative is revoked")
35 return false
36 end
38 local member = app.session.member
40 local supporter = Supporter:by_pk(initiative.id, member.id)
42 local last_draft = Draft:new_selector()
43 :add_where{ "initiative_id = ?", initiative.id }
44 :add_order_by("id DESC")
45 :limit(1)
46 :single_object_mode()
47 :exec()
49 if draft_id and draft_id ~= last_draft.id then
50 slot.select("error", function()
51 ui.tag{ content = _"The initiative draft has been updated again in the meanwhile, support not updated!" }
52 end)
53 return false
54 end
56 if not supporter then
57 supporter = Supporter:new()
58 supporter.member_id = member.id
59 supporter.initiative_id = initiative.id
60 supporter.draft_id = last_draft.id
61 supporter:save()
62 elseif supporter.draft_id ~= last_draft.id then
63 supporter.draft_id = last_draft.id
64 supporter:save()
65 slot.put_into("notice", _"Your support has been updated to the latest draft")
66 else
67 slot.put_into("notice", _"You are already supporting the latest draft")
68 end
70 return true
72 end

Impressum / About Us