liquid_feedback_frontend

view app/main/lf2/delegation.lua @ 219:217653875fbb

Fix registration process for units
author bsw
date Sun Mar 13 16:59:16 2011 +0100 (2011-03-13)
parents 7ea52c710503
children
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 unit = Unit:by_id(param.get("unit_id", atom.integer))
7 local delegation = Delegation:by_pk(app.session.member_id, unit and unit.id or nil, area and area.id or nil, issue and issue.id or nil)
9 local initiative = Initiative:by_id(param.get("initiative_id", atom.integer))
11 local contact_members = Member:build_selector{
12 is_contact_of_member_id = app.session.member_id,
13 order = "name"
14 }:exec()
16 if area then
17 title = _("Set delegation for area '#{name}'", { name = area.name })
18 end
20 if issue then
21 title = _("Set delegation for issue ##{number} in area '#{area_name}'", { number = issue.id, area_name = issue.area.name })
22 end
24 if not area and not issue then
25 title = _("Set delegation for unit #{name}", { name = unit.name })
26 end
28 ui.box{ content = function()
30 ui.box_row{ class = "head", content = function() ui.box_col{ class = "head", content = title } end }
32 ui.form{
33 attr = { class = "vertical" },
34 module = "delegation",
35 action = "update",
36 params = {
37 unit_id = unit and unit.id or nil,
38 area_id = area and area.id or nil,
39 issue_id = issue and issue.id or nil,
40 },
41 routing = {
42 default = {
43 mode = "redirect",
44 module = "lf2",
45 view = area and "area" or initiative and "initiative" or issue and "issue" or "index",
46 id = area and area.id or initiative and initiative.id or issue and issue.id or unit.id,
47 }
48 },
49 content = function()
50 local records
52 if issue then
53 local delegate_name = ""
54 local scope = "no delegation set"
55 local area_delegation = Delegation:by_pk(app.session.member_id, issue.area_id)
56 if area_delegation then
57 delegate_name = area_delegation.trustee and area_delegation.trustee.name or _"abandoned"
58 scope = _"area"
59 else
60 local unit_delegation = Delegation:by_pk(app.session.member_id)
61 if unit_delegation then
62 delegate_name = unit_delegation.trustee.name
63 scope = _"unit"
64 end
65 end
66 records = {
67 {
68 id = -1,
69 name = _("Apply unit or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
70 },
71 {
72 id = 0,
73 name = _"Abandon unit and area delegations for this issue"
74 },
76 }
77 elseif area then
78 local delegate_name = ""
79 local scope = "no delegation set"
80 local unit_delegation = Delegation:by_pk(app.session.member_id)
81 if unit_delegation then
82 delegate_name = unit_delegation.trustee.name
83 scope = _"unit"
84 end
85 records = {
86 {
87 id = -1,
88 name = _("Apply unit delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
89 },
90 {
91 id = 0,
92 name = _"Abandon unit delegation for this area"
93 }
94 }
96 else
97 records = {
98 {
99 id = -1,
100 name = _"No delegation"
101 }
102 }
104 end
105 disabled_records = {}
106 disabled_records["_"] = true
108 -- add saved members
109 records[#records+1] = {id="_", name= "--- " .. _"Saved contacts" .. " ---"}
110 for i, record in ipairs(contact_members) do
111 records[#records+1] = record
112 end
114 -- add initiative authors
115 if initiative then
116 records[#records+1] = {id="_", name= "--- " .. _"Initiators" .. " ---"}
117 for i,record in ipairs(initiative.initiators) do
118 records[#records+1] = record.member
119 if record.member.id == app.session.member_id then
120 disabled_records[record.member.id] = true
121 end
122 end
123 end
127 ui.box_row{ content = function() ui.box_col{ content = function()
128 ui.field.select{
129 label = _"Delegate",
130 name = "trustee_id",
131 foreign_records = records,
132 foreign_id = "id",
133 foreign_name = "name",
134 disabled_records = disabled_records,
135 value = delegation and delegation.trustee_id or nil
136 }
137 end } end }
139 ui.box_row{ content = function()
140 ui.box_col{ content = _"Please note: Member, interest and supporter counts are calculated periodically, therefore it can take some time until your changes become effective everywhere." }
141 end }
142 ui.box_row{ content = function() ui.box_col{ content = function()
143 ui.submit{ text = _"Save" }
144 end } end }
145 end
146 }
148 end }

Impressum / About Us