liquid_feedback_frontend

view 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 source
1 slot.set_layout("lf2")
3 local area = Area:by_id(param.get("area_id", atom.integer))
4 local issue = Issue:by_id(param.get("issue_id", atom.integer))
5 local initiative = Initiative:by_id(param.get("initiative_id", atom.integer))
7 local contact_members = Member:build_selector{
8 is_contact_of_member_id = app.session.member_id,
9 order = "name"
10 }:exec()
12 if area then
13 title = _"Set delegation for Area '#{name}'":gsub("#{name}", area.name)
14 end
16 if issue then
17 title = _"Set delegation for Issue ##{number} in Area '#{area_name}'":gsub("#{number}", issue.id):gsub("#{area_name}", issue.area.name)
18 end
20 if not area and not issue then
21 title = _"Set unit delegation"
22 end
24 ui.box{ content = function()
26 ui.box_row{ class = "head", content = function() ui.box_col{ class = "head", content = title } end }
28 ui.form{
29 attr = { class = "vertical" },
30 module = "delegation",
31 action = "update",
32 params = {
33 area_id = area and area.id or nil,
34 issue_id = issue and issue.id or nil,
35 },
36 routing = {
37 default = {
38 mode = "redirect",
39 module = "lf2",
40 view = area and "area" or issue and "issue" or "index",
41 id = area and area.id or issue and issue.id or nil,
42 }
43 },
44 content = function()
45 local records
47 if issue then
48 local delegate_name = ""
49 local scope = "no delegation set"
50 local area_delegation = Delegation:by_pk(app.session.member_id, issue.area_id)
51 if area_delegation then
52 delegate_name = area_delegation.trustee and area_delegation.trustee.name or _"abandoned"
53 scope = _"area"
54 else
55 local unit_delegation = Delegation:by_pk(app.session.member_id)
56 if unit_delegation then
57 delegate_name = unit_delegation.trustee.name
58 scope = _"unit"
59 end
60 end
61 records = {
62 {
63 id = -1,
64 name = _("Apply unit or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
65 },
66 {
67 id = 0,
68 name = _"Abandon unit and area delegations for this issue"
69 },
71 }
72 elseif area then
73 local delegate_name = ""
74 local scope = "no delegation set"
75 local unit_delegation = Delegation:by_pk(app.session.member_id)
76 if unit_delegation then
77 delegate_name = unit_delegation.trustee.name
78 scope = _"unit"
79 end
80 records = {
81 {
82 id = -1,
83 name = _("Apply unit delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
84 },
85 {
86 id = 0,
87 name = _"Abandon unit delegation for this area"
88 }
89 }
91 else
92 records = {
93 {
94 id = -1,
95 name = _"No delegation"
96 }
97 }
99 end
100 -- add saved members
101 records[#records+1] = {id="_", name= "--- " .. _"Saved contacts" .. " ---"}
102 for i, record in ipairs(contact_members) do
103 records[#records+1] = record
104 end
105 -- add initiative authors
106 if initiative then
107 records[#records+1] = {id="_", name= "--- " .. _"Initiators" .. " ---"}
108 for i,record in ipairs(initiative.initiators) do
109 records[#records+1] = record.member
110 end
111 end
113 disabled_records = {}
114 disabled_records["_"] = true
117 ui.box_row{ content = function() ui.box_col{ content = function()
118 ui.field.select{
119 label = _"Trustee",
120 name = "trustee_id",
121 foreign_records = records,
122 foreign_id = "id",
123 foreign_name = "name",
124 disabled_records = disabled_records
125 }
126 end } end }
128 ui.box_row{ content = function() ui.box_col{ content = function()
129 ui.submit{ text = _"Save" }
130 end } end }
131 end
132 }
134 end }

Impressum / About Us