liquid_feedback_frontend

annotate 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
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@1045 4 local draft_id = param.get("draft_id", atom.integer)
bsw@1045 5
bsw/jbe@5 6 -- TODO important m1 selectors returning result _SET_!
bsw/jbe@5 7 local issue = initiative:get_reference_selector("issue"):for_share():single_object_mode():exec()
bsw/jbe@5 8
bsw@281 9 if not app.session.member:has_voting_right_for_unit_id(issue.area.unit_id) then
bsw@281 10 error("access denied")
bsw@281 11 end
bsw@281 12
bsw/jbe@5 13 if issue.closed then
bsw/jbe@5 14 slot.put_into("error", _"This issue is already closed.")
bsw/jbe@5 15 return false
bsw@964 16 elseif issue.fully_frozen then
bsw/jbe@5 17 slot.put_into("error", _"Voting for this issue has already begun.")
bsw/jbe@5 18 return false
bsw@964 19 elseif
bsw@964 20 (issue.half_frozen and issue.phase_finished) or
bsw@964 21 (not issue.accepted and issue.phase_finished)
bsw@964 22 then
bsw@964 23 slot.put_into("error", _"Current phase is already closed.")
bsw@964 24 return false
bsw/jbe@5 25 end
bsw/jbe@5 26
bsw@10 27 if initiative.revoked then
bsw@10 28 slot.put_into("error", _"This initiative is revoked")
bsw@10 29 return false
bsw@10 30 end
bsw@10 31
bsw/jbe@0 32 local member = app.session.member
bsw/jbe@0 33
bsw/jbe@0 34 local supporter = Supporter:by_pk(initiative.id, member.id)
bsw/jbe@0 35
bsw/jbe@0 36 local last_draft = Draft:new_selector()
bsw/jbe@0 37 :add_where{ "initiative_id = ?", initiative.id }
bsw/jbe@0 38 :add_order_by("id DESC")
bsw/jbe@0 39 :limit(1)
bsw/jbe@0 40 :single_object_mode()
bsw/jbe@0 41 :exec()
bsw@1045 42
bsw@1045 43 if draft_id and draft_id ~= last_draft.id then
bsw@1045 44 slot.select("error", function()
bsw@1045 45 ui.tag{ content = _"The initiative draft has been updated again in the meanwhile, support not updated!" }
bsw@1045 46 end)
bsw@1045 47 return false
bsw@1045 48 end
bsw/jbe@0 49
bsw/jbe@0 50 if not supporter then
bsw/jbe@0 51 supporter = Supporter:new()
bsw/jbe@0 52 supporter.member_id = member.id
bsw/jbe@0 53 supporter.initiative_id = initiative.id
bsw/jbe@0 54 supporter.draft_id = last_draft.id
poelzi@165 55 if config.auto_support and auto_support ~= nil then
poelzi@165 56 supporter.auto_support = auto_support
poelzi@165 57 end
bsw/jbe@0 58 supporter:save()
bsw/jbe@0 59 elseif supporter.draft_id ~= last_draft.id then
bsw/jbe@0 60 supporter.draft_id = last_draft.id
bsw/jbe@0 61 supporter:save()
bsw@1045 62 slot.put_into("notice", _"Your support has been updated to the latest draft")
bsw/jbe@0 63 else
bsw@1045 64 slot.put_into("notice", _"You are already supporting the latest draft")
poelzi@148 65 end
poelzi@148 66

Impressum / About Us