liquid_feedback_frontend

view app/main/initiative/new.lua @ 903:dd6c00eb215f

Make preview of new initiative work with free timings
author bsw
date Tue Aug 21 01:29:28 2012 +0200 (2012-08-21)
parents f3d6d08b0125
children a176129ce282
line source
1 local issue
2 local area
4 local issue_id = param.get("issue_id", atom.integer)
5 if issue_id then
6 issue = Issue:new_selector():add_where{"id=?",issue_id}:single_object_mode():exec()
7 area = issue.area
9 else
10 local area_id = param.get("area_id", atom.integer)
11 area = Area:new_selector():add_where{"id=?",area_id}:single_object_mode():exec()
12 end
14 local policy_id = param.get("policy_id", atom.integer)
15 local policy
17 if policy_id then
18 policy = Policy:by_id(policy_id)
19 end
21 if issue_id then
22 ui.title(_"Add alternative initiative to issue")
23 else
24 ui.title(_"Create new issue")
25 end
27 local preview = param.get("preview")
29 if not preview and not issue_id and app.session.member:has_polling_right_for_unit_id(area.unit_id) then
30 ui.actions(function()
31 ui.link{
32 text = _"Standard policies",
33 module = "initiative", view = "new", params = {
34 area_id = area.id
35 }
36 }
37 for i, policy in ipairs(area.allowed_policies) do
38 if policy.polling then
39 slot.put(" · ")
40 ui.link{
41 text = policy.name,
42 module = "initiative", view = "new", params = {
43 area_id = area.id, policy_id = policy.id
44 }
45 }
46 end
47 end
48 end)
49 end
51 ui.form{
52 module = "initiative",
53 action = "create",
54 params = {
55 area_id = area.id,
56 issue_id = issue and issue.id or nil
57 },
58 attr = { class = "vertical" },
59 content = function()
60 ui.field.text{ label = _"Unit", value = area.unit.name }
61 ui.field.text{ label = _"Area", value = area.name }
62 slot.put("<br />")
63 if issue_id then
64 ui.field.text{ label = _"Issue", value = issue_id }
65 elseif policy_id then
66 ui.field.hidden{ name = "policy_id", value = policy.id }
67 ui.field.text{ label = _"Policy", value = policy.name }
68 if policy.free_timeable then
69 local available_timings
70 if config.free_timing and config.free_timing.available_func then
71 available_timings = config.free_timing.available_func(policy)
72 if available_timings == false then
73 error("error in free timing config")
74 end
75 end
76 if available_timings then
77 ui.field.select{
78 label = _"Free timing",
79 name = _"free_timing",
80 foreign_records = available_timings,
81 foreign_id = "id",
82 foreign_name = "name",
83 value = param.get("free_timing")
84 }
85 else
86 ui.field.text{ label = _"Free timing", name = "free_timing", value = param.get("free_timing") }
87 end
88 end
89 else
90 tmp = { { id = -1, name = _"Please choose a policy" } }
91 for i, allowed_policy in ipairs(area.allowed_policies) do
92 if not allowed_policy.polling or app.session.member:has_polling_right_for_unit_id(area.unit_id) then
93 tmp[#tmp+1] = allowed_policy
94 end
95 end
96 ui.field.select{
97 label = _"Policy",
98 name = "policy_id",
99 foreign_records = tmp,
100 foreign_id = "id",
101 foreign_name = "name",
102 value = param.get("policy_id", atom.integer) or area.default_policy and area.default_policy.id
103 }
104 ui.tag{
105 tag = "div",
106 content = function()
107 ui.tag{
108 tag = "label",
109 attr = { class = "ui_field_label" },
110 content = function() slot.put("&nbsp;") end,
111 }
112 ui.tag{
113 content = function()
114 ui.link{
115 text = _"Information about the available policies",
116 module = "policy",
117 view = "list"
118 }
119 slot.put(" ")
120 ui.link{
121 attr = { target = "_blank" },
122 text = _"(new window)",
123 module = "policy",
124 view = "list"
125 }
126 end
127 }
128 end
129 }
130 end
132 if issue and issue.policy.polling and app.session.member:has_polling_right_for_unit_id(area.unit_id) then
133 ui.field.boolean{ name = "polling", label = _"Poll" }
134 end
136 if preview then
137 ui.heading{ level = 1, content = encode.html(param.get("name")) }
138 local discussion_url = param.get("discussion_url")
139 ui.container{
140 attr = { class = "ui_field_label" },
141 content = _"Discussion with initiators"
142 }
143 ui.tag{
144 tag = "span",
145 content = function()
146 if discussion_url:find("^https?://") then
147 if discussion_url and #discussion_url > 0 then
148 ui.link{
149 attr = {
150 class = "actions",
151 target = "_blank",
152 title = discussion_url
153 },
154 content = discussion_url,
155 external = discussion_url
156 }
157 end
158 else
159 slot.put(encode.html(discussion_url))
160 end
161 end
162 }
163 ui.container{
164 attr = { class = "draft_content wiki" },
165 content = function()
166 slot.put(format.wiki_text(param.get("draft"), param.get("formatting_engine")))
167 end
168 }
169 slot.put("<br />")
170 ui.submit{ text = _"Save" }
171 slot.put("<br />")
172 slot.put("<br />")
173 end
174 slot.put("<br />")
176 ui.field.text{
177 label = _"Title of initiative",
178 name = "name",
179 value = param.get("name")
180 }
181 ui.field.text{
182 label = _"Discussion URL",
183 name = "discussion_url",
184 value = param.get("discussion_url")
185 }
186 ui.field.select{
187 label = _"Wiki engine",
188 name = "formatting_engine",
189 foreign_records = {
190 { id = "rocketwiki", name = "RocketWiki" },
191 { id = "compat", name = _"Traditional wiki syntax" }
192 },
193 attr = {id = "formatting_engine"},
194 foreign_id = "id",
195 foreign_name = "name",
196 value = param.get("formatting_engine")
197 }
198 ui.tag{
199 tag = "div",
200 content = function()
201 ui.tag{
202 tag = "label",
203 attr = { class = "ui_field_label" },
204 content = function() slot.put("&nbsp;") end,
205 }
206 ui.tag{
207 content = function()
208 ui.link{
209 text = _"Syntax help",
210 module = "help",
211 view = "show",
212 id = "wikisyntax",
213 attr = {onClick="this.href=this.href.replace(/wikisyntax[^.]*/g, 'wikisyntax_'+getElementById('formatting_engine').value)"}
214 }
215 slot.put(" ")
216 ui.link{
217 text = _"(new window)",
218 module = "help",
219 view = "show",
220 id = "wikisyntax",
221 attr = {target = "_blank", onClick="this.href=this.href.replace(/wikisyntax[^.]*/g, 'wikisyntax_'+getElementById('formatting_engine').value)"}
222 }
223 end
224 }
225 end
226 }
227 ui.field.text{
228 label = _"Draft",
229 name = "draft",
230 multiline = true,
231 attr = { style = "height: 50ex;" },
232 value = param.get("draft")
233 }
234 ui.submit{ name = "preview", text = _"Preview" }
235 ui.submit{ text = _"Save" }
236 end

Impressum / About Us