liquid_feedback_frontend
view app/main/delegation/new.lua @ 258:878526479494
Removed old test scripts
author | bsw |
---|---|
date | Tue Feb 07 17:25:03 2012 +0100 (2012-02-07) |
parents | e3613831cd1e |
children | 1b8d51e21614 |
line source
1 local unit = Unit:by_id(param.get("unit_id", atom.integer))
2 if unit then
3 slot.put_into("title", encode.html(_"Set unit delegation"))
4 util.help("delegation.new.unit")
5 end
7 local area = Area:by_id(param.get("area_id", atom.integer))
8 if area then
9 slot.put_into("title", encode.html(_"Set delegation for Area '#{name}'":gsub("#{name}", area.name)))
10 util.help("delegation.new.area")
11 end
13 local issue = Issue:by_id(param.get("issue_id", atom.integer))
14 if issue then
15 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)))
16 util.help("delegation.new.issue")
17 end
19 local initiative = Initiative:by_id(param.get("initiative_id", atom.integer))
21 slot.select("actions", function()
22 if issue then
23 ui.link{
24 module = "issue",
25 view = "show",
26 id = issue.id,
27 content = function()
28 ui.image{ static = "icons/16/cancel.png" }
29 slot.put(_"Cancel")
30 end,
31 }
32 elseif area then
33 ui.link{
34 module = "area",
35 view = "show",
36 id = area.id,
37 content = function()
38 ui.image{ static = "icons/16/cancel.png" }
39 slot.put(_"Cancel")
40 end,
41 }
42 else
43 ui.link{
44 module = "index",
45 view = "index",
46 content = function()
47 ui.image{ static = "icons/16/cancel.png" }
48 slot.put(_"Cancel")
49 end,
50 }
51 end
52 end)
55 local contact_members = Member:build_selector{
56 is_contact_of_member_id = app.session.member_id,
57 order = "name"
58 }:exec()
60 ui.form{
61 attr = { class = "vertical" },
62 module = "delegation",
63 action = "update",
64 params = {
65 unit_id = unit and unit.id or nil,
66 area_id = area and area.id or nil,
67 issue_id = issue and issue.id or nil,
68 },
69 routing = {
70 default = {
71 mode = "redirect",
72 module = area and "area" or issue and "issue" or "index",
73 view = (area or issue) and "show" or "index",
74 id = area and area.id or issue and issue.id or nil,
75 }
76 },
77 content = function()
78 local records
80 if issue then
81 local delegate_name = ""
82 local scope = "no delegation set"
83 local area_delegation = Delegation:by_pk(app.session.member_id, nil, issue.area_id)
84 if area_delegation then
85 delegate_name = area_delegation.trustee and area_delegation.trustee.name or _"abandoned"
86 scope = _"area"
87 else
88 local unit_delegation = Delegation:by_pk(app.session.member_id, issue.area.unit_id)
89 if unit_delegation then
90 delegate_name = unit_delegation.trustee.name
91 scope = _"unit"
92 end
93 end
94 records = {
95 {
96 id = -1,
97 name = _("Apply unit or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
98 },
99 {
100 id = 0,
101 name = _"Abandon unit and area delegations for this issue"
102 },
104 }
105 elseif area then
106 local delegate_name = ""
107 local scope = "no delegation set"
108 local unit_delegation = Delegation:by_pk(app.session.member_id, area.unit_id)
109 if unit_delegation then
110 delegate_name = unit_delegation.trustee.name
111 scope = _"unit"
112 end
113 records = {
114 {
115 id = -1,
116 name = _("Apply unit delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
117 },
118 {
119 id = 0,
120 name = _"Abandon unit delegation for this area"
121 }
122 }
124 else
125 records = {
126 {
127 id = -1,
128 name = _"No delegation"
129 }
130 }
132 end
133 -- add saved members
134 records[#records+1] = {id="_", name= "--- " .. _"Saved contacts" .. " ---"}
135 for i, record in ipairs(contact_members) do
136 records[#records+1] = record
137 end
138 -- add initiative authors
139 if initiative then
140 records[#records+1] = {id="_", name= "--- " .. _"Initiators" .. " ---"}
141 for i,record in ipairs(initiative.initiators) do
142 records[#records+1] = record.member
143 end
144 end
146 disabled_records = {}
147 disabled_records["_"] = true
149 ui.field.select{
150 label = _"Trustee",
151 name = "trustee_id",
152 foreign_records = records,
153 foreign_id = "id",
154 foreign_name = "name",
155 disabled_records = disabled_records
156 }
158 ui.submit{ text = _"Save" }
159 end
160 }