liquid_feedback_frontend

view app/main/delegation/_show_box.lua @ 277:bde068b37608

Dropdown boxes except of delegation box removed, optical enhancements and repositioning of elements
author bsw
date Mon Feb 13 00:16:42 2012 +0100 (2012-02-13)
parents 7196685f9dd7
children b77e6a17ca77
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 local inline = param.get("inline", atom.boolean)
76 if param.get("initiative_id", atom.integer) then
77 initiative_id = param.get("initiative_id", atom.integer)
78 issue_id = Initiative:by_id(initiative_id).issue_id
79 scope = "issue"
80 end
82 if param.get("issue_id", atom.integer) then
83 issue_id = param.get("issue_id", atom.integer)
84 scope = "issue"
85 end
87 if param.get("area_id", atom.integer) then
88 area_id = param.get("area_id", atom.integer)
89 scope = "area"
90 end
94 local delegation
95 local issue
97 if issue_id then
98 issue = Issue:by_id(issue_id)
99 delegation = Delegation:by_pk(app.session.member.id, nil, nil, issue_id)
100 if not delegation then
101 delegation = Delegation:by_pk(app.session.member.id, nil, issue.area_id)
102 end
103 if not delegation then
104 delegation = Delegation:by_pk(app.session.member.id, issue.area.unit_id)
105 end
106 elseif area_id then
107 delegation = Delegation:by_pk(app.session.member.id, nil, area_id)
108 if not delegation then
109 local area = Area:by_id(area_id)
110 delegation = Delegation:by_pk(app.session.member.id, area.unit_id)
111 end
112 end
114 if not delegation then
115 delegation = Delegation:by_pk(app.session.member.id, unit_id)
116 end
118 local slot_name = "actions"
120 if inline then
121 slot_name = "default"
122 end
124 slot.select(slot_name, function()
126 if delegation then
127 ui.container{
128 attr = { class = "delegation vote_info"},
129 content = function()
130 ui.container{
131 attr = {
132 title = _"Click for details",
133 class = "head head_active",
134 style = "cursor: pointer;",
135 onclick = "document.getElementById('delegation_content').style.display = 'block';"
136 },
137 content = function()
138 if delegation.trustee_id then
139 ui.image{
140 static = "icons/16/table_go.png"
141 }
142 local member = Member:new_selector()
143 :reset_fields()
144 :add_field("name", "delegation_name")
145 :add_where({ "id = ?", delegation.trustee_id })
146 :single_object_mode()
147 :exec()
148 if delegation.issue_id then
149 slot.put( _("Issue delegated to '#{name}'", { name = member.delegation_name }) )
150 elseif delegation.area_id then
151 slot.put( _("Area delegated to '#{name}'", { name = member.delegation_name }) )
152 else
153 if config.single_unit_id then
154 slot.put( _("Global delegation set to '#{name}'", { name = member.delegation_name }) )
155 else
156 slot.put( _("Unit delegated to '#{name}'", { name = member.delegation_name }) )
157 end
158 end
160 else
161 ui.image{
162 static = "icons/16/table_go_crossed.png"
163 }
164 if delegation.issue_id then
165 slot.put(_"Delegation turned off for issue")
166 elseif delegation.area_id then
167 slot.put(_"Delegation turned off for area")
168 end
169 end
170 ui.image{
171 static = "icons/16/dropdown.png"
172 }
173 end
174 }
175 ui.container{
176 attr = { class = "content", id = "delegation_content" },
177 content = function()
178 ui.container{
179 attr = {
180 class = "close",
181 style = "cursor: pointer;",
182 onclick = "document.getElementById('delegation_content').style.display = 'none';"
183 },
184 content = function()
185 ui.image{ static = "icons/16/cross.png" }
186 end
187 }
189 local delegation_chain = Member:new_selector()
190 :add_field("delegation_chain.*")
191 :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")
192 :add_order_by("index")
193 :exec()
195 if not issue or (issue.state ~= "finished" and issue.state ~= "cancelled") then
196 change_delegation(scope, unit_id, area_id, issue, delegation, initiative_id)
197 slot.put("<br style='clear: left'/>")
198 end
200 for i, record in ipairs(delegation_chain) do
201 local style
202 local overridden = record.overridden
203 if record.scope_in then
204 ui.container{
205 attr = { class = "delegation_info" },
206 content = function()
207 if not overridden then
208 ui.image{
209 attr = { class = "delegation_arrow" },
210 static = "delegation_arrow_vertical.jpg"
211 }
212 else
213 ui.image{
214 attr = { class = "delegation_arrow delegation_arrow_overridden" },
215 static = "delegation_arrow_vertical.jpg"
216 }
217 end
218 ui.container{
219 attr = { class = "delegation_scope" .. (overridden and " delegation_scope_overridden" or "") },
220 content = function()
221 if record.scope_in == "unit" then
222 slot.put(config.single_object_mode and _"Global delegation" or _"Unit delegation")
223 elseif record.scope_in == "area" then
224 slot.put(_"Area delegation")
225 elseif record.scope_in == "issue" then
226 slot.put(_"Issue delegation")
227 end
228 end
229 }
230 end
231 }
232 end
233 ui.container{
234 attr = { class = overridden and "delegation_overridden" or "" },
235 content = function()
236 execute.view{
237 module = "member",
238 view = "_show_thumb",
239 params = { member = record }
240 }
241 end
242 }
243 if record.participation and not record.overridden then
244 ui.container{
245 attr = { class = "delegation_participation" },
246 content = function()
247 slot.put(_"This member is participating, the rest of delegation chain is suspended while discussing")
248 end
249 }
250 end
251 slot.put("<br style='clear: left'/>")
252 end
253 end
254 }
255 end
256 }
257 else
258 change_delegation(scope, unit_id, area_id, issue, nil, initiative_id)
259 end
260 end)

Impressum / About Us