liquid_feedback_frontend
diff app/main/vote/_action/update.lua @ 879:ea3d3757ddc3
Added support for voting comments
| author | bsw |
|---|---|
| date | Mon Aug 20 01:00:09 2012 +0200 (2012-08-20) |
| parents | 75a95999a410 |
| children | fe39c1fb541b |
line diff
1.1 --- a/app/main/vote/_action/update.lua Sat Aug 18 23:22:20 2012 +0200 1.2 +++ b/app/main/vote/_action/update.lua Mon Aug 20 01:00:09 2012 +0200 1.3 @@ -1,15 +1,22 @@ 1.4 +local cancel = param.get("cancel") and true or false 1.5 +if cancel then return end 1.6 + 1.7 local issue = Issue:new_selector():add_where{ "id = ?", param.get("issue_id", atom.integer) }:for_share():single_object_mode():exec() 1.8 1.9 +local preview = param.get("preview") or param.get("preview2") == "1" and true or false 1.10 + 1.11 if not app.session.member:has_voting_right_for_unit_id(issue.area.unit_id) then 1.12 error("access denied") 1.13 end 1.14 1.15 -if issue.closed then 1.16 +local update_comment = param.get("update_comment") == "1" and true or false 1.17 + 1.18 +if issue.closed and not update_comment then 1.19 slot.put_into("error", _"This issue is already closed.") 1.20 return false 1.21 end 1.22 1.23 -if issue.state ~= "voting" then 1.24 +if issue.state ~= "voting" and not issue.closed then 1.25 slot.put_into("error", _"Voting has not started yet.") 1.26 return false 1.27 end 1.28 @@ -30,44 +37,84 @@ 1.29 local tempvoting_string = param.get("scoring") 1.30 1.31 local tempvotings = {} 1.32 -for match in tempvoting_string:gmatch("([^;]+)") do 1.33 - for initiative_id, grade in match:gmatch("([^:;]+):([^:;]+)") do 1.34 - tempvotings[tonumber(initiative_id)] = tonumber(grade) 1.35 - if param.get("move_up_" .. initiative_id .. ".x", atom.integer) then 1.36 - move_up = tonumber(initiative_id) 1.37 - elseif param.get("move_down_" .. initiative_id .. ".x", atom.integer) then 1.38 - move_down = tonumber(initiative_id) 1.39 +if not update_comment then 1.40 + for match in tempvoting_string:gmatch("([^;]+)") do 1.41 + for initiative_id, grade in match:gmatch("([^:;]+):([^:;]+)") do 1.42 + tempvotings[tonumber(initiative_id)] = tonumber(grade) 1.43 + if param.get("move_up_" .. initiative_id .. ".x", atom.integer) then 1.44 + move_up = tonumber(initiative_id) 1.45 + elseif param.get("move_down_" .. initiative_id .. ".x", atom.integer) then 1.46 + move_down = tonumber(initiative_id) 1.47 + end 1.48 end 1.49 end 1.50 end 1.51 1.52 if not move_down and not move_up then 1.53 - if not direct_voter then 1.54 - direct_voter = DirectVoter:new() 1.55 - direct_voter.issue_id = issue.id 1.56 - direct_voter.member_id = app.session.member_id 1.57 + if not preview then 1.58 + if not direct_voter then 1.59 + if issue.closed then 1.60 + slot.put_into("error", _"This issue is already closed.") 1.61 + return false 1.62 + else 1.63 + direct_voter = DirectVoter:new() 1.64 + direct_voter.issue_id = issue.id 1.65 + direct_voter.member_id = app.session.member_id 1.66 + direct_voter:save() 1.67 + 1.68 + direct_voter = DirectVoter:by_pk(issue.id, app.session.member_id) 1.69 + end 1.70 + end 1.71 + 1.72 + local formatting_engine = param.get("formatting_engine") 1.73 + local comment = util.trim(param.get("comment")) 1.74 + 1.75 + if comment ~= direct_voter.comment then 1.76 + if #comment > 0 then 1.77 + direct_voter.formatting_engine = formatting_engine 1.78 + direct_voter.comment = comment 1.79 + direct_voter.comment_changed = 'now' 1.80 + direct_voter:render_content(true) 1.81 + else 1.82 + direct_voter.formatting_engine = null 1.83 + direct_voter.comment = null 1.84 + direct_voter.comment_changed = 'now' 1.85 + end 1.86 + end 1.87 + direct_voter:save() 1.88 + 1.89 end 1.90 1.91 - direct_voter:save() 1.92 - 1.93 - local scoring = param.get("scoring") 1.94 + if not update_comment then 1.95 + local scoring = param.get("scoring") 1.96 1.97 - for initiative_id, grade in scoring:gmatch("([^:;]+):([^:;]+)") do 1.98 - local initiative_id = tonumber(initiative_id) 1.99 - local grade = tonumber(grade) 1.100 - local initiative = Initiative:by_id(initiative_id) 1.101 - if initiative.issue.id ~= issue.id then 1.102 - error("initiative from wrong issue") 1.103 + for initiative_id, grade in scoring:gmatch("([^:;]+):([^:;]+)") do 1.104 + local initiative_id = tonumber(initiative_id) 1.105 + local grade = tonumber(grade) 1.106 + local initiative = Initiative:by_id(initiative_id) 1.107 + if initiative.issue.id ~= issue.id then 1.108 + error("initiative from wrong issue") 1.109 + end 1.110 + if not preview and not issue.closed then 1.111 + local vote = Vote:by_pk(initiative_id, app.session.member.id) 1.112 + if not vote then 1.113 + vote = Vote:new() 1.114 + vote.issue_id = issue.id 1.115 + vote.initiative_id = initiative.id 1.116 + vote.member_id = app.session.member.id 1.117 + end 1.118 + vote.grade = grade 1.119 + vote:save() 1.120 + end 1.121 end 1.122 - local vote = Vote:by_pk(initiative_id, app.session.member.id) 1.123 - if not vote then 1.124 - vote = Vote:new() 1.125 - vote.issue_id = issue.id 1.126 - vote.initiative_id = initiative.id 1.127 - vote.member_id = app.session.member.id 1.128 - end 1.129 - vote.grade = grade 1.130 - vote:save() 1.131 + end 1.132 + 1.133 + if not preview and not cancel then 1.134 + request.redirect{ 1.135 + module = "issue", 1.136 + view = "show", 1.137 + id = issue.id 1.138 + } 1.139 end 1.140 1.141 else