liquid_feedback_frontend

view app/main/delegation/_show_box.lua @ 180:02aacb3dffe0

Added support for null delegation in upcoming core release
author bsw
date Sun Oct 31 23:38:43 2010 +0100 (2010-10-31)
parents bf885faf3452
children 02197b85ca3b
line source
1 function change_delegation(scope, area_id, issue, delegation, initiative_id)
2 local image
3 local text
4 if scope == "global" and delegation then
5 image = { static = "icons/16/table_go.png" }
6 text = _"Change global delegation"
7 elseif scope == "global" and not delegation then
8 image = { static = "icons/16/table_go.png" }
9 text = _"Set global 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 },
40 }
41 if delegation then
42 ui.link{
43 image = { static = "icons/16/delete.png" },
44 text = _"Revoke",
45 module = "delegation",
46 action = "update",
47 params = { issue_id = delegation.issue_id, area_id = delegation.area_id, delete = true },
48 routing = {
49 default = {
50 mode = "redirect",
51 module = request.get_module(),
52 view = request.get_view(),
53 id = param.get_id_cgi(),
54 params = param.get_all_cgi()
55 }
56 }
57 }
58 end
59 end
60 }
61 end
63 local delegation
64 local area_id
65 local issue_id
66 local initiative_id
68 local scope = "global"
70 if param.get("initiative_id", atom.integer) then
71 initiative_id = param.get("initiative_id", atom.integer)
72 issue_id = Initiative:by_id(initiative_id).issue_id
73 scope = "issue"
74 end
76 if param.get("issue_id", atom.integer) then
77 issue_id = param.get("issue_id", atom.integer)
78 scope = "issue"
79 end
81 if param.get("area_id", atom.integer) then
82 area_id = param.get("area_id", atom.integer)
83 scope = "area"
84 end
88 local delegation
89 local issue
91 if issue_id then
92 issue = Issue:by_id(issue_id)
93 delegation = Delegation:by_pk(app.session.member.id, nil, issue_id)
94 if not delegation then
95 delegation = Delegation:by_pk(app.session.member.id, issue.area_id)
96 end
97 elseif area_id then
98 delegation = Delegation:by_pk(app.session.member.id, area_id)
99 end
101 if not delegation then
102 delegation = Delegation:by_pk(app.session.member.id)
103 end
106 slot.select("actions", function()
108 if delegation then
109 ui.container{
110 attr = { class = "delegation vote_info"},
111 content = function()
112 ui.container{
113 attr = {
114 title = _"Click for details",
115 class = "head head_active",
116 style = "cursor: pointer;",
117 onclick = "document.getElementById('delegation_content').style.display = 'block';"
118 },
119 content = function()
120 if delegation.trustee_id then
121 ui.image{
122 static = "icons/16/table_go.png"
123 }
124 if delegation.issue_id then
125 slot.put(_"Issue delegation active")
126 elseif delegation.area_id then
127 slot.put(_"Area wide delegation active")
128 else
129 slot.put(_"Global delegation active")
130 end
131 else
132 ui.image{
133 static = "icons/16/table_go_crossed.png"
134 }
135 if delegation.issue_id then
136 slot.put(_"Delegation turned off for issue")
137 elseif delegation.area_id then
138 slot.put(_"Delegation turned off for area")
139 end
140 end
141 ui.image{
142 static = "icons/16/dropdown.png"
143 }
144 end
145 }
146 ui.container{
147 attr = { class = "content", id = "delegation_content" },
148 content = function()
149 ui.container{
150 attr = {
151 class = "close",
152 style = "cursor: pointer;",
153 onclick = "document.getElementById('delegation_content').style.display = 'none';"
154 },
155 content = function()
156 ui.image{ static = "icons/16/cross.png" }
157 end
158 }
160 local delegation_chain = Member:new_selector()
161 :add_field("delegation_chain.*")
162 :join("delegation_chain(" .. tostring(app.session.member.id) .. ", " .. tostring(area_id or "NULL") .. ", " .. tostring(issue_id or "NULL") .. ")", "delegation_chain", "member.id = delegation_chain.member_id")
163 :add_order_by("index")
164 :exec()
166 if not issue or (issue.state ~= "finished" and issue.state ~= "cancelled") then
167 change_delegation(scope, area_id, issue, delegation, initiative_id)
168 end
170 for i, record in ipairs(delegation_chain) do
171 local style
172 local overridden = record.overridden
173 if record.scope_in then
174 ui.container{
175 attr = { class = "delegation_info" },
176 content = function()
177 if not overridden then
178 ui.image{
179 attr = { class = "delegation_arrow" },
180 static = "delegation_arrow_vertical.jpg"
181 }
182 else
183 ui.image{
184 attr = { class = "delegation_arrow delegation_arrow_overridden" },
185 static = "delegation_arrow_vertical.jpg"
186 }
187 end
188 ui.container{
189 attr = { class = "delegation_scope" .. (overridden and " delegation_scope_overridden" or "") },
190 content = function()
191 if record.scope_in == "global" then
192 slot.put(_"Global delegation")
193 elseif record.scope_in == "area" then
194 slot.put(_"Area delegation")
195 elseif record.scope_in == "issue" then
196 slot.put(_"Issue delegation")
197 end
198 end
199 }
200 end
201 }
202 end
203 ui.container{
204 attr = { class = overridden and "delegation_overridden" or "" },
205 content = function()
206 execute.view{
207 module = "member",
208 view = "_show_thumb",
209 params = { member = record }
210 }
211 end
212 }
213 if record.participation and not record.overridden then
214 ui.container{
215 attr = { class = "delegation_participation" },
216 content = function()
217 slot.put(_"This member is participating, the rest of delegation chain is suspended while discussing")
218 end
219 }
220 end
221 slot.put("<br style='clear: left'/>")
222 end
223 end
224 }
225 end
226 }
227 else
228 change_delegation(scope, area_id, issue, nil, initiative_id)
229 end
230 end)

Impressum / About Us