liquid_feedback_frontend

annotate app/main/delegation/show.lua @ 570:b904fc12cc1a

Show only units with voting privilege in member_home page
author bsw
date Tue Jun 19 23:18:39 2012 +0200 (2012-06-19)
parents 774d8804ce65
children e7baf2713987
rev   line source
bsw@525 1 local voting_right_unit_id
bsw@529 2 local current_trustee_id
bsw@529 3 local current_trustee_name
bsw@525 4
bsw@525 5 local unit = Unit:by_id(param.get("unit_id", atom.integer))
bsw@525 6 if unit then
bsw@529 7 unit:load_delegation_info_once_for_member_id(app.session.member_id)
bsw@525 8 voting_right_unit_id = unit.id
bsw@529 9 if unit.delegation_info.own_delegation_scope == 'unit' then
bsw@529 10 current_trustee_id = unit.delegation_info.first_trustee_id
bsw@529 11 current_trustee_name = unit.delegation_info.first_trustee_name
bsw@529 12 end
bsw@563 13 ui.title(config.single_unit_id and _"Set global delegation" or _"Set unit delegation")
bsw@525 14 util.help("delegation.new.unit")
bsw@525 15 end
bsw@525 16
bsw@525 17 local area = Area:by_id(param.get("area_id", atom.integer))
bsw@525 18 if area then
bsw@529 19 area:load_delegation_info_once_for_member_id(app.session.member_id)
bsw@525 20 voting_right_unit_id = area.unit_id
bsw@563 21 if area.delegation_info.own_delegation_scope == 'area' then
bsw@563 22 current_trustee_id = area.delegation_info.first_trustee_id
bsw@563 23 current_trustee_name = area.delegation_info.first_trustee_name
bsw@563 24 end
bsw@563 25 ui.title(_"Set delegation for Area '#{name}'":gsub("#{name}", area.name))
bsw@525 26 util.help("delegation.new.area")
bsw@525 27 end
bsw@525 28
bsw@525 29 local issue = Issue:by_id(param.get("issue_id", atom.integer))
bsw@525 30 if issue then
bsw@551 31 issue:load("member_info", { member_id = app.session.member_id })
bsw@525 32 voting_right_unit_id = issue.area.unit_id
bsw@563 33 if issue.member_info.own_delegation_scope == 'issue' then
bsw@563 34 current_trustee_id = issue.member_info.first_trustee_id
bsw@563 35 current_trustee_name = issue.member_info.first_trustee_name
bsw@563 36 end
bsw@563 37 ui.title(_"Set delegation for Issue ##{number} in Area '#{area_name}'":gsub("#{number}", issue.id):gsub("#{area_name}", issue.area.name))
bsw@525 38 util.help("delegation.new.issue")
bsw@525 39 end
bsw@525 40
bsw@525 41 local initiative = Initiative:by_id(param.get("initiative_id", atom.integer))
bsw@525 42
bsw@529 43 local contact_members = Member:build_selector{
bsw@529 44 is_contact_of_member_id = app.session.member_id,
bsw@529 45 voting_right_for_unit_id = voting_right_unit_id,
bsw@529 46 active = true,
bsw@529 47 order = "name"
bsw@529 48 }:exec()
bsw@529 49
bsw@529 50 local preview_trustee_id = param.get("preview_trustee_id", atom.integer)
bsw@529 51
bsw@529 52 ui.script{ static = "js/update_delegation_info.js" }
bsw@529 53
bsw@525 54 slot.select("actions", function()
bsw@525 55 if issue then
bsw@525 56 ui.link{
bsw@525 57 module = "issue",
bsw@525 58 view = "show",
bsw@525 59 id = issue.id,
bsw@525 60 content = function()
bsw@525 61 ui.image{ static = "icons/16/cancel.png" }
bsw@525 62 slot.put(_"Cancel")
bsw@525 63 end,
bsw@525 64 }
bsw@525 65 elseif area then
bsw@525 66 ui.link{
bsw@525 67 module = "area",
bsw@525 68 view = "show",
bsw@525 69 id = area.id,
bsw@525 70 content = function()
bsw@525 71 ui.image{ static = "icons/16/cancel.png" }
bsw@525 72 slot.put(_"Cancel")
bsw@525 73 end,
bsw@525 74 }
bsw@525 75 else
bsw@525 76 ui.link{
bsw@525 77 module = "index",
bsw@525 78 view = "index",
bsw@525 79 content = function()
bsw@525 80 ui.image{ static = "icons/16/cancel.png" }
bsw@525 81 slot.put(_"Cancel")
bsw@525 82 end,
bsw@525 83 }
bsw@525 84 end
bsw@525 85 end)
bsw@525 86
bsw@525 87
bsw@525 88 ui.form{
bsw@529 89 attr = { class = "vertical", id = "delegationForm" },
bsw@525 90 module = "delegation",
bsw@525 91 action = "update",
bsw@525 92 params = {
bsw@525 93 unit_id = unit and unit.id or nil,
bsw@525 94 area_id = area and area.id or nil,
bsw@525 95 issue_id = issue and issue.id or nil,
bsw@525 96 },
bsw@525 97 routing = {
bsw@525 98 default = {
bsw@525 99 mode = "redirect",
bsw@525 100 module = area and "area" or initiative and "initiative" or issue and "issue" or "unit",
bsw@525 101 view = "show",
bsw@525 102 id = area and area.id or initiative and initiative.id or issue and issue.id or unit.id
bsw@525 103 }
bsw@525 104 },
bsw@525 105 content = function()
bsw@525 106 local records
bsw@525 107
bsw@525 108 if issue then
bsw@525 109 local delegate_name = ""
bsw@525 110 local scope = "no delegation set"
bsw@525 111 local area_delegation = Delegation:by_pk(app.session.member_id, nil, issue.area_id)
bsw@525 112 if area_delegation then
bsw@525 113 delegate_name = area_delegation.trustee and area_delegation.trustee.name or _"abandoned"
bsw@525 114 scope = _"area"
bsw@525 115 else
bsw@525 116 local unit_delegation = Delegation:by_pk(app.session.member_id, issue.area.unit_id)
bsw@525 117 if unit_delegation then
bsw@525 118 delegate_name = unit_delegation.trustee.name
bsw@525 119 scope = config.single_unit_id and _"global" or _"unit"
bsw@525 120 end
bsw@525 121 end
bsw@525 122 local text_apply
bsw@525 123 local text_abandon
bsw@525 124 if config.single_unit_id then
bsw@525 125 text_apply = _("Apply global or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
bsw@525 126 text_abandon = _"Abandon unit and area delegations for this issue"
bsw@525 127 else
bsw@525 128 text_apply = _("Apply unit or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
bsw@525 129 text_abandon = _"Abandon unit and area delegations for this issue"
bsw@525 130 end
bsw@525 131 records = {
bsw@525 132 { id = -1, name = text_apply },
bsw@525 133 { id = 0, name = text_abandon }
bsw@525 134 }
bsw@525 135 elseif area then
bsw@525 136 local delegate_name = ""
bsw@525 137 local scope = "no delegation set"
bsw@525 138 local unit_delegation = Delegation:by_pk(app.session.member_id, area.unit_id)
bsw@525 139 if unit_delegation then
bsw@525 140 delegate_name = unit_delegation.trustee.name
bsw@525 141 scope = config.single_unit_id and _"global" or _"unit"
bsw@525 142 end
bsw@525 143 local text_apply
bsw@525 144 local text_abandon
bsw@525 145 if config.single_unit_id then
bsw@525 146 text_apply = _("Apply global delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
bsw@525 147 text_abandon = _"Abandon global delegation for this area"
bsw@525 148 else
bsw@525 149 text_apply = _("Apply unit delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
bsw@525 150 text_abandon = _"Abandon unit delegation for this area"
bsw@525 151 end
bsw@525 152 records = {
bsw@525 153 {
bsw@525 154 id = -1,
bsw@525 155 name = text_apply
bsw@525 156 },
bsw@525 157 {
bsw@525 158 id = 0,
bsw@525 159 name = text_abandon
bsw@525 160 }
bsw@525 161 }
bsw@525 162
bsw@525 163 else
bsw@525 164 records = {
bsw@525 165 {
bsw@525 166 id = -1,
bsw@525 167 name = _"No delegation"
bsw@525 168 }
bsw@525 169 }
bsw@525 170
bsw@525 171 end
bsw@525 172 -- add saved members
bsw@529 173 if current_trustee_id then
bsw@529 174 records[#records+1] = {id="_", name= "--- " .. _"Current trustee" .. " ---"}
bsw@529 175 records[#records+1] = { id = current_trustee_id, name = current_trustee_name }
bsw@529 176 end
bsw@529 177 -- add saved members
bsw@525 178 records[#records+1] = {id="_", name= "--- " .. _"Saved contacts" .. " ---"}
bsw@525 179 for i, record in ipairs(contact_members) do
bsw@525 180 records[#records+1] = record
bsw@525 181 end
bsw@525 182 -- add initiative authors
bsw@525 183 if initiative then
bsw@525 184 records[#records+1] = {id="_", name= "--- " .. _"Initiators" .. " ---"}
bsw@525 185 for i,record in ipairs(initiative.initiators) do
bsw@525 186 records[#records+1] = record.member
bsw@525 187 end
bsw@525 188 end
bsw@525 189
bsw@525 190 disabled_records = {}
bsw@525 191 disabled_records["_"] = true
bsw@525 192 disabled_records[app.session.member_id] = true
bsw@525 193
bsw@525 194 ui.field.select{
bsw@529 195 attr = { onchange = "updateDelegationInfo();" },
bsw@525 196 label = _"Trustee",
bsw@525 197 name = "trustee_id",
bsw@525 198 foreign_records = records,
bsw@525 199 foreign_id = "id",
bsw@525 200 foreign_name = "name",
bsw@529 201 disabled_records = disabled_records,
bsw@529 202 value = preview_trustee_id or current_trustee_id
bsw@525 203 }
bsw@525 204
bsw@529 205 ui.field.hidden{ name = "preview" }
bsw@529 206
bsw@525 207 ui.submit{ text = _"Save" }
bsw@529 208
bsw@525 209 end
bsw@525 210 }
bsw@525 211
bsw@525 212
bsw@525 213
bsw@525 214 -- ------------------------
bsw@525 215
bsw@525 216
bsw@525 217
bsw@525 218
bsw@525 219 local delegation
bsw@525 220 local unit_id
bsw@525 221 local area_id
bsw@525 222 local issue_id
bsw@525 223 local initiative_id
bsw@525 224
bsw@525 225 local scope = "unit"
bsw@525 226
bsw@525 227 unit_id = param.get("unit_id", atom.integer)
bsw@525 228
bsw@525 229 local inline = param.get("inline", atom.boolean)
bsw@525 230
bsw@525 231 if param.get("initiative_id", atom.integer) then
bsw@525 232 initiative_id = param.get("initiative_id", atom.integer)
bsw@525 233 issue_id = Initiative:by_id(initiative_id).issue_id
bsw@525 234 scope = "issue"
bsw@525 235 end
bsw@525 236
bsw@525 237 if param.get("issue_id", atom.integer) then
bsw@525 238 issue_id = param.get("issue_id", atom.integer)
bsw@525 239 scope = "issue"
bsw@525 240 end
bsw@525 241
bsw@525 242 if param.get("area_id", atom.integer) then
bsw@525 243 area_id = param.get("area_id", atom.integer)
bsw@525 244 scope = "area"
bsw@525 245 end
bsw@525 246
bsw@525 247
bsw@525 248
bsw@525 249 local delegation
bsw@525 250 local issue
bsw@525 251
bsw@525 252 if issue_id then
bsw@525 253 issue = Issue:by_id(issue_id)
bsw@525 254 delegation = Delegation:by_pk(app.session.member.id, nil, nil, issue_id)
bsw@525 255 if not delegation then
bsw@525 256 delegation = Delegation:by_pk(app.session.member.id, nil, issue.area_id)
bsw@525 257 end
bsw@525 258 if not delegation then
bsw@525 259 delegation = Delegation:by_pk(app.session.member.id, issue.area.unit_id)
bsw@525 260 end
bsw@525 261 elseif area_id then
bsw@525 262 delegation = Delegation:by_pk(app.session.member.id, nil, area_id)
bsw@525 263 if not delegation then
bsw@525 264 local area = Area:by_id(area_id)
bsw@525 265 delegation = Delegation:by_pk(app.session.member.id, area.unit_id)
bsw@525 266 end
bsw@525 267 end
bsw@525 268
bsw@525 269 if not delegation then
bsw@525 270 delegation = Delegation:by_pk(app.session.member.id, unit_id)
bsw@525 271 end
bsw@525 272
bsw@525 273 local slot_name = "actions"
bsw@525 274
bsw@525 275 if inline then
bsw@525 276 slot_name = "default"
bsw@525 277 end
bsw@525 278
bsw@529 279 if delegation and not delegation.trustee_id then
bsw@525 280 ui.image{
bsw@525 281 static = "icons/16/table_go_crossed.png"
bsw@525 282 }
bsw@525 283 if delegation.issue_id then
bsw@525 284 slot.put(_"Delegation turned off for issue")
bsw@525 285 elseif delegation.area_id then
bsw@525 286 slot.put(_"Delegation turned off for area")
bsw@525 287 end
bsw@525 288 end
bsw@525 289
bsw@525 290 local delegation_chain = Member:new_selector()
bsw@525 291 :add_field("delegation_chain.*")
bsw@529 292 :join({ "delegation_chain(?,?,?,?,?)", app.session.member.id, unit_id, area_id, issue_id, preview_trustee_id }, "delegation_chain", "member.id = delegation_chain.member_id")
bsw@525 293 :add_order_by("index")
bsw@525 294 :exec()
bsw@525 295
bsw@525 296 for i, record in ipairs(delegation_chain) do
bsw@525 297 local style
bsw@525 298 local overridden = (not issue or issue.state ~= 'voting') and record.overridden
bsw@525 299 if record.scope_in then
bsw@525 300 if not overridden then
bsw@525 301 ui.image{
bsw@525 302 attr = { class = "delegation_arrow" },
bsw@525 303 static = "delegation_arrow_24_vertical.png"
bsw@525 304 }
bsw@525 305 else
bsw@525 306 ui.image{
bsw@525 307 attr = { class = "delegation_arrow delegation_arrow_overridden" },
bsw@525 308 static = "delegation_arrow_24_vertical.png"
bsw@525 309 }
bsw@525 310 end
bsw@525 311 ui.tag{
bsw@525 312 attr = { class = "delegation_scope" .. (overridden and " delegation_scope_overridden" or "") },
bsw@525 313 content = function()
bsw@525 314 if record.scope_in == "unit" then
bsw@525 315 slot.put(config.single_object_mode and _"Global delegation" or _"Unit delegation")
bsw@525 316 elseif record.scope_in == "area" then
bsw@525 317 slot.put(_"Area delegation")
bsw@525 318 elseif record.scope_in == "issue" then
bsw@525 319 slot.put(_"Issue delegation")
bsw@525 320 end
bsw@525 321 end
bsw@525 322 }
bsw@525 323 end
bsw@525 324 ui.container{
bsw@525 325 attr = { class = overridden and "delegation_overridden" or "" },
bsw@525 326 content = function()
bsw@525 327 execute.view{
bsw@525 328 module = "member",
bsw@525 329 view = "_show_thumb",
bsw@525 330 params = { member = record }
bsw@525 331 }
bsw@525 332 end
bsw@525 333 }
bsw@525 334 if (not issue or issue.state ~= 'voting') and record.participation and not record.overridden then
bsw@525 335 ui.container{
bsw@525 336 attr = { class = "delegation_participation" },
bsw@525 337 content = function()
bsw@525 338 slot.put(_"This member is participating, the rest of delegation chain is suspended while discussing")
bsw@525 339 end
bsw@525 340 }
bsw@525 341 end
bsw@525 342 slot.put("<br style='clear: left'/>")
bsw@525 343 end

Impressum / About Us