liquid_feedback_frontend
view app/main/delegation/_show_box.lua @ 264:1b8d51e21614
More unit support added
author | bsw |
---|---|
date | Tue Feb 07 18:32:18 2012 +0100 (2012-02-07) |
parents | cb2380e08bb5 |
children | 7196685f9dd7 |
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 = config.single_unit_id and _"Change global delegation" or _"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 = config.single_unit_id and _"Set global delegation" or _"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 local member = Member:new_selector()
129 :reset_fields()
130 :add_field("name", "delegation_name")
131 :add_where({ "id = ?", delegation.trustee_id })
132 :single_object_mode()
133 :exec()
134 if delegation.issue_id then
135 slot.put( _("Issue delegated to '#{name}'", { name = member.delegation_name }) )
136 elseif delegation.area_id then
137 slot.put( _("Area delegated to '#{name}'", { name = member.delegation_name }) )
138 else
139 if config.single_unit_id then
140 slot.put( _("Global delegation set to '#{name}'", { name = member.delegation_name }) )
141 else
142 slot.put( _("Unit delegated to '#{name}'", { name = member.delegation_name }) )
143 end
144 end
146 else
147 ui.image{
148 static = "icons/16/table_go_crossed.png"
149 }
150 if delegation.issue_id then
151 slot.put(_"Delegation turned off for issue")
152 elseif delegation.area_id then
153 slot.put(_"Delegation turned off for area")
154 end
155 end
156 ui.image{
157 static = "icons/16/dropdown.png"
158 }
159 end
160 }
161 ui.container{
162 attr = { class = "content", id = "delegation_content" },
163 content = function()
164 ui.container{
165 attr = {
166 class = "close",
167 style = "cursor: pointer;",
168 onclick = "document.getElementById('delegation_content').style.display = 'none';"
169 },
170 content = function()
171 ui.image{ static = "icons/16/cross.png" }
172 end
173 }
175 local delegation_chain = Member:new_selector()
176 :add_field("delegation_chain.*")
177 :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")
178 :add_order_by("index")
179 :exec()
181 if not issue or (issue.state ~= "finished" and issue.state ~= "cancelled") then
182 change_delegation(scope, unit_id, area_id, issue, delegation, initiative_id)
183 end
185 for i, record in ipairs(delegation_chain) do
186 local style
187 local overridden = record.overridden
188 if record.scope_in then
189 ui.container{
190 attr = { class = "delegation_info" },
191 content = function()
192 if not overridden then
193 ui.image{
194 attr = { class = "delegation_arrow" },
195 static = "delegation_arrow_vertical.jpg"
196 }
197 else
198 ui.image{
199 attr = { class = "delegation_arrow delegation_arrow_overridden" },
200 static = "delegation_arrow_vertical.jpg"
201 }
202 end
203 ui.container{
204 attr = { class = "delegation_scope" .. (overridden and " delegation_scope_overridden" or "") },
205 content = function()
206 if record.scope_in == "unit" then
207 slot.put(config.single_object_mode and _"Global delegation" or _"Unit delegation")
208 elseif record.scope_in == "area" then
209 slot.put(_"Area delegation")
210 elseif record.scope_in == "issue" then
211 slot.put(_"Issue delegation")
212 end
213 end
214 }
215 end
216 }
217 end
218 ui.container{
219 attr = { class = overridden and "delegation_overridden" or "" },
220 content = function()
221 execute.view{
222 module = "member",
223 view = "_show_thumb",
224 params = { member = record }
225 }
226 end
227 }
228 if record.participation and not record.overridden then
229 ui.container{
230 attr = { class = "delegation_participation" },
231 content = function()
232 slot.put(_"This member is participating, the rest of delegation chain is suspended while discussing")
233 end
234 }
235 end
236 slot.put("<br style='clear: left'/>")
237 end
238 end
239 }
240 end
241 }
242 else
243 change_delegation(scope, unit_id, area_id, issue, nil, initiative_id)
244 end
245 end)