bsw@212: slot.set_layout("lf2") bsw@212: bsw@212: local area = Area:by_id(param.get("area_id", atom.integer)) bsw@212: local issue = Issue:by_id(param.get("issue_id", atom.integer)) bsw@212: local initiative = Initiative:by_id(param.get("initiative_id", atom.integer)) bsw@212: bsw@212: local contact_members = Member:build_selector{ bsw@212: is_contact_of_member_id = app.session.member_id, bsw@212: order = "name" bsw@212: }:exec() bsw@212: bsw@212: if area then bsw@212: title = _"Set delegation for Area '#{name}'":gsub("#{name}", area.name) bsw@212: end bsw@212: bsw@212: if issue then bsw@212: title = _"Set delegation for Issue ##{number} in Area '#{area_name}'":gsub("#{number}", issue.id):gsub("#{area_name}", issue.area.name) bsw@212: end bsw@212: bsw@212: if not area and not issue then bsw@212: title = _"Set unit delegation" bsw@212: end bsw@212: bsw@212: ui.box{ content = function() bsw@212: bsw@212: ui.box_row{ class = "head", content = function() ui.box_col{ class = "head", content = title } end } bsw@212: bsw@212: ui.form{ bsw@212: attr = { class = "vertical" }, bsw@212: module = "delegation", bsw@212: action = "update", bsw@212: params = { bsw@212: area_id = area and area.id or nil, bsw@212: issue_id = issue and issue.id or nil, bsw@212: }, bsw@212: routing = { bsw@212: default = { bsw@212: mode = "redirect", bsw@212: module = "lf2", bsw@213: view = area and "area" or initiative and "initiative" or issue and "issue" or "index", bsw@213: id = area and area.id or initiative and initiative.id or issue and issue.id or nil, bsw@212: } bsw@212: }, bsw@212: content = function() bsw@212: local records bsw@212: bsw@212: if issue then bsw@212: local delegate_name = "" bsw@212: local scope = "no delegation set" bsw@212: local area_delegation = Delegation:by_pk(app.session.member_id, issue.area_id) bsw@212: if area_delegation then bsw@212: delegate_name = area_delegation.trustee and area_delegation.trustee.name or _"abandoned" bsw@212: scope = _"area" bsw@212: else bsw@212: local unit_delegation = Delegation:by_pk(app.session.member_id) bsw@212: if unit_delegation then bsw@212: delegate_name = unit_delegation.trustee.name bsw@212: scope = _"unit" bsw@212: end bsw@212: end bsw@212: records = { bsw@212: { bsw@212: id = -1, bsw@212: name = _("Apply unit or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope }) bsw@212: }, bsw@212: { bsw@212: id = 0, bsw@212: name = _"Abandon unit and area delegations for this issue" bsw@212: }, bsw@212: bsw@212: } bsw@212: elseif area then bsw@212: local delegate_name = "" bsw@212: local scope = "no delegation set" bsw@212: local unit_delegation = Delegation:by_pk(app.session.member_id) bsw@212: if unit_delegation then bsw@212: delegate_name = unit_delegation.trustee.name bsw@212: scope = _"unit" bsw@212: end bsw@212: records = { bsw@212: { bsw@212: id = -1, bsw@212: name = _("Apply unit delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope }) bsw@212: }, bsw@212: { bsw@212: id = 0, bsw@212: name = _"Abandon unit delegation for this area" bsw@212: } bsw@212: } bsw@212: bsw@212: else bsw@212: records = { bsw@212: { bsw@212: id = -1, bsw@212: name = _"No delegation" bsw@212: } bsw@212: } bsw@212: bsw@212: end bsw@214: disabled_records = {} bsw@214: disabled_records["_"] = true bsw@214: bsw@212: -- add saved members bsw@212: records[#records+1] = {id="_", name= "--- " .. _"Saved contacts" .. " ---"} bsw@212: for i, record in ipairs(contact_members) do bsw@212: records[#records+1] = record bsw@212: end bsw@214: bsw@212: -- add initiative authors bsw@212: if initiative then bsw@212: records[#records+1] = {id="_", name= "--- " .. _"Initiators" .. " ---"} bsw@212: for i,record in ipairs(initiative.initiators) do bsw@212: records[#records+1] = record.member bsw@214: if record.member.id == app.session.member_id then bsw@214: disabled_records[record.member.id] = true bsw@214: end bsw@212: end bsw@212: end bsw@212: bsw@212: bsw@212: bsw@212: ui.box_row{ content = function() ui.box_col{ content = function() bsw@212: ui.field.select{ bsw@212: label = _"Trustee", bsw@212: name = "trustee_id", bsw@212: foreign_records = records, bsw@212: foreign_id = "id", bsw@212: foreign_name = "name", bsw@212: disabled_records = disabled_records bsw@212: } bsw@212: end } end } bsw@212: bsw@215: ui.box_row{ content = function() bsw@215: ui.box_col{ content = _"Please note: Member, interest and supporter counts are calculated periodically, therefore it can take some time until your changes become effective everywhere." } bsw@215: end } bsw@212: ui.box_row{ content = function() ui.box_col{ content = function() bsw@212: ui.submit{ text = _"Save" } bsw@212: end } end } bsw@212: end bsw@212: } bsw@212: bsw@212: end }