liquid_feedback_frontend

annotate app/main/delegation/show.lua @ 904:a176129ce282

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

Impressum / About Us