bsw@525: local voting_right_unit_id bsw@529: local current_trustee_id bsw@529: local current_trustee_name bsw@525: bsw@525: local unit = Unit:by_id(param.get("unit_id", atom.integer)) bsw@525: if unit then bsw@529: unit:load_delegation_info_once_for_member_id(app.session.member_id) bsw@525: voting_right_unit_id = unit.id bsw@529: if unit.delegation_info.own_delegation_scope == 'unit' then bsw@529: current_trustee_id = unit.delegation_info.first_trustee_id bsw@529: current_trustee_name = unit.delegation_info.first_trustee_name bsw@529: end bsw@525: slot.put_into("title", encode.html(config.single_unit_id and _"Set global delegation" or _"Set unit delegation")) bsw@525: util.help("delegation.new.unit") bsw@525: end bsw@525: bsw@525: local area = Area:by_id(param.get("area_id", atom.integer)) bsw@525: if area then bsw@529: area:load_delegation_info_once_for_member_id(app.session.member_id) bsw@525: voting_right_unit_id = area.unit_id bsw@525: slot.put_into("title", encode.html(_"Set delegation for Area '#{name}'":gsub("#{name}", area.name))) bsw@525: util.help("delegation.new.area") bsw@525: end bsw@525: bsw@525: local issue = Issue:by_id(param.get("issue_id", atom.integer)) bsw@525: if issue then bsw@529: issue:load_delegation_info_once_for_member_id(app.session.member_id) bsw@525: voting_right_unit_id = issue.area.unit_id bsw@525: 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))) bsw@525: util.help("delegation.new.issue") bsw@525: end bsw@525: bsw@525: local initiative = Initiative:by_id(param.get("initiative_id", atom.integer)) bsw@525: bsw@529: local contact_members = Member:build_selector{ bsw@529: is_contact_of_member_id = app.session.member_id, bsw@529: voting_right_for_unit_id = voting_right_unit_id, bsw@529: active = true, bsw@529: order = "name" bsw@529: }:exec() bsw@529: bsw@529: local preview_trustee_id = param.get("preview_trustee_id", atom.integer) bsw@529: bsw@529: ui.script{ static = "js/update_delegation_info.js" } bsw@529: bsw@525: slot.select("actions", function() bsw@525: if issue then bsw@525: ui.link{ bsw@525: module = "issue", bsw@525: view = "show", bsw@525: id = issue.id, bsw@525: content = function() bsw@525: ui.image{ static = "icons/16/cancel.png" } bsw@525: slot.put(_"Cancel") bsw@525: end, bsw@525: } bsw@525: elseif area then bsw@525: ui.link{ bsw@525: module = "area", bsw@525: view = "show", bsw@525: id = area.id, bsw@525: content = function() bsw@525: ui.image{ static = "icons/16/cancel.png" } bsw@525: slot.put(_"Cancel") bsw@525: end, bsw@525: } bsw@525: else bsw@525: ui.link{ bsw@525: module = "index", bsw@525: view = "index", bsw@525: content = function() bsw@525: ui.image{ static = "icons/16/cancel.png" } bsw@525: slot.put(_"Cancel") bsw@525: end, bsw@525: } bsw@525: end bsw@525: end) bsw@525: bsw@525: bsw@525: ui.form{ bsw@529: attr = { class = "vertical", id = "delegationForm" }, bsw@525: module = "delegation", bsw@525: action = "update", bsw@525: params = { bsw@525: unit_id = unit and unit.id or nil, bsw@525: area_id = area and area.id or nil, bsw@525: issue_id = issue and issue.id or nil, bsw@525: }, bsw@525: routing = { bsw@525: default = { bsw@525: mode = "redirect", bsw@525: module = area and "area" or initiative and "initiative" or issue and "issue" or "unit", bsw@525: view = "show", bsw@525: id = area and area.id or initiative and initiative.id or issue and issue.id or unit.id bsw@525: } bsw@525: }, bsw@525: content = function() bsw@525: local records bsw@525: bsw@525: if issue then bsw@525: local delegate_name = "" bsw@525: local scope = "no delegation set" bsw@525: local area_delegation = Delegation:by_pk(app.session.member_id, nil, issue.area_id) bsw@525: if area_delegation then bsw@525: delegate_name = area_delegation.trustee and area_delegation.trustee.name or _"abandoned" bsw@525: scope = _"area" bsw@525: else bsw@525: local unit_delegation = Delegation:by_pk(app.session.member_id, issue.area.unit_id) bsw@525: if unit_delegation then bsw@525: delegate_name = unit_delegation.trustee.name bsw@525: scope = config.single_unit_id and _"global" or _"unit" bsw@525: end bsw@525: end bsw@525: local text_apply bsw@525: local text_abandon bsw@525: if config.single_unit_id then bsw@525: text_apply = _("Apply global or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope }) bsw@525: text_abandon = _"Abandon unit and area delegations for this issue" bsw@525: else bsw@525: text_apply = _("Apply unit or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope }) bsw@525: text_abandon = _"Abandon unit and area delegations for this issue" bsw@525: end bsw@525: records = { bsw@525: { id = -1, name = text_apply }, bsw@525: { id = 0, name = text_abandon } bsw@525: } bsw@525: elseif area then bsw@525: local delegate_name = "" bsw@525: local scope = "no delegation set" bsw@525: local unit_delegation = Delegation:by_pk(app.session.member_id, area.unit_id) bsw@525: if unit_delegation then bsw@525: delegate_name = unit_delegation.trustee.name bsw@525: scope = config.single_unit_id and _"global" or _"unit" bsw@525: end bsw@525: local text_apply bsw@525: local text_abandon bsw@525: if config.single_unit_id then bsw@525: text_apply = _("Apply global delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope }) bsw@525: text_abandon = _"Abandon global delegation for this area" bsw@525: else bsw@525: text_apply = _("Apply unit delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope }) bsw@525: text_abandon = _"Abandon unit delegation for this area" bsw@525: end bsw@525: records = { bsw@525: { bsw@525: id = -1, bsw@525: name = text_apply bsw@525: }, bsw@525: { bsw@525: id = 0, bsw@525: name = text_abandon bsw@525: } bsw@525: } bsw@525: bsw@525: else bsw@525: records = { bsw@525: { bsw@525: id = -1, bsw@525: name = _"No delegation" bsw@525: } bsw@525: } bsw@525: bsw@525: end bsw@525: -- add saved members bsw@529: if current_trustee_id then bsw@529: records[#records+1] = {id="_", name= "--- " .. _"Current trustee" .. " ---"} bsw@529: records[#records+1] = { id = current_trustee_id, name = current_trustee_name } bsw@529: end bsw@529: -- add saved members bsw@525: records[#records+1] = {id="_", name= "--- " .. _"Saved contacts" .. " ---"} bsw@525: for i, record in ipairs(contact_members) do bsw@525: records[#records+1] = record bsw@525: end bsw@525: -- add initiative authors bsw@525: if initiative then bsw@525: records[#records+1] = {id="_", name= "--- " .. _"Initiators" .. " ---"} bsw@525: for i,record in ipairs(initiative.initiators) do bsw@525: records[#records+1] = record.member bsw@525: end bsw@525: end bsw@525: bsw@525: disabled_records = {} bsw@525: disabled_records["_"] = true bsw@525: disabled_records[app.session.member_id] = true bsw@525: bsw@525: ui.field.select{ bsw@529: attr = { onchange = "updateDelegationInfo();" }, bsw@525: label = _"Trustee", bsw@525: name = "trustee_id", bsw@525: foreign_records = records, bsw@525: foreign_id = "id", bsw@525: foreign_name = "name", bsw@529: disabled_records = disabled_records, bsw@529: value = preview_trustee_id or current_trustee_id bsw@525: } bsw@525: bsw@529: ui.field.hidden{ name = "preview" } bsw@529: bsw@525: ui.submit{ text = _"Save" } bsw@529: bsw@525: end bsw@525: } bsw@525: bsw@525: bsw@525: bsw@525: -- ------------------------ bsw@525: bsw@525: bsw@525: bsw@525: bsw@525: local delegation bsw@525: local unit_id bsw@525: local area_id bsw@525: local issue_id bsw@525: local initiative_id bsw@525: bsw@525: local scope = "unit" bsw@525: bsw@525: unit_id = param.get("unit_id", atom.integer) bsw@525: bsw@525: local inline = param.get("inline", atom.boolean) bsw@525: bsw@525: if param.get("initiative_id", atom.integer) then bsw@525: initiative_id = param.get("initiative_id", atom.integer) bsw@525: issue_id = Initiative:by_id(initiative_id).issue_id bsw@525: scope = "issue" bsw@525: end bsw@525: bsw@525: if param.get("issue_id", atom.integer) then bsw@525: issue_id = param.get("issue_id", atom.integer) bsw@525: scope = "issue" bsw@525: end bsw@525: bsw@525: if param.get("area_id", atom.integer) then bsw@525: area_id = param.get("area_id", atom.integer) bsw@525: scope = "area" bsw@525: end bsw@525: bsw@525: bsw@525: bsw@525: local delegation bsw@525: local issue bsw@525: bsw@525: if issue_id then bsw@525: issue = Issue:by_id(issue_id) bsw@525: delegation = Delegation:by_pk(app.session.member.id, nil, nil, issue_id) bsw@525: if not delegation then bsw@525: delegation = Delegation:by_pk(app.session.member.id, nil, issue.area_id) bsw@525: end bsw@525: if not delegation then bsw@525: delegation = Delegation:by_pk(app.session.member.id, issue.area.unit_id) bsw@525: end bsw@525: elseif area_id then bsw@525: delegation = Delegation:by_pk(app.session.member.id, nil, area_id) bsw@525: if not delegation then bsw@525: local area = Area:by_id(area_id) bsw@525: delegation = Delegation:by_pk(app.session.member.id, area.unit_id) bsw@525: end bsw@525: end bsw@525: bsw@525: if not delegation then bsw@525: delegation = Delegation:by_pk(app.session.member.id, unit_id) bsw@525: end bsw@525: bsw@525: local slot_name = "actions" bsw@525: bsw@525: if inline then bsw@525: slot_name = "default" bsw@525: end bsw@525: bsw@529: if delegation and not delegation.trustee_id then bsw@525: ui.image{ bsw@525: static = "icons/16/table_go_crossed.png" bsw@525: } bsw@525: if delegation.issue_id then bsw@525: slot.put(_"Delegation turned off for issue") bsw@525: elseif delegation.area_id then bsw@525: slot.put(_"Delegation turned off for area") bsw@525: end bsw@525: end bsw@525: bsw@525: local delegation_chain = Member:new_selector() bsw@525: :add_field("delegation_chain.*") bsw@529: :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: :add_order_by("index") bsw@525: :exec() bsw@525: bsw@525: for i, record in ipairs(delegation_chain) do bsw@525: local style bsw@525: local overridden = (not issue or issue.state ~= 'voting') and record.overridden bsw@525: if record.scope_in then bsw@525: if not overridden then bsw@525: ui.image{ bsw@525: attr = { class = "delegation_arrow" }, bsw@525: static = "delegation_arrow_24_vertical.png" bsw@525: } bsw@525: else bsw@525: ui.image{ bsw@525: attr = { class = "delegation_arrow delegation_arrow_overridden" }, bsw@525: static = "delegation_arrow_24_vertical.png" bsw@525: } bsw@525: end bsw@525: ui.tag{ bsw@525: attr = { class = "delegation_scope" .. (overridden and " delegation_scope_overridden" or "") }, bsw@525: content = function() bsw@525: if record.scope_in == "unit" then bsw@525: slot.put(config.single_object_mode and _"Global delegation" or _"Unit delegation") bsw@525: elseif record.scope_in == "area" then bsw@525: slot.put(_"Area delegation") bsw@525: elseif record.scope_in == "issue" then bsw@525: slot.put(_"Issue delegation") bsw@525: end bsw@525: end bsw@525: } bsw@525: end bsw@525: ui.container{ bsw@525: attr = { class = overridden and "delegation_overridden" or "" }, bsw@525: content = function() bsw@525: execute.view{ bsw@525: module = "member", bsw@525: view = "_show_thumb", bsw@525: params = { member = record } bsw@525: } bsw@525: end bsw@525: } bsw@525: if (not issue or issue.state ~= 'voting') and record.participation and not record.overridden then bsw@525: ui.container{ bsw@525: attr = { class = "delegation_participation" }, bsw@525: content = function() bsw@525: slot.put(_"This member is participating, the rest of delegation chain is suspended while discussing") bsw@525: end bsw@525: } bsw@525: end bsw@525: slot.put("
") bsw@525: end