liquid_feedback_frontend

view app/main/vote/_action/update.lua @ 243:ec86db506312

Removed autoreject support (which was removed from core-2)
author bsw
date Fri Dec 30 03:04:17 2011 +0100 (2011-12-30)
parents 3036f2732b83
children b77e6a17ca77
line source
1 local issue = Issue:new_selector():add_where{ "id = ?", param.get("issue_id", atom.integer) }:for_share():single_object_mode():exec()
3 if issue.closed then
4 slot.put_into("error", _"This issue is already closed.")
5 return false
6 end
8 if issue.state ~= "voting" then
9 slot.put_into("error", _"Voting has not started yet.")
10 return false
11 end
15 local move_up = param.get("move_up", atom.integer)
16 local move_down = param.get("move_down", atom.integer)
18 if not move_down and not move_up then
19 local direct_voter = DirectVoter:by_pk(issue.id, app.session.member_id)
21 if param.get("discard", atom.boolean) then
22 if direct_voter then
23 direct_voter:destroy()
24 end
25 slot.put_into("notice", _"Your vote has been discarded. Delegation rules apply if set.")
26 return
27 end
29 if not direct_voter then
30 direct_voter = DirectVoter:new()
31 direct_voter.issue_id = issue.id
32 direct_voter.member_id = app.session.member_id
33 end
35 direct_voter:save()
37 local scoring = param.get("scoring")
39 for initiative_id, grade in scoring:gmatch("([^:;]+):([^:;]+)") do
40 local initiative_id = tonumber(initiative_id)
41 local grade = tonumber(grade)
42 local initiative = Initiative:by_id(initiative_id)
43 if initiative.issue.id ~= issue.id then
44 error("initiative from wrong issue")
45 end
46 local vote = Vote:by_pk(initiative_id, app.session.member.id)
47 if not vote then
48 vote = Vote:new()
49 vote.issue_id = issue.id
50 vote.initiative_id = initiative.id
51 vote.member_id = app.session.member.id
52 end
53 vote.grade = grade
54 vote:save()
55 end
57 else
59 local tempvoting_string = param.get("scoring")
61 local tempvotings = {}
62 for match in tempvoting_string:gmatch("([^;]+)") do
63 for initiative_id, grade in match:gmatch("([^:;]+):([^:;]+)") do
64 tempvotings[tonumber(initiative_id)] = tonumber(grade)
65 end
66 end
68 local current_initiative_id = move_up or move_down
70 local current_grade = tempvotings[current_initiative_id] or 0
71 local is_alone = true
72 if current_grade == 0 then
73 is_alone = false
74 else
75 for initiative_id, grade in pairs(tempvotings) do
76 if current_initiative_id ~= initiative_id and grade == current_grade then
77 is_alone = false
78 break
79 end
80 end
81 end
83 if move_up and current_grade >= 0 and is_alone then
84 for initiative_id, grade in pairs(tempvotings) do
85 if grade > current_grade then
86 tempvotings[initiative_id] = grade - 1
87 end
88 end
90 elseif move_up and current_grade >= 0 and not is_alone then
91 for initiative_id, grade in pairs(tempvotings) do
92 if grade > current_grade then
93 tempvotings[initiative_id] = grade + 1
94 end
95 end
96 tempvotings[current_initiative_id] = current_grade + 1
98 elseif move_up and current_grade < 0 and is_alone then
99 tempvotings[current_initiative_id] = current_grade + 1
100 for initiative_id, grade in pairs(tempvotings) do
101 if grade < current_grade then
102 tempvotings[initiative_id] = grade + 1
103 end
104 end
106 elseif move_up and current_grade < 0 and not is_alone then
107 for initiative_id, grade in pairs(tempvotings) do
108 if grade <= current_grade then
109 tempvotings[initiative_id] = grade - 1
110 end
111 end
112 tempvotings[current_initiative_id] = current_grade
114 elseif move_down and current_grade <= 0 and is_alone then
115 for initiative_id, grade in pairs(tempvotings) do
116 if grade < current_grade then
117 tempvotings[initiative_id] = grade + 1
118 end
119 end
121 elseif move_down and current_grade <= 0 and not is_alone then
122 for initiative_id, grade in pairs(tempvotings) do
123 if grade < current_grade then
124 tempvotings[initiative_id] = grade - 1
125 end
126 end
127 tempvotings[current_initiative_id] = current_grade - 1
129 elseif move_down and current_grade > 0 and is_alone then
130 tempvotings[current_initiative_id] = current_grade - 1
131 for initiative_id, grade in pairs(tempvotings) do
132 if grade > current_grade then
133 tempvotings[initiative_id] = grade - 1
134 end
135 end
137 elseif move_down and current_grade > 0 and not is_alone then
138 for initiative_id, grade in pairs(tempvotings) do
139 if grade >= current_grade then
140 tempvotings[initiative_id] = grade + 1
141 end
142 end
143 tempvotings[current_initiative_id] = current_grade
145 end
147 local tempvotings_list = {}
148 for key, val in pairs(tempvotings) do
149 tempvotings_list[#tempvotings_list+1] = tostring(key) .. ":" .. tostring(val)
150 end
152 tempvoting_string = table.concat(tempvotings_list, ";")
154 request.redirect{
155 module = "vote",
156 view = "list",
157 params = {
158 issue_id = issue.id,
159 scoring = tempvoting_string
160 }
161 }
163 end

Impressum / About Us