liquid_feedback_frontend

annotate app/main/vote/_action/non_voter.lua @ 890:941941955c0e

Allow (un)set of non_voter only while voting is running
author bsw
date Mon Aug 20 02:59:30 2012 +0200 (2012-08-20)
parents 2e9d39b53b64
children 1997cf1da04b
rev   line source
bsw@886 1 local issue = Issue:new_selector():add_where{ "id = ?", param.get("issue_id", atom.integer) }:for_share():single_object_mode():exec()
bsw@886 2
bsw@890 3 if issue.closed then
bsw@890 4 slot.put_into("error", _"This issue is already closed.")
bsw@890 5 return false
bsw@890 6 end
bsw@890 7
bsw@890 8 if issue.state ~= "voting" then
bsw@890 9 slot.put_into("error", _"Voting has not started yet.")
bsw@890 10 return false
bsw@890 11 end
bsw@890 12
bsw@886 13 local direct_voter = DirectVoter:by_pk(issue.id, app.session.member_id)
bsw@886 14
bsw@886 15 if direct_voter then
bsw@886 16 slot.select("error", function()
bsw@886 17 ui.tag{ content = _"You already voted this issue" }
bsw@886 18 end )
bsw@886 19 return false
bsw@886 20 end
bsw@886 21
bsw@886 22 local non_voter = NonVoter:by_pk(issue.id, app.session.member_id)
bsw@886 23
bsw@886 24 if non_voter and param.get("delete", atom.boolean) then
bsw@886 25 non_voter:destroy()
bsw@886 26 elseif not non_voter then
bsw@886 27 non_voter = NonVoter:new()
bsw@886 28 non_voter.issue_id = issue.id
bsw@886 29 non_voter.member_id = app.session.member_id
bsw@886 30 non_voter:save()
bsw@886 31 end

Impressum / About Us