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