liquid_feedback_frontend
view app/main/initiative/new.lua @ 1091:20680a81c3e1
Fixed view for creating new initiatives in polling mode
author | bsw |
---|---|
date | Fri Oct 17 11:30:09 2014 +0200 (2014-10-17) |
parents | 701a5cf6b067 |
children | 5b65ea5c24f5 |
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 issue:load_everything_for_member_id(app.session.member_id)
8 area = issue.area
10 else
11 local area_id = param.get("area_id", atom.integer)
12 area = Area:new_selector():add_where{"id=?",area_id}:single_object_mode():exec()
13 area:load_delegation_info_once_for_member_id(app.session.member_id)
14 end
16 local polling = param.get("polling", atom.boolean)
18 local policy_id = param.get("policy_id", atom.integer)
19 local policy
21 local preview = param.get("preview")
23 if #(slot.get_content("error")) > 0 then
24 preview = false
25 end
27 if policy_id then
28 policy = Policy:by_id(policy_id)
29 end
31 if issue_id then
32 execute.view {
33 module = "issue", view = "_head",
34 params = { issue = issue, member = app.session.member }
35 }
36 execute.view {
37 module = "issue", view = "_sidebar_state",
38 params = {
39 issue = issue
40 }
41 }
42 execute.view {
43 module = "issue", view = "_sidebar_issue",
44 params = {
45 issue = issue
46 }
47 }
48 else
49 execute.view {
50 module = "area", view = "_head",
51 params = { area = area, member = app.session.member }
52 }
53 execute.view {
54 module = "initiative", view = "_sidebar_policies",
55 params = {
56 area = area,
57 }
58 }
59 end
61 ui.form{
62 module = "initiative",
63 action = "create",
64 params = {
65 area_id = area.id,
66 issue_id = issue and issue.id or nil
67 },
68 attr = { class = "vertical" },
69 content = function()
71 if preview then
72 ui.section( function()
73 ui.sectionHead( function()
74 ui.heading{ level = 1, content = encode.html(param.get("name")) }
75 if not issue then
76 ui.container { content = policy.name }
77 end
78 slot.put("<br />")
80 ui.field.hidden{ name = "formatting_engine", value = param.get("formatting_engine") }
81 ui.field.hidden{ name = "policy_id", value = param.get("policy_id") }
82 ui.field.hidden{ name = "name", value = param.get("name") }
83 ui.field.hidden{ name = "draft", value = param.get("draft") }
84 local formatting_engine
85 if config.enforce_formatting_engine then
86 formatting_engine = config.enforce_formatting_engine
87 else
88 formatting_engine = param.get("formatting_engine")
89 end
90 ui.container{
91 attr = { class = "draft_content wiki" },
92 content = function()
93 slot.put(format.wiki_text(param.get("draft"), formatting_engine))
94 end
95 }
96 slot.put("<br />")
98 ui.tag{
99 tag = "input",
100 attr = {
101 type = "submit",
102 class = "btn btn-default",
103 value = _'Publish now'
104 },
105 content = ""
106 }
107 slot.put("<br />")
108 slot.put("<br />")
109 ui.tag{
110 tag = "input",
111 attr = {
112 type = "submit",
113 name = "edit",
114 class = "btn-link",
115 value = _'Edit again'
116 },
117 content = ""
118 }
119 slot.put(" | ")
120 if issue then
121 ui.link{ content = _"Cancel", module = "issue", view = "show", id = issue.id }
122 else
123 ui.link{ content = _"Cancel", module = "area", view = "show", id = area.id }
124 end
125 end )
126 end )
127 else
130 execute.view{ module = "initiative", view = "_sidebar_wikisyntax" }
132 ui.section( function()
133 if preview then
134 ui.sectionHead( function()
135 ui.heading { level = 1, content = _"Edit again" }
136 end )
137 elseif issue_id then
138 ui.sectionHead( function()
139 ui.heading { level = 1, content = _"Add a new competing initiative to issue" }
140 end )
141 else
142 ui.sectionHead( function()
143 ui.heading { level = 1, content = _"Create a new issue" }
144 end )
145 end
147 ui.sectionRow( function()
148 if not preview and not issue_id then
149 ui.container { attr = { class = "section" }, content = _"Before creating a new issue, please check any existant issues before, if the topic is already in discussion." }
150 slot.put("<br />")
151 end
152 if not issue_id then
153 tmp = { { id = -1, name = "" } }
154 for i, allowed_policy in ipairs(area.allowed_policies) do
155 if not allowed_policy.polling or app.session.member:has_polling_right_for_unit_id(area.unit_id) then
156 tmp[#tmp+1] = allowed_policy
157 end
158 end
159 ui.heading{ level = 2, content = _"Please choose a policy for the new issue:" }
160 ui.field.select{
161 name = "policy_id",
162 foreign_records = tmp,
163 foreign_id = "id",
164 foreign_name = "name",
165 value = param.get("policy_id", atom.integer) or area.default_policy and area.default_policy.id
166 }
167 if policy and policy.free_timeable then
168 ui.sectionRow( function()
169 local available_timings
170 if config.free_timing and config.free_timing.available_func then
171 available_timings = config.free_timing.available_func(policy)
172 if available_timings == false then
173 error("error in free timing config")
174 end
175 end
176 ui.heading{ level = 4, content = _"Free timing:" }
177 if available_timings then
178 ui.field.select{
179 name = "free_timing",
180 foreign_records = available_timings,
181 foreign_id = "id",
182 foreign_name = "name",
183 value = param.get("free_timing")
184 }
185 else
186 ui.field.text{
187 name = "free_timing",
188 value = param.get("free_timing")
189 }
190 end
191 end )
192 end
193 end
195 if issue and issue.policy.polling and app.session.member:has_polling_right_for_unit_id(area.unit_id) then
196 slot.put("<br />")
197 ui.field.boolean{ name = "polling", label = _"No admission needed", value = polling }
198 end
200 slot.put("<br />")
201 ui.heading { level = 2, content = _"Enter a title for your initiative (max. 140 chars):" }
202 ui.field.text{
203 attr = { style = "width: 100%;" },
204 name = "name",
205 value = param.get("name")
206 }
207 ui.container { content = _"The title is the figurehead of your iniative. It should be short but meaningful! As others identifies your initiative by this title, you cannot change it later!" }
209 if not config.enforce_formatting_engine then
210 slot.put("<br />")
211 ui.heading { level = 4, content = _"Choose a formatting engine:" }
212 ui.field.select{
213 name = "formatting_engine",
214 foreign_records = config.formatting_engines,
215 attr = {id = "formatting_engine"},
216 foreign_id = "id",
217 foreign_name = "name",
218 value = param.get("formatting_engine")
219 }
220 end
221 slot.put("<br />")
223 ui.heading { level = 2, content = _"Enter your proposal and/or reasons:" }
224 ui.field.text{
225 name = "draft",
226 multiline = true,
227 attr = { style = "height: 50ex; width: 100%;" },
228 value = param.get("draft") or
229 [[
230 Proposal
231 ======
233 Replace me with your proposal.
236 Reasons
237 ======
239 Argument 1
240 ------
242 Replace me with your first argument
245 Argument 2
246 ------
248 Replace me with your second argument
250 ]]
251 }
252 if not issue or issue.state == "admission" or issue.state == "discussion" then
253 ui.container { content = _"You can change your text again anytime during admission and discussion phase" }
254 else
255 ui.container { content = _"You cannot change your text again later, because this issue is already in verfication phase!" }
256 end
257 slot.put("<br />")
258 ui.tag{
259 tag = "input",
260 attr = {
261 type = "submit",
262 name = "preview",
263 class = "btn btn-default",
264 value = _'Preview'
265 },
266 content = ""
267 }
268 slot.put("<br />")
269 slot.put("<br />")
271 if issue then
272 ui.link{ content = _"Cancel", module = "issue", view = "show", id = issue.id }
273 else
274 ui.link{ content = _"Cancel", module = "area", view = "show", id = area.id }
275 end
276 end )
277 end )
278 end
279 end
280 }