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