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@563: ui.title(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@563: if area.delegation_info.own_delegation_scope == 'area' then bsw@563: current_trustee_id = area.delegation_info.first_trustee_id bsw@563: current_trustee_name = area.delegation_info.first_trustee_name bsw@563: end bsw@563: ui.title(_"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@551: issue:load("member_info", { member_id = app.session.member_id }) bsw@525: voting_right_unit_id = issue.area.unit_id bsw@563: if issue.member_info.own_delegation_scope == 'issue' then bsw@563: current_trustee_id = issue.member_info.first_trustee_id bsw@563: current_trustee_name = issue.member_info.first_trustee_name bsw@563: end bsw@563: ui.title(_"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@575: bsw@575: local delegation bsw@575: local unit_id bsw@575: local area_id bsw@575: local issue_id bsw@575: local initiative_id bsw@575: local initiative bsw@575: bsw@575: local scope = "unit" bsw@575: bsw@575: unit_id = param.get("unit_id", atom.integer) bsw@575: bsw@575: local inline = param.get("inline", atom.boolean) bsw@575: bsw@575: if param.get("initiative_id", atom.integer) then bsw@575: initiative_id = param.get("initiative_id", atom.integer) bsw@575: initiative = Initiative:by_id(initiative_id) bsw@575: issue_id = initiative.issue_id bsw@575: scope = "issue" bsw@575: end bsw@575: bsw@575: if param.get("issue_id", atom.integer) then bsw@575: issue_id = param.get("issue_id", atom.integer) bsw@575: scope = "issue" bsw@575: end bsw@575: bsw@575: if param.get("area_id", atom.integer) then bsw@575: area_id = param.get("area_id", atom.integer) bsw@575: scope = "area" bsw@575: end bsw@575: bsw@575: bsw@575: bsw@575: local delegation bsw@575: local issue bsw@575: bsw@575: if issue_id then bsw@575: issue = Issue:by_id(issue_id) bsw@575: delegation = Delegation:by_pk(app.session.member.id, nil, nil, issue_id) bsw@575: if not delegation then bsw@575: delegation = Delegation:by_pk(app.session.member.id, nil, issue.area_id) bsw@575: end bsw@575: if not delegation then bsw@575: delegation = Delegation:by_pk(app.session.member.id, issue.area.unit_id) bsw@575: end bsw@575: elseif area_id then bsw@575: delegation = Delegation:by_pk(app.session.member.id, nil, area_id) bsw@575: if not delegation then bsw@575: local area = Area:by_id(area_id) bsw@575: delegation = Delegation:by_pk(app.session.member.id, area.unit_id) bsw@575: end bsw@575: end bsw@575: bsw@575: if not delegation then bsw@575: delegation = Delegation:by_pk(app.session.member.id, unit_id) bsw@575: end 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@575: initiative_id = initiative_id 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@575: 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@574: -- add current trustee 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@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@574: -- add saved members bsw@575: if #contact_members > 0 then bsw@575: records[#records+1] = {id="_", name= "--- " .. _"Saved contacts" .. " ---"} bsw@575: for i, record in ipairs(contact_members) do bsw@575: records[#records+1] = record bsw@575: end bsw@574: end bsw@525: bsw@525: disabled_records = {} bsw@525: disabled_records["_"] = true bsw@525: disabled_records[app.session.member_id] = true bsw@525: bsw@575: local value = current_trustee_id bsw@575: if preview_trustee_id then bsw@575: value = preview_trustee_id bsw@575: end bsw@575: if preview_trustee_id == nil and delegation and not delegation.trustee_id then bsw@575: value = 0 bsw@575: end bsw@575: 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@575: value = value 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@583: local preview_inherit = false bsw@583: local tmp_preview_trustee_id = preview_trustee_id bsw@583: if preview_trustee_id == -1 then bsw@583: preview_inherit = true bsw@583: tmp_preview_trustee_id = nil bsw@583: end bsw@575: local delegation_chain = Member:new_selector() bsw@575: :add_field("delegation_chain.*") bsw@583: :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: :add_order_by("index") bsw@575: :exec() bsw@525: bsw@575: for i, record in ipairs(delegation_chain) do bsw@575: local style bsw@575: local overridden = (not issue or issue.state ~= 'voting') and record.overridden bsw@575: if record.scope_in then bsw@575: if not overridden then bsw@575: ui.image{ bsw@575: attr = { class = "delegation_arrow" }, bsw@575: static = "delegation_arrow_24_vertical.png" bsw@575: } bsw@575: else bsw@575: ui.image{ bsw@575: attr = { class = "delegation_arrow delegation_arrow_overridden" }, bsw@575: static = "delegation_arrow_24_vertical.png" bsw@575: } bsw@575: end bsw@575: ui.tag{ bsw@575: attr = { class = "delegation_scope" .. (overridden and " delegation_scope_overridden" or "") }, bsw@575: content = function() bsw@575: if record.scope_in == "unit" then bsw@575: slot.put(config.single_object_mode and _"Global delegation" or _"Unit delegation") bsw@575: elseif record.scope_in == "area" then bsw@575: slot.put(_"Area delegation") bsw@575: elseif record.scope_in == "issue" then bsw@575: slot.put(_"Issue delegation") bsw@575: end bsw@575: end bsw@575: } bsw@575: end bsw@575: ui.container{ bsw@575: attr = { class = overridden and "delegation_overridden" or "" }, bsw@575: content = function() bsw@575: execute.view{ bsw@575: module = "member", bsw@575: view = "_show_thumb", bsw@575: params = { member = record } bsw@575: } bsw@575: end bsw@575: } bsw@575: if (not issue or issue.state ~= 'voting') and record.participation and not record.overridden then bsw@575: ui.container{ bsw@575: attr = { class = "delegation_participation" }, bsw@575: content = function() bsw@575: slot.put(_"This member is participating, the rest of delegation chain is suspended while discussing") bsw@575: end bsw@575: } bsw@575: end bsw@575: slot.put("
") bsw@525: end bsw@525: bsw@577: if preview_trustee_id == 0 or not preview_trustee_id == null and delegation and not delegation.trustee_id then bsw@575: ui.image{ bsw@575: static = "icons/16/table_go_crossed.png" bsw@575: } bsw@577: if issue_id then bsw@575: slot.put(_"Delegation turned off for issue") bsw@577: elseif area_id then bsw@575: slot.put(_"Delegation turned off for area") bsw@525: end bsw@525: end bsw@525: