liquid_feedback_frontend
diff app/main/lf2/delegation.lua @ 212:3e4ad069847a
Some more work at 2nd generation frontend code
author | bsw |
---|---|
date | Thu Mar 03 18:39:00 2011 +0100 (2011-03-03) |
parents | |
children | acf92c2d33f4 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/app/main/lf2/delegation.lua Thu Mar 03 18:39:00 2011 +0100 1.3 @@ -0,0 +1,134 @@ 1.4 +slot.set_layout("lf2") 1.5 + 1.6 +local area = Area:by_id(param.get("area_id", atom.integer)) 1.7 +local issue = Issue:by_id(param.get("issue_id", atom.integer)) 1.8 +local initiative = Initiative:by_id(param.get("initiative_id", atom.integer)) 1.9 + 1.10 +local contact_members = Member:build_selector{ 1.11 + is_contact_of_member_id = app.session.member_id, 1.12 + order = "name" 1.13 +}:exec() 1.14 + 1.15 +if area then 1.16 + title = _"Set delegation for Area '#{name}'":gsub("#{name}", area.name) 1.17 +end 1.18 + 1.19 +if issue then 1.20 + title = _"Set delegation for Issue ##{number} in Area '#{area_name}'":gsub("#{number}", issue.id):gsub("#{area_name}", issue.area.name) 1.21 +end 1.22 + 1.23 +if not area and not issue then 1.24 + title = _"Set unit delegation" 1.25 +end 1.26 + 1.27 +ui.box{ content = function() 1.28 + 1.29 + ui.box_row{ class = "head", content = function() ui.box_col{ class = "head", content = title } end } 1.30 + 1.31 + ui.form{ 1.32 + attr = { class = "vertical" }, 1.33 + module = "delegation", 1.34 + action = "update", 1.35 + params = { 1.36 + area_id = area and area.id or nil, 1.37 + issue_id = issue and issue.id or nil, 1.38 + }, 1.39 + routing = { 1.40 + default = { 1.41 + mode = "redirect", 1.42 + module = "lf2", 1.43 + view = area and "area" or issue and "issue" or "index", 1.44 + id = area and area.id or issue and issue.id or nil, 1.45 + } 1.46 + }, 1.47 + content = function() 1.48 + local records 1.49 + 1.50 + if issue then 1.51 + local delegate_name = "" 1.52 + local scope = "no delegation set" 1.53 + local area_delegation = Delegation:by_pk(app.session.member_id, issue.area_id) 1.54 + if area_delegation then 1.55 + delegate_name = area_delegation.trustee and area_delegation.trustee.name or _"abandoned" 1.56 + scope = _"area" 1.57 + else 1.58 + local unit_delegation = Delegation:by_pk(app.session.member_id) 1.59 + if unit_delegation then 1.60 + delegate_name = unit_delegation.trustee.name 1.61 + scope = _"unit" 1.62 + end 1.63 + end 1.64 + records = { 1.65 + { 1.66 + id = -1, 1.67 + name = _("Apply unit or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope }) 1.68 + }, 1.69 + { 1.70 + id = 0, 1.71 + name = _"Abandon unit and area delegations for this issue" 1.72 + }, 1.73 + 1.74 + } 1.75 + elseif area then 1.76 + local delegate_name = "" 1.77 + local scope = "no delegation set" 1.78 + local unit_delegation = Delegation:by_pk(app.session.member_id) 1.79 + if unit_delegation then 1.80 + delegate_name = unit_delegation.trustee.name 1.81 + scope = _"unit" 1.82 + end 1.83 + records = { 1.84 + { 1.85 + id = -1, 1.86 + name = _("Apply unit delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope }) 1.87 + }, 1.88 + { 1.89 + id = 0, 1.90 + name = _"Abandon unit delegation for this area" 1.91 + } 1.92 + } 1.93 + 1.94 + else 1.95 + records = { 1.96 + { 1.97 + id = -1, 1.98 + name = _"No delegation" 1.99 + } 1.100 + } 1.101 + 1.102 + end 1.103 + -- add saved members 1.104 + records[#records+1] = {id="_", name= "--- " .. _"Saved contacts" .. " ---"} 1.105 + for i, record in ipairs(contact_members) do 1.106 + records[#records+1] = record 1.107 + end 1.108 + -- add initiative authors 1.109 + if initiative then 1.110 + records[#records+1] = {id="_", name= "--- " .. _"Initiators" .. " ---"} 1.111 + for i,record in ipairs(initiative.initiators) do 1.112 + records[#records+1] = record.member 1.113 + end 1.114 + end 1.115 + 1.116 + disabled_records = {} 1.117 + disabled_records["_"] = true 1.118 + 1.119 + 1.120 + ui.box_row{ content = function() ui.box_col{ content = function() 1.121 + ui.field.select{ 1.122 + label = _"Trustee", 1.123 + name = "trustee_id", 1.124 + foreign_records = records, 1.125 + foreign_id = "id", 1.126 + foreign_name = "name", 1.127 + disabled_records = disabled_records 1.128 + } 1.129 + end } end } 1.130 + 1.131 + ui.box_row{ content = function() ui.box_col{ content = function() 1.132 + ui.submit{ text = _"Save" } 1.133 + end } end } 1.134 + end 1.135 + } 1.136 + 1.137 +end } 1.138 \ No newline at end of file