liquid_feedback_frontend
view app/main/delegation/_show_box.lua @ 248:e3613831cd1e
Migrate global delegation to unit level
author | bsw |
---|---|
date | Fri Dec 30 03:13:10 2011 +0100 (2011-12-30) |
parents | 6efacc81ce81 |
children | cb2380e08bb5 |
line source
1 function change_delegation(scope, unit_id, area_id, issue, delegation, initiative_id)
2 local image
3 local text
4 if scope == "unit" and delegation and delegation.unit_id then
5 image = { static = "icons/16/table_go.png" }
6 text = _"Change unit delegation"
7 elseif scope == "unit" and not (delegation and delegation.unit_id) then
8 image = { static = "icons/16/table_go.png" }
9 text = _"Set unit delegation"
10 elseif scope == "area" and delegation and delegation.area_id then
11 image = { static = "icons/16/table_go.png" }
12 text = _"Change area delegation"
13 elseif scope == "area" and not (delegation and delegation.area_id) then
14 image = { static = "icons/16/table_go.png" }
15 text = _"Set area delegation"
16 elseif scope == "issue" then
17 if delegation and delegation.issue_id then
18 image = { static = "icons/16/table_go.png" }
19 text = _"Change issue delegation"
20 elseif issue.state ~= "finished" and issue.state ~= "cancelled" then
21 image = { static = "icons/16/table_go.png" }
22 text = _"Set issue delegation"
23 end
24 end
25 ui.container{
26 attr = {
27 class = "change_delegation",
28 },
29 content = function()
30 ui.link{
31 image = image,
32 text = text,
33 module = "delegation",
34 view = "new",
35 params = {
36 issue_id = issue and issue.id or nil,
37 initiative_id = initiative_id or nil,
38 area_id = area_id,
39 unit_id = unit_id
40 },
41 }
42 if delegation then
43 ui.link{
44 image = { static = "icons/16/delete.png" },
45 text = _"Revoke",
46 module = "delegation",
47 action = "update",
48 params = { issue_id = delegation.issue_id, area_id = delegation.area_id, unit_id = delegation.unit_id, delete = true },
49 routing = {
50 default = {
51 mode = "redirect",
52 module = request.get_module(),
53 view = request.get_view(),
54 id = param.get_id_cgi(),
55 params = param.get_all_cgi()
56 }
57 }
58 }
59 end
60 end
61 }
62 end
64 local delegation
65 local unit_id
66 local area_id
67 local issue_id
68 local initiative_id
70 local scope = "unit"
72 unit_id = param.get("unit_id", atom.integer)
74 if param.get("initiative_id", atom.integer) then
75 initiative_id = param.get("initiative_id", atom.integer)
76 issue_id = Initiative:by_id(initiative_id).issue_id
77 scope = "issue"
78 end
80 if param.get("issue_id", atom.integer) then
81 issue_id = param.get("issue_id", atom.integer)
82 scope = "issue"
83 end
85 if param.get("area_id", atom.integer) then
86 area_id = param.get("area_id", atom.integer)
87 scope = "area"
88 end
92 local delegation
93 local issue
95 if issue_id then
96 issue = Issue:by_id(issue_id)
97 delegation = Delegation:by_pk(app.session.member.id, nil, nil, issue_id)
98 if not delegation then
99 delegation = Delegation:by_pk(app.session.member.id, nil, issue.area_id)
100 end
101 elseif area_id then
102 delegation = Delegation:by_pk(app.session.member.id, nil, area_id)
103 end
105 if not delegation then
106 delegation = Delegation:by_pk(app.session.member.id, unit_id)
107 end
110 slot.select("actions", function()
112 if delegation then
113 ui.container{
114 attr = { class = "delegation vote_info"},
115 content = function()
116 ui.container{
117 attr = {
118 title = _"Click for details",
119 class = "head head_active",
120 style = "cursor: pointer;",
121 onclick = "document.getElementById('delegation_content').style.display = 'block';"
122 },
123 content = function()
124 if delegation.trustee_id then
125 ui.image{
126 static = "icons/16/table_go.png"
127 }
128 if delegation.issue_id then
129 slot.put(_"Issue delegation active")
130 elseif delegation.area_id then
131 slot.put(_"Area delegation active")
132 else
133 slot.put(_"Unit delegation active")
134 end
135 else
136 ui.image{
137 static = "icons/16/table_go_crossed.png"
138 }
139 if delegation.issue_id then
140 slot.put(_"Delegation turned off for issue")
141 elseif delegation.area_id then
142 slot.put(_"Delegation turned off for area")
143 end
144 end
145 ui.image{
146 static = "icons/16/dropdown.png"
147 }
148 end
149 }
150 ui.container{
151 attr = { class = "content", id = "delegation_content" },
152 content = function()
153 ui.container{
154 attr = {
155 class = "close",
156 style = "cursor: pointer;",
157 onclick = "document.getElementById('delegation_content').style.display = 'none';"
158 },
159 content = function()
160 ui.image{ static = "icons/16/cross.png" }
161 end
162 }
164 local delegation_chain = Member:new_selector()
165 :add_field("delegation_chain.*")
166 :join("delegation_chain(" .. tostring(app.session.member.id) .. ", " .. tostring(unit_id or "NULL") .. ", " .. tostring(area_id or "NULL") .. ", " .. tostring(issue_id or "NULL") .. ")", "delegation_chain", "member.id = delegation_chain.member_id")
167 :add_order_by("index")
168 :exec()
170 if not issue or (issue.state ~= "finished" and issue.state ~= "cancelled") then
171 change_delegation(scope, unit_id, area_id, issue, delegation, initiative_id)
172 end
174 for i, record in ipairs(delegation_chain) do
175 local style
176 local overridden = record.overridden
177 if record.scope_in then
178 ui.container{
179 attr = { class = "delegation_info" },
180 content = function()
181 if not overridden then
182 ui.image{
183 attr = { class = "delegation_arrow" },
184 static = "delegation_arrow_vertical.jpg"
185 }
186 else
187 ui.image{
188 attr = { class = "delegation_arrow delegation_arrow_overridden" },
189 static = "delegation_arrow_vertical.jpg"
190 }
191 end
192 ui.container{
193 attr = { class = "delegation_scope" .. (overridden and " delegation_scope_overridden" or "") },
194 content = function()
195 if record.scope_in == "unit" then
196 slot.put(_"Unit delegation")
197 elseif record.scope_in == "area" then
198 slot.put(_"Area delegation")
199 elseif record.scope_in == "issue" then
200 slot.put(_"Issue delegation")
201 end
202 end
203 }
204 end
205 }
206 end
207 ui.container{
208 attr = { class = overridden and "delegation_overridden" or "" },
209 content = function()
210 execute.view{
211 module = "member",
212 view = "_show_thumb",
213 params = { member = record }
214 }
215 end
216 }
217 if record.participation and not record.overridden then
218 ui.container{
219 attr = { class = "delegation_participation" },
220 content = function()
221 slot.put(_"This member is participating, the rest of delegation chain is suspended while discussing")
222 end
223 }
224 end
225 slot.put("<br style='clear: left'/>")
226 end
227 end
228 }
229 end
230 }
231 else
232 change_delegation(scope, unit_id, area_id, issue, nil, initiative_id)
233 end
234 end)