# HG changeset patch # User bsw # Date 1345423153 -7200 # Node ID 2e9d39b53b64a3a69e3edaaca98d349d156eedfa # Parent e81f35cdc0881ee38748e9b4055417c922c52675 Added support for setting/removing of beeing a non voter diff -r e81f35cdc088 -r 2e9d39b53b64 app/main/issue/_show.lua --- a/app/main/issue/_show.lua Mon Aug 20 02:38:34 2012 +0200 +++ b/app/main/issue/_show.lua Mon Aug 20 02:39:13 2012 +0200 @@ -102,6 +102,43 @@ params = { issue_id = issue.id } } end + + if voteable and not direct_voter then + if not issue.member_info.non_voter then + links[#links+1] ={ + content = _"Do not vote directly", + module = "vote", + action = "non_voter", + params = { issue_id = issue.id }, + routing = { + default = { + mode = "redirect", + module = request.get_module(), + view = request.get_view(), + id = param.get_id_cgi(), + params = param.get_all_cgi() + } + } + } + else + links[#links+1] = { attr = { class = "action" }, content = _"Do not vote directly" } + links[#links+1] ={ + content = _"Cancel do not vote", + module = "vote", + action = "non_voter", + params = { issue_id = issue.id, delete = true }, + routing = { + default = { + mode = "redirect", + module = request.get_module(), + view = request.get_view(), + id = param.get_id_cgi(), + params = param.get_all_cgi() + } + } + } + end + end if not for_member or for_member.id == app.session.member_id then diff -r e81f35cdc088 -r 2e9d39b53b64 app/main/vote/_action/non_voter.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/main/vote/_action/non_voter.lua Mon Aug 20 02:39:13 2012 +0200 @@ -0,0 +1,21 @@ +local issue = Issue:new_selector():add_where{ "id = ?", param.get("issue_id", atom.integer) }:for_share():single_object_mode():exec() + +local direct_voter = DirectVoter:by_pk(issue.id, app.session.member_id) + +if direct_voter then + slot.select("error", function() + ui.tag{ content = _"You already voted this issue" } + end ) + return false +end + +local non_voter = NonVoter:by_pk(issue.id, app.session.member_id) + +if non_voter and param.get("delete", atom.boolean) then + non_voter:destroy() +elseif not non_voter then + non_voter = NonVoter:new() + non_voter.issue_id = issue.id + non_voter.member_id = app.session.member_id + non_voter:save() +end \ No newline at end of file diff -r e81f35cdc088 -r 2e9d39b53b64 model/issue.lua --- a/model/issue.lua Mon Aug 20 02:38:34 2012 +0200 +++ b/model/issue.lua Mon Aug 20 02:39:13 2012 +0200 @@ -153,6 +153,8 @@ selector:add_field("other_trustee.name", "other_trustee_name") selector:left_join("direct_voter", nil, { "direct_voter.issue_id = issue.id AND direct_voter.member_id = ?", options.member_id }) selector:add_field("direct_voter.member_id NOTNULL", "direct_voted") + selector:left_join("non_voter", nil, { "non_voter.issue_id = issue.id AND non_voter.member_id = ?", options.member_id }) + selector:add_field("non_voter.member_id NOTNULL", "non_voter") return selector end } diff -r e81f35cdc088 -r 2e9d39b53b64 model/non_voter.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/model/non_voter.lua Mon Aug 20 02:39:13 2012 +0200 @@ -0,0 +1,10 @@ +NonVoter = mondelefant.new_class() +NonVoter.table = 'non_voter' +NonVoter.primary_key = { "issue_id", "member_id" } + +function NonVoter:by_pk(issue_id, member_id) + return self:new_selector() + :add_where{ "issue_id = ? AND member_id = ?", issue_id, member_id } + :optional_object_mode() + :exec() +end \ No newline at end of file