liquid_feedback_frontend

view app/main/delegation/new.lua @ 199:e60a26bf535b

Delegation module refactored
author bsw
date Mon Nov 08 15:49:23 2010 +0100 (2010-11-08)
parents 19fbc5c758b5
children e3613831cd1e
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)
54 local contact_members = Member:build_selector{
55 is_contact_of_member_id = app.session.member_id,
56 order = "name"
57 }:exec()
59 ui.form{
60 attr = { class = "vertical" },
61 module = "delegation",
62 action = "update",
63 params = {
64 area_id = area and area.id or nil,
65 issue_id = issue and issue.id or nil,
66 },
67 routing = {
68 default = {
69 mode = "redirect",
70 module = area and "area" or issue and "issue" or "index",
71 view = (area or issue) and "show" or "index",
72 id = area and area.id or issue and issue.id or nil,
73 }
74 },
75 content = function()
76 local records
78 if issue then
79 local delegate_name = ""
80 local scope = "no delegation set"
81 local area_delegation = Delegation:by_pk(app.session.member_id, issue.area_id)
82 if area_delegation then
83 delegate_name = area_delegation.trustee and area_delegation.trustee.name or _"abandoned"
84 scope = _"area"
85 else
86 local global_delegation = Delegation:by_pk(app.session.member_id)
87 if global_delegation then
88 delegate_name = global_delegation.trustee.name
89 scope = _"global"
90 end
91 end
92 records = {
93 {
94 id = -1,
95 name = _("Apply global or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
96 },
97 {
98 id = 0,
99 name = _"Abandon global and area delegations for this issue"
100 },
102 }
103 elseif area then
104 local delegate_name = ""
105 local scope = "no delegation set"
106 local global_delegation = Delegation:by_pk(app.session.member_id)
107 if global_delegation then
108 delegate_name = global_delegation.trustee.name
109 scope = _"global"
110 end
111 records = {
112 {
113 id = -1,
114 name = _("Apply global delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
115 },
116 {
117 id = 0,
118 name = _"Abandon global delegation for this area"
119 }
120 }
122 else
123 records = {
124 {
125 id = -1,
126 name = _"No delegation"
127 }
128 }
130 end
131 -- add saved members
132 records[#records+1] = {id="_", name= "--- " .. _"Saved contacts" .. " ---"}
133 for i, record in ipairs(contact_members) do
134 records[#records+1] = record
135 end
136 -- add initiative authors
137 if initiative then
138 records[#records+1] = {id="_", name= "--- " .. _"Initiators" .. " ---"}
139 for i,record in ipairs(initiative.initiators) do
140 records[#records+1] = record.member
141 end
142 end
144 disabled_records = {}
145 disabled_records["_"] = true
147 ui.field.select{
148 label = _"Trustee",
149 name = "trustee_id",
150 foreign_records = records,
151 foreign_id = "id",
152 foreign_name = "name",
153 disabled_records = disabled_records
154 }
156 ui.submit{ text = _"Save" }
157 end
158 }

Impressum / About Us