liquid_feedback_frontend
diff app/main/delegation/show.lua @ 525:63d6549cc00b
Delegation chain preview improved, better visualisation of current context, code cleanup
author | bsw |
---|---|
date | Fri May 18 19:07:07 2012 +0200 (2012-05-18) |
parents | |
children | 5ca9de94cb13 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/app/main/delegation/show.lua Fri May 18 19:07:07 2012 +0200 1.3 @@ -0,0 +1,314 @@ 1.4 +local voting_right_unit_id 1.5 + 1.6 +local unit = Unit:by_id(param.get("unit_id", atom.integer)) 1.7 +if unit then 1.8 + voting_right_unit_id = unit.id 1.9 + slot.put_into("title", encode.html(config.single_unit_id and _"Set global delegation" or _"Set unit delegation")) 1.10 + util.help("delegation.new.unit") 1.11 +end 1.12 + 1.13 +local area = Area:by_id(param.get("area_id", atom.integer)) 1.14 +if area then 1.15 + voting_right_unit_id = area.unit_id 1.16 + slot.put_into("title", encode.html(_"Set delegation for Area '#{name}'":gsub("#{name}", area.name))) 1.17 + util.help("delegation.new.area") 1.18 +end 1.19 + 1.20 +local issue = Issue:by_id(param.get("issue_id", atom.integer)) 1.21 +if issue then 1.22 + voting_right_unit_id = issue.area.unit_id 1.23 + slot.put_into("title", encode.html(_"Set delegation for Issue ##{number} in Area '#{area_name}'":gsub("#{number}", issue.id):gsub("#{area_name}", issue.area.name))) 1.24 + util.help("delegation.new.issue") 1.25 +end 1.26 + 1.27 +local initiative = Initiative:by_id(param.get("initiative_id", atom.integer)) 1.28 + 1.29 +slot.select("actions", function() 1.30 + if issue then 1.31 + ui.link{ 1.32 + module = "issue", 1.33 + view = "show", 1.34 + id = issue.id, 1.35 + content = function() 1.36 + ui.image{ static = "icons/16/cancel.png" } 1.37 + slot.put(_"Cancel") 1.38 + end, 1.39 + } 1.40 + elseif area then 1.41 + ui.link{ 1.42 + module = "area", 1.43 + view = "show", 1.44 + id = area.id, 1.45 + content = function() 1.46 + ui.image{ static = "icons/16/cancel.png" } 1.47 + slot.put(_"Cancel") 1.48 + end, 1.49 + } 1.50 + else 1.51 + ui.link{ 1.52 + module = "index", 1.53 + view = "index", 1.54 + content = function() 1.55 + ui.image{ static = "icons/16/cancel.png" } 1.56 + slot.put(_"Cancel") 1.57 + end, 1.58 + } 1.59 + end 1.60 +end) 1.61 + 1.62 + 1.63 +local contact_members = Member:build_selector{ 1.64 + is_contact_of_member_id = app.session.member_id, 1.65 + voting_right_for_unit_id = voting_right_unit_id, 1.66 + order = "name" 1.67 +}:exec() 1.68 + 1.69 +ui.form{ 1.70 + attr = { class = "vertical" }, 1.71 + module = "delegation", 1.72 + action = "update", 1.73 + params = { 1.74 + unit_id = unit and unit.id or nil, 1.75 + area_id = area and area.id or nil, 1.76 + issue_id = issue and issue.id or nil, 1.77 + }, 1.78 + routing = { 1.79 + default = { 1.80 + mode = "redirect", 1.81 + module = area and "area" or initiative and "initiative" or issue and "issue" or "unit", 1.82 + view = "show", 1.83 + id = area and area.id or initiative and initiative.id or issue and issue.id or unit.id 1.84 + } 1.85 + }, 1.86 + content = function() 1.87 + local records 1.88 + 1.89 + if issue then 1.90 + local delegate_name = "" 1.91 + local scope = "no delegation set" 1.92 + local area_delegation = Delegation:by_pk(app.session.member_id, nil, issue.area_id) 1.93 + if area_delegation then 1.94 + delegate_name = area_delegation.trustee and area_delegation.trustee.name or _"abandoned" 1.95 + scope = _"area" 1.96 + else 1.97 + local unit_delegation = Delegation:by_pk(app.session.member_id, issue.area.unit_id) 1.98 + if unit_delegation then 1.99 + delegate_name = unit_delegation.trustee.name 1.100 + scope = config.single_unit_id and _"global" or _"unit" 1.101 + end 1.102 + end 1.103 + local text_apply 1.104 + local text_abandon 1.105 + if config.single_unit_id then 1.106 + text_apply = _("Apply global or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope }) 1.107 + text_abandon = _"Abandon unit and area delegations for this issue" 1.108 + else 1.109 + text_apply = _("Apply unit or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope }) 1.110 + text_abandon = _"Abandon unit and area delegations for this issue" 1.111 + end 1.112 + records = { 1.113 + { id = -1, name = text_apply }, 1.114 + { id = 0, name = text_abandon } 1.115 + } 1.116 + elseif area then 1.117 + local delegate_name = "" 1.118 + local scope = "no delegation set" 1.119 + local unit_delegation = Delegation:by_pk(app.session.member_id, area.unit_id) 1.120 + if unit_delegation then 1.121 + delegate_name = unit_delegation.trustee.name 1.122 + scope = config.single_unit_id and _"global" or _"unit" 1.123 + end 1.124 + local text_apply 1.125 + local text_abandon 1.126 + if config.single_unit_id then 1.127 + text_apply = _("Apply global delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope }) 1.128 + text_abandon = _"Abandon global delegation for this area" 1.129 + else 1.130 + text_apply = _("Apply unit delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope }) 1.131 + text_abandon = _"Abandon unit delegation for this area" 1.132 + end 1.133 + records = { 1.134 + { 1.135 + id = -1, 1.136 + name = text_apply 1.137 + }, 1.138 + { 1.139 + id = 0, 1.140 + name = text_abandon 1.141 + } 1.142 + } 1.143 + 1.144 + else 1.145 + records = { 1.146 + { 1.147 + id = -1, 1.148 + name = _"No delegation" 1.149 + } 1.150 + } 1.151 + 1.152 + end 1.153 + -- add saved members 1.154 + records[#records+1] = {id="_", name= "--- " .. _"Saved contacts" .. " ---"} 1.155 + for i, record in ipairs(contact_members) do 1.156 + records[#records+1] = record 1.157 + end 1.158 + -- add initiative authors 1.159 + if initiative then 1.160 + records[#records+1] = {id="_", name= "--- " .. _"Initiators" .. " ---"} 1.161 + for i,record in ipairs(initiative.initiators) do 1.162 + records[#records+1] = record.member 1.163 + end 1.164 + end 1.165 + 1.166 + disabled_records = {} 1.167 + disabled_records["_"] = true 1.168 + disabled_records[app.session.member_id] = true 1.169 + 1.170 + ui.field.select{ 1.171 + label = _"Trustee", 1.172 + name = "trustee_id", 1.173 + foreign_records = records, 1.174 + foreign_id = "id", 1.175 + foreign_name = "name", 1.176 + disabled_records = disabled_records 1.177 + } 1.178 + 1.179 + ui.submit{ text = _"Save" } 1.180 + end 1.181 +} 1.182 + 1.183 + 1.184 + 1.185 +-- ------------------------ 1.186 + 1.187 + 1.188 + 1.189 + 1.190 +local delegation 1.191 +local unit_id 1.192 +local area_id 1.193 +local issue_id 1.194 +local initiative_id 1.195 + 1.196 +local scope = "unit" 1.197 + 1.198 +unit_id = param.get("unit_id", atom.integer) 1.199 + 1.200 +local inline = param.get("inline", atom.boolean) 1.201 + 1.202 +if param.get("initiative_id", atom.integer) then 1.203 + initiative_id = param.get("initiative_id", atom.integer) 1.204 + issue_id = Initiative:by_id(initiative_id).issue_id 1.205 + scope = "issue" 1.206 +end 1.207 + 1.208 +if param.get("issue_id", atom.integer) then 1.209 + issue_id = param.get("issue_id", atom.integer) 1.210 + scope = "issue" 1.211 +end 1.212 + 1.213 +if param.get("area_id", atom.integer) then 1.214 + area_id = param.get("area_id", atom.integer) 1.215 + scope = "area" 1.216 +end 1.217 + 1.218 + 1.219 + 1.220 +local delegation 1.221 +local issue 1.222 + 1.223 +if issue_id then 1.224 + issue = Issue:by_id(issue_id) 1.225 + delegation = Delegation:by_pk(app.session.member.id, nil, nil, issue_id) 1.226 + if not delegation then 1.227 + delegation = Delegation:by_pk(app.session.member.id, nil, issue.area_id) 1.228 + end 1.229 + if not delegation then 1.230 + delegation = Delegation:by_pk(app.session.member.id, issue.area.unit_id) 1.231 + end 1.232 +elseif area_id then 1.233 + delegation = Delegation:by_pk(app.session.member.id, nil, area_id) 1.234 + if not delegation then 1.235 + local area = Area:by_id(area_id) 1.236 + delegation = Delegation:by_pk(app.session.member.id, area.unit_id) 1.237 + end 1.238 +end 1.239 + 1.240 +if not delegation then 1.241 + delegation = Delegation:by_pk(app.session.member.id, unit_id) 1.242 +end 1.243 + 1.244 +local slot_name = "actions" 1.245 + 1.246 +if inline then 1.247 + slot_name = "default" 1.248 +end 1.249 + 1.250 +if delegation then 1.251 + 1.252 + if not delegation.trustee_id then 1.253 + ui.image{ 1.254 + static = "icons/16/table_go_crossed.png" 1.255 + } 1.256 + if delegation.issue_id then 1.257 + slot.put(_"Delegation turned off for issue") 1.258 + elseif delegation.area_id then 1.259 + slot.put(_"Delegation turned off for area") 1.260 + end 1.261 + end 1.262 + 1.263 + local delegation_chain = Member:new_selector() 1.264 + :add_field("delegation_chain.*") 1.265 + :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") 1.266 + :add_order_by("index") 1.267 + :exec() 1.268 + 1.269 + for i, record in ipairs(delegation_chain) do 1.270 + local style 1.271 + local overridden = (not issue or issue.state ~= 'voting') and record.overridden 1.272 + if record.scope_in then 1.273 + if not overridden then 1.274 + ui.image{ 1.275 + attr = { class = "delegation_arrow" }, 1.276 + static = "delegation_arrow_24_vertical.png" 1.277 + } 1.278 + else 1.279 + ui.image{ 1.280 + attr = { class = "delegation_arrow delegation_arrow_overridden" }, 1.281 + static = "delegation_arrow_24_vertical.png" 1.282 + } 1.283 + end 1.284 + ui.tag{ 1.285 + attr = { class = "delegation_scope" .. (overridden and " delegation_scope_overridden" or "") }, 1.286 + content = function() 1.287 + if record.scope_in == "unit" then 1.288 + slot.put(config.single_object_mode and _"Global delegation" or _"Unit delegation") 1.289 + elseif record.scope_in == "area" then 1.290 + slot.put(_"Area delegation") 1.291 + elseif record.scope_in == "issue" then 1.292 + slot.put(_"Issue delegation") 1.293 + end 1.294 + end 1.295 + } 1.296 + end 1.297 + ui.container{ 1.298 + attr = { class = overridden and "delegation_overridden" or "" }, 1.299 + content = function() 1.300 + execute.view{ 1.301 + module = "member", 1.302 + view = "_show_thumb", 1.303 + params = { member = record } 1.304 + } 1.305 + end 1.306 + } 1.307 + if (not issue or issue.state ~= 'voting') and record.participation and not record.overridden then 1.308 + ui.container{ 1.309 + attr = { class = "delegation_participation" }, 1.310 + content = function() 1.311 + slot.put(_"This member is participating, the rest of delegation chain is suspended while discussing") 1.312 + end 1.313 + } 1.314 + end 1.315 + slot.put("<br style='clear: left'/>") 1.316 + end 1.317 +end 1.318 \ No newline at end of file