liquid_feedback_frontend

annotate app/main/delegation/show.lua @ 1252:659e3eda2fad

Minor fixes to new notification system
author bsw
date Sun Apr 17 16:02:26 2016 +0200 (2016-04-17)
parents 904f6807f7fa
children 32cc544d5a5b
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@1045 5 local head_text
bsw@1045 6
bsw@525 7 local unit = Unit:by_id(param.get("unit_id", atom.integer))
bsw@1045 8 local area = Area:by_id(param.get("area_id", atom.integer))
bsw@1045 9 local issue = Issue:by_id(param.get("issue_id", atom.integer))
bsw@1045 10 local initiative = Initiative:by_id(param.get("initiative_id", atom.integer))
bsw@1045 11
bsw@1045 12 if initiative then
bsw@1045 13 issue = initiative.issue
bsw@1045 14 end
bsw@1045 15
bsw@525 16 if unit then
bsw@529 17 unit:load_delegation_info_once_for_member_id(app.session.member_id)
bsw@525 18 voting_right_unit_id = unit.id
bsw@529 19 if unit.delegation_info.own_delegation_scope == 'unit' then
bsw@529 20 current_trustee_id = unit.delegation_info.first_trustee_id
bsw@529 21 current_trustee_name = unit.delegation_info.first_trustee_name
bsw@529 22 end
bsw@1045 23 execute.view { module = "unit", view = "_head", params = { unit = unit } }
bsw@1045 24 head_text = _"Set unit delegation"
bsw@525 25 end
bsw@525 26
bsw@525 27 if area then
bsw@529 28 area:load_delegation_info_once_for_member_id(app.session.member_id)
bsw@525 29 voting_right_unit_id = area.unit_id
bsw@563 30 if area.delegation_info.own_delegation_scope == 'area' then
bsw@563 31 current_trustee_id = area.delegation_info.first_trustee_id
bsw@563 32 current_trustee_name = area.delegation_info.first_trustee_name
bsw@563 33 end
bsw@1045 34 execute.view { module = "area", view = "_head", params = { area = area } }
bsw@1045 35 head_text = _"Set area delegation"
bsw@525 36 end
bsw@525 37
bsw@525 38 if issue then
bsw@551 39 issue:load("member_info", { member_id = app.session.member_id })
bsw@525 40 voting_right_unit_id = issue.area.unit_id
bsw@563 41 if issue.member_info.own_delegation_scope == 'issue' then
bsw@563 42 current_trustee_id = issue.member_info.first_trustee_id
bsw@563 43 current_trustee_name = issue.member_info.first_trustee_name
bsw@563 44 end
bsw@1045 45 execute.view { module = "issue", view = "_head", params = { issue = issue } }
bsw@1045 46 head_text = _"Set issue delegation"
bsw@1045 47 end
bsw@1045 48
bsw@575 49 local delegation
bsw@575 50 local unit_id
bsw@575 51 local area_id
bsw@575 52 local issue_id
bsw@575 53 local initiative_id
bsw@575 54
bsw@575 55 local scope = "unit"
bsw@575 56
bsw@1045 57 local inline = param.get("inline", atom.boolean)
bsw@1045 58
bsw@1045 59
bsw@575 60 unit_id = param.get("unit_id", atom.integer)
bsw@575 61
bsw@575 62 if param.get("initiative_id", atom.integer) then
bsw@1045 63 initiative_id = initiative.id
bsw@575 64 issue_id = initiative.issue_id
bsw@575 65 scope = "issue"
bsw@575 66 end
bsw@575 67
bsw@575 68 if param.get("issue_id", atom.integer) then
bsw@575 69 issue_id = param.get("issue_id", atom.integer)
bsw@575 70 scope = "issue"
bsw@575 71 end
bsw@575 72
bsw@575 73 if param.get("area_id", atom.integer) then
bsw@575 74 area_id = param.get("area_id", atom.integer)
bsw@575 75 scope = "area"
bsw@575 76 end
bsw@575 77
bsw@575 78
bsw@575 79
bsw@575 80 local delegation
bsw@575 81 local issue
bsw@575 82
bsw@575 83 if issue_id then
bsw@575 84 issue = Issue:by_id(issue_id)
bsw@575 85 delegation = Delegation:by_pk(app.session.member.id, nil, nil, issue_id)
bsw@575 86 if not delegation then
bsw@575 87 delegation = Delegation:by_pk(app.session.member.id, nil, issue.area_id)
bsw@575 88 end
bsw@575 89 if not delegation then
bsw@575 90 delegation = Delegation:by_pk(app.session.member.id, issue.area.unit_id)
bsw@575 91 end
bsw@575 92 elseif area_id then
bsw@575 93 delegation = Delegation:by_pk(app.session.member.id, nil, area_id)
bsw@575 94 if not delegation then
bsw@575 95 local area = Area:by_id(area_id)
bsw@575 96 delegation = Delegation:by_pk(app.session.member.id, area.unit_id)
bsw@575 97 end
bsw@575 98 end
bsw@575 99
bsw@575 100 if not delegation then
bsw@575 101 delegation = Delegation:by_pk(app.session.member.id, unit_id)
bsw@575 102 end
bsw@525 103
bsw@529 104 local contact_members = Member:build_selector{
bsw@529 105 is_contact_of_member_id = app.session.member_id,
bsw@529 106 voting_right_for_unit_id = voting_right_unit_id,
bsw@529 107 active = true,
bsw@529 108 order = "name"
bsw@529 109 }:exec()
bsw@529 110
bsw@529 111 local preview_trustee_id = param.get("preview_trustee_id", atom.integer)
bsw@529 112
bsw@529 113 ui.script{ static = "js/update_delegation_info.js" }
bsw@529 114
bsw@1045 115
bsw@1045 116 ui.section( function ()
bsw@1045 117
bsw@1045 118 ui.sectionHead( function ()
bsw@1045 119 ui.heading{ level = 1, content = head_text }
bsw@1045 120 end )
bsw@1045 121
bsw@1045 122 ui.sectionRow( function ()
bsw@525 123
bsw@1045 124 ui.form{
bsw@1045 125 attr = { class = "wide section", id = "delegationForm" },
bsw@1045 126 module = "delegation",
bsw@1045 127 action = "update",
bsw@1045 128 params = {
bsw@1045 129 unit_id = unit and unit.id or nil,
bsw@1045 130 area_id = area and area.id or nil,
bsw@1045 131 issue_id = issue and issue.id or nil,
bsw@1045 132 initiative_id = initiative_id
bsw@1045 133 },
bsw@1045 134 routing = {
bsw@1045 135 default = {
bsw@1045 136 mode = "redirect",
bsw@1045 137 module = area and "area" or initiative and "initiative" or issue and "issue" or "unit",
bsw@1045 138 view = "show",
bsw@1045 139 id = area and area.id or initiative and initiative.id or issue and issue.id or unit.id,
bsw@1045 140 }
bsw@1045 141 },
bsw@1045 142 content = function()
bsw@1145 143 local records
bsw@1045 144 if issue then
bsw@1045 145 local delegate_name = ""
bsw@1098 146 local scope = _"no delegation set"
bsw@1045 147 local area_delegation = Delegation:by_pk(app.session.member_id, nil, issue.area_id)
bsw@1045 148 if area_delegation then
bsw@1045 149 delegate_name = area_delegation.trustee and area_delegation.trustee.name or _"abandoned"
bsw@1045 150 scope = _"area"
bsw@1045 151 else
bsw@1045 152 local unit_delegation = Delegation:by_pk(app.session.member_id, issue.area.unit_id)
bsw@1045 153 if unit_delegation then
bsw@1045 154 delegate_name = unit_delegation.trustee.name
bsw@1045 155 scope = config.single_unit_id and _"global" or _"unit"
bsw@1045 156 end
bsw@1045 157 end
bsw@1045 158 local text_apply
bsw@1045 159 local text_abandon
bsw@1045 160 if config.single_unit_id then
bsw@1045 161 text_apply = _("Apply global or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
bsw@1045 162 text_abandon = _"Abandon unit and area delegations for this issue"
bsw@1045 163 else
bsw@1045 164 text_apply = _("Apply unit or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
bsw@1045 165 text_abandon = _"Abandon unit and area delegations for this issue"
bsw@1045 166 end
bsw@1045 167
bsw@1045 168 records = {
bsw@1045 169 { id = -1, name = text_apply },
bsw@1045 170 { id = 0, name = text_abandon }
bsw@1045 171 }
bsw@1045 172 elseif area then
bsw@1045 173 local delegate_name = ""
bsw@1098 174 local scope = _"no delegation set"
bsw@1045 175 local unit_delegation = Delegation:by_pk(app.session.member_id, area.unit_id)
bsw@525 176 if unit_delegation then
bsw@525 177 delegate_name = unit_delegation.trustee.name
bsw@525 178 scope = config.single_unit_id and _"global" or _"unit"
bsw@525 179 end
bsw@1045 180 local text_apply
bsw@1045 181 local text_abandon
bsw@1045 182 if config.single_unit_id then
bsw@1045 183 text_apply = _("Apply global delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
bsw@1045 184 text_abandon = _"Abandon global delegation for this area"
bsw@1045 185 else
bsw@1045 186 text_apply = _("Apply unit delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
bsw@1045 187 text_abandon = _"Abandon unit delegation for this area"
bsw@1045 188 end
bsw@1045 189 records = {
bsw@1045 190 {
bsw@1045 191 id = -1,
bsw@1045 192 name = text_apply
bsw@1045 193 },
bsw@1045 194 {
bsw@1045 195 id = 0,
bsw@1045 196 name = text_abandon
bsw@1045 197 }
bsw@1045 198 }
bsw@1045 199
bsw@525 200 else
bsw@1045 201 records = {
bsw@1045 202 {
bsw@1045 203 id = -1,
bsw@1045 204 name = _"No delegation"
bsw@1045 205 }
bsw@1045 206 }
bsw@1045 207
bsw@525 208 end
bsw@1045 209 -- add current trustee
bsw@1045 210 if current_trustee_id then
bsw@1045 211 records[#records+1] = {id="_", name= "--- " .. _"Current delegatee" .. " ---"}
bsw@1045 212 records[#records+1] = { id = current_trustee_id, name = current_trustee_name }
bsw@1045 213 end
bsw@1045 214 -- add initiative authors
bsw@1045 215 if initiative then
bsw@1045 216 records[#records+1] = {id="_", name= "--- " .. _"Initiators" .. " ---"}
bsw@1045 217 for i,record in ipairs(initiative.initiators) do
bsw@1045 218 records[#records+1] = record.member
bsw@1045 219 end
bsw@1045 220 end
bsw@1045 221 -- add saved members
bsw@1045 222 if #contact_members > 0 then
bsw@1045 223 records[#records+1] = {id="_", name= "--- " .. _"Saved contacts" .. " ---"}
bsw@1045 224 for i, record in ipairs(contact_members) do
bsw@1045 225 records[#records+1] = record
bsw@1045 226 end
bsw@1045 227 end
bsw@1045 228
bsw@1145 229 local disabled_records = {}
bsw@1045 230 disabled_records["_"] = true
bsw@1045 231 disabled_records[app.session.member_id] = true
bsw@1045 232
bsw@1045 233 local value = current_trustee_id
bsw@1045 234 if preview_trustee_id then
bsw@1045 235 value = preview_trustee_id
bsw@1045 236 end
bsw@1045 237 if preview_trustee_id == nil and delegation and not delegation.trustee_id then
bsw@1045 238 value = 0
bsw@525 239 end
bsw@1045 240
bsw@1045 241 ui.heading{ level = 2, content = _"Choose your delegatee" }
bsw@1045 242
bsw@1045 243 ui.field.select{
bsw@1045 244 attr = { onchange = "updateDelegationInfo();" },
bsw@1045 245 name = "trustee_id",
bsw@1045 246 foreign_records = records,
bsw@1045 247 foreign_id = "id",
bsw@1045 248 foreign_name = "name",
bsw@1045 249 disabled_records = disabled_records,
bsw@1045 250 value = value
bsw@1045 251 }
bsw@1045 252
bsw@1045 253 ui.container{ content = _"You can choose only members which you have been saved as contact before." }
bsw@1045 254
bsw@1045 255 ui.field.hidden{ name = "preview" }
bsw@1045 256
bsw@1045 257 slot.put("<br />")
bsw@1045 258 ui.tag { tag = "input", content = "", attr = {
bsw@1045 259 type = "submit",
bsw@1045 260 value = _"Save",
bsw@1045 261 class = "btn btn-default",
bsw@1045 262 } }
bsw@1045 263
bsw@1045 264 slot.put("<br /><br /><br />")
bsw@1045 265 if initiative then
bsw@1045 266 ui.link{
bsw@1045 267 module = "initiative",
bsw@1045 268 view = "show",
bsw@1045 269 id = initiative.id,
bsw@1045 270 content = function()
bsw@1045 271 slot.put(_"Cancel")
bsw@1045 272 end,
bsw@1045 273 }
bsw@1045 274 elseif issue then
bsw@1045 275 ui.link{
bsw@1045 276 module = "issue",
bsw@1045 277 view = "show",
bsw@1045 278 id = issue.id,
bsw@1045 279 content = function()
bsw@1045 280 slot.put(_"Cancel")
bsw@1045 281 end,
bsw@1045 282 }
bsw@1045 283 elseif area then
bsw@1045 284 ui.link{
bsw@1045 285 module = "area",
bsw@1045 286 view = "show",
bsw@1045 287 id = area.id,
bsw@1045 288 content = function()
bsw@1045 289 slot.put(_"Cancel")
bsw@1045 290 end,
bsw@1045 291 }
bsw@525 292 else
bsw@1045 293 ui.link{
bsw@1045 294 module = "index",
bsw@1045 295 view = "index",
bsw@1045 296 content = function()
bsw@1045 297 slot.put(_"Cancel")
bsw@1045 298 end,
bsw@1045 299 }
bsw@525 300 end
bsw@525 301
bsw@525 302 end
bsw@1045 303 }
bsw@525 304
bsw@1045 305 end ) end )
bsw@1045 306 -- ------------------------
bsw@525 307
bsw@1045 308 ui.sidebar( "tab-members", function ()
bsw@525 309
bsw@1045 310 ui.sidebarHead( function ()
bsw@1045 311 ui.heading { level = 1, content = _"Preview of delegation" }
bsw@1045 312 end )
bsw@525 313
bsw@583 314 local preview_inherit = false
bsw@583 315 local tmp_preview_trustee_id = preview_trustee_id
bsw@583 316 if preview_trustee_id == -1 then
bsw@583 317 preview_inherit = true
bsw@583 318 tmp_preview_trustee_id = nil
bsw@583 319 end
bsw@575 320 local delegation_chain = Member:new_selector()
bsw@575 321 :add_field("delegation_chain.*")
bsw@583 322 :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 323 :add_order_by("index")
bsw@575 324 :exec()
bsw@525 325
bsw@575 326 for i, record in ipairs(delegation_chain) do
bsw@575 327 local style
bsw@575 328 local overridden = (not issue or issue.state ~= 'voting') and record.overridden
bsw@1045 329 ui.sidebarSection( function ()
bsw@1045 330 if record.scope_in then
bsw@1045 331 if not overridden then
bsw@1045 332 local text = _"delegated to"
bsw@1045 333 ui.image{
bsw@1045 334 attr = { class = "delegation_arrow", alt = text, title = text },
bsw@1045 335 static = "delegation_arrow_24_vertical.png"
bsw@1045 336 }
bsw@1045 337 else
bsw@1045 338 local text = _"delegated to"
bsw@1045 339 ui.image{
bsw@1045 340 attr = { class = "delegation_arrow delegation_arrow_overridden", alt = text, title = text },
bsw@1045 341 static = "delegation_arrow_24_vertical.png"
bsw@1045 342 }
bsw@1045 343 end
bsw@1045 344 ui.tag{
bsw@1045 345 attr = { class = "delegation_scope" .. (overridden and " delegation_scope_overridden" or "") },
bsw@1045 346 content = function()
bsw@1045 347 if record.scope_in == "unit" then
bsw@1045 348 slot.put(config.single_object_mode and _"Global delegation" or _"Unit delegation")
bsw@1045 349 elseif record.scope_in == "area" then
bsw@1045 350 slot.put(_"Area delegation")
bsw@1045 351 elseif record.scope_in == "issue" then
bsw@1045 352 slot.put(_"Issue delegation")
bsw@1045 353 end
bsw@1045 354 end
bsw@575 355 }
bsw@575 356 end
bsw@1045 357 ui.container{
bsw@1045 358 attr = { class = overridden and "delegation_overridden" or "" },
bsw@575 359 content = function()
bsw@1045 360 execute.view{
bsw@1045 361 module = "member",
bsw@1045 362 view = "_show_thumb",
bsw@1045 363 params = { member = record }
bsw@1045 364 }
bsw@575 365 end
bsw@575 366 }
bsw@1045 367 if issue and issue.state ~= 'voting' and record.participation and not record.overridden then
bsw@1045 368 ui.container{
bsw@1045 369 attr = { class = "delegation_participation" },
bsw@1045 370 content = function()
bsw@1045 371 if i == #delegation_chain then
bsw@1045 372 ui.tag{ content = _"This member is currently participating in this issue." }
bsw@1045 373 else
bsw@1045 374 ui.tag{ content = _"This member is participating, the remaining delegation chain is suspended during discussing." }
bsw@1045 375 end
bsw@1045 376 end
bsw@575 377 }
bsw@575 378 end
bsw@1045 379 slot.put("<br style='clear: left'/>")
bsw@1045 380 end )
bsw@525 381 end
bsw@525 382
bsw@577 383 if preview_trustee_id == 0 or not preview_trustee_id == null and delegation and not delegation.trustee_id then
bsw@575 384 ui.image{
bsw@575 385 static = "icons/16/table_go_crossed.png"
bsw@575 386 }
bsw@577 387 if issue_id then
bsw@575 388 slot.put(_"Delegation turned off for issue")
bsw@577 389 elseif area_id then
bsw@575 390 slot.put(_"Delegation turned off for area")
bsw@525 391 end
bsw@525 392 end
bsw@525 393
bsw@1045 394
bsw@1045 395 end )

Impressum / About Us