liquid_feedback_frontend
view app/main/vote/_action/update.lua @ 20:0a23f39b3e21
Esperanto translation strings added
author | Dinu Gherman |
---|---|
date | Sat Feb 20 22:14:38 2010 +0100 (2010-02-20) |
parents | 00d1004545f1 |
children | 3036f2732b83 |
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
13 local move_up = param.get("move_up", atom.integer)
14 local move_down = param.get("move_down", atom.integer)
16 if not move_down and not move_up then
17 local direct_voter = DirectVoter:by_pk(issue.id, app.session.member_id)
19 if not direct_voter then
20 direct_voter = DirectVoter:new()
21 direct_voter.issue_id = issue.id
22 direct_voter.member_id = app.session.member_id
23 end
25 direct_voter.autoreject = false
26 direct_voter:save()
28 local scoring = param.get("scoring")
30 for initiative_id, grade in scoring:gmatch("([^:;]+):([^:;]+)") do
31 local initiative_id = tonumber(initiative_id)
32 local grade = tonumber(grade)
33 local initiative = Initiative:by_id(initiative_id)
34 if initiative.issue.id ~= issue.id then
35 error("initiative from wrong issue")
36 end
37 local vote = Vote:by_pk(initiative_id, app.session.member.id)
38 if not vote then
39 vote = Vote:new()
40 vote.issue_id = issue.id
41 vote.initiative_id = initiative.id
42 vote.member_id = app.session.member.id
43 end
44 vote.grade = grade
45 vote:save()
46 end
48 else
50 local tempvoting_string = param.get("scoring")
52 local tempvotings = {}
53 for match in tempvoting_string:gmatch("([^;]+)") do
54 for initiative_id, grade in match:gmatch("([^:;]+):([^:;]+)") do
55 tempvotings[tonumber(initiative_id)] = tonumber(grade)
56 end
57 end
59 local current_initiative_id = move_up or move_down
61 local current_grade = tempvotings[current_initiative_id] or 0
62 local is_alone = true
63 if current_grade == 0 then
64 is_alone = false
65 else
66 for initiative_id, grade in pairs(tempvotings) do
67 if current_initiative_id ~= initiative_id and grade == current_grade then
68 is_alone = false
69 break
70 end
71 end
72 end
74 if move_up and current_grade >= 0 and is_alone then
75 for initiative_id, grade in pairs(tempvotings) do
76 if grade > current_grade then
77 tempvotings[initiative_id] = grade - 1
78 end
79 end
81 elseif move_up and current_grade >= 0 and not is_alone then
82 for initiative_id, grade in pairs(tempvotings) do
83 if grade > current_grade then
84 tempvotings[initiative_id] = grade + 1
85 end
86 end
87 tempvotings[current_initiative_id] = current_grade + 1
89 elseif move_up and current_grade < 0 and is_alone then
90 tempvotings[current_initiative_id] = current_grade + 1
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
97 elseif move_up and current_grade < 0 and not is_alone then
98 for initiative_id, grade in pairs(tempvotings) do
99 if grade <= current_grade then
100 tempvotings[initiative_id] = grade - 1
101 end
102 end
103 tempvotings[current_initiative_id] = current_grade
105 elseif move_down and current_grade <= 0 and is_alone then
106 for initiative_id, grade in pairs(tempvotings) do
107 if grade < current_grade then
108 tempvotings[initiative_id] = grade + 1
109 end
110 end
112 elseif move_down and current_grade <= 0 and not is_alone then
113 for initiative_id, grade in pairs(tempvotings) do
114 if grade < current_grade then
115 tempvotings[initiative_id] = grade - 1
116 end
117 end
118 tempvotings[current_initiative_id] = current_grade - 1
120 elseif move_down and current_grade > 0 and is_alone then
121 tempvotings[current_initiative_id] = current_grade - 1
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
128 elseif move_down and current_grade > 0 and not is_alone then
129 for initiative_id, grade in pairs(tempvotings) do
130 if grade >= current_grade then
131 tempvotings[initiative_id] = grade + 1
132 end
133 end
134 tempvotings[current_initiative_id] = current_grade
136 end
138 local tempvotings_list = {}
139 for key, val in pairs(tempvotings) do
140 tempvotings_list[#tempvotings_list+1] = tostring(key) .. ":" .. tostring(val)
141 end
143 tempvoting_string = table.concat(tempvotings_list, ";")
145 request.redirect{
146 module = "vote",
147 view = "list",
148 params = {
149 issue_id = issue.id,
150 scoring = tempvoting_string
151 }
152 }
154 end