liquid_feedback_frontend

annotate app/main/initiative/_action/add_support.lua @ 1112:8fb4eab439c1

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

Impressum / About Us