liquid_feedback_frontend

view app/main/draft/new.lua @ 1763:0f04f8c2a469

Removed unused views
author bsw
date Mon Oct 18 15:31:37 2021 +0200 (2021-10-18)
parents 89f524f1d185
children de3770da915e
line source
1 local issue
2 local area
3 local area_id
5 local issue_id = param.get("issue_id", atom.integer)
6 if issue_id then
7 issue = Issue:new_selector():add_where{"id=?",issue_id}:single_object_mode():exec()
8 issue:load_everything_for_member_id(app.session.member_id)
9 area = issue.area
10 else
11 area_id = param.get("area_id", atom.integer)
12 if area_id then
13 area = Area:new_selector():add_where{"id=?",area_id}:single_object_mode():exec()
14 area:load_delegation_info_once_for_member_id(app.session.member_id)
15 else
16 local firstlife_id = param.get("firstlife_id")
17 if firstlife_id then
18 area = Area:new_selector():join("unit", nil, "unit.id = area.unit_id"):add_where{"attr->>'firstlife_id'=?",firstlife_id}:single_object_mode():exec()
19 area:load_delegation_info_once_for_member_id(app.session.member_id)
20 area_id = area.id
21 end
22 end
23 end
25 local polling = param.get("polling", atom.boolean)
27 local policy_id = param.get("policy_id", atom.integer)
28 local policy
30 local preview = param.get("preview")
32 if #(slot.get_content("error")) > 0 then
33 preview = false
34 end
36 if policy_id then
37 policy = Policy:by_id(policy_id)
38 end
40 local callback = param.get("callback")
43 local initiative_id = param.get("initiative_id")
44 local initiative = Initiative:by_id(initiative_id)
45 local draft
46 if initiative then
47 initiative:load_everything_for_member_id(app.session.member_id)
48 initiative.issue:load_everything_for_member_id(app.session.member_id)
50 if initiative.issue.closed then
51 slot.put_into("error", _"This issue is already closed.")
52 return
53 elseif initiative.issue.half_frozen then
54 slot.put_into("error", _"This issue is already frozen.")
55 return
56 elseif initiative.issue.phase_finished then
57 slot.put_into("error", _"Current phase is already closed.")
58 return
59 end
61 draft = initiative.current_draft
62 if config.initiative_abstract then
63 draft.abstract = string.match(draft.content, "(.+)<!%--END_OF_ABSTRACT%-->")
64 if draft.abstract then
65 draft.content = string.match(draft.content, "<!%--END_OF_ABSTRACT%-->(.*)")
66 end
67 end
68 end
70 if not initiative and not issue and not area then
71 ui.heading{ content = _"Missing parameter" }
72 return false
73 end
75 ui.form{
76 record = draft,
77 attr = { class = "vertical section", enctype = 'multipart/form-data' },
78 module = "draft",
79 action = "add",
80 params = {
81 area_id = area and area.id,
82 issue_id = issue and issue.id or nil,
83 initiative_id = initiative_id,
84 callback = callback
85 },
86 routing = {
87 ok = {
88 mode = "redirect",
89 module = "initiative",
90 view = "show",
91 id = initiative_id
92 }
93 },
94 content = function()
96 if issue or initiative then
97 execute.view {
98 module = "issue", view = "_head", params = {
99 issue = issue or initiative.issue,
100 member = app.session.member
101 }
102 }
103 else
104 execute.view {
105 module = "area", view = "_head", params = {
106 area = area,
107 member = app.session.member
108 }
109 }
110 end
112 ui.grid{ content = function()
113 ui.cell_main{ content = function()
114 ui.container{ attr = { class = "mdl-card mdl-shadow--2dp mdl-card__fullwidth" }, content = function()
115 ui.container{ attr = { class = "mdl-card__title mdl-card--border" }, content = function()
116 if initiative then
117 ui.heading { attr = { class = "mdl-card__title-text" }, level = 2, content = initiative.display_name }
118 elseif param.get("name") then
119 ui.heading { attr = { class = "mdl-card__title-text" }, level = 2, content = param.get("name") }
120 elseif issue then
121 ui.heading { attr = { class = "mdl-card__title-text" }, level = 2, content = _("New competing initiative in issue '#{issue}'", { issue = issue.name }) }
122 elseif area then
123 ui.heading { attr = { class = "mdl-card__title-text" }, level = 2, content = _"New issue" }
124 end
125 end }
126 ui.container{ attr = { class = "mdl-card__content mdl-card--border" }, content = function()
128 -- -------- PREVIEW
129 if param.get("preview") and slot.get_content("error") == "" then
130 ui.sectionRow( function()
131 if not issue and not initiative and #area.allowed_policies > 1 then
132 ui.container { content = policy and policy.name or "" }
133 slot.put("<br />")
134 end
135 if param.get("free_timing") then
136 ui.container { content = param.get("free_timing") }
137 slot.put("<br />")
138 end
139 ui.field.hidden{ name = "policy_id", value = param.get("policy_id") }
140 ui.field.hidden{ name = "name", value = param.get("name") }
141 if config.initiative_abstract then
142 ui.field.hidden{ name = "abstract", value = param.get("abstract") }
143 ui.container{
144 attr = { class = "abstract" },
145 content = param.get("abstract")
146 }
147 slot.put("<br />")
148 end
149 local draft_text = param.get("content")
150 local draft_text = util.wysihtml_preproc(draft_text)
151 ui.field.hidden{ name = "content", value = draft_text }
152 ui.container{
153 attr = { class = "draft" },
154 content = function()
155 slot.put(draft_text)
156 end
157 }
158 slot.put("<br />")
160 if config.attachments then
161 local file_upload_session = param.get("file_upload_session") or multirand.string(
162 32,
163 '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
164 )
165 file_upload_session = string.gsub(file_upload_session, "[^A-Za-z0-9]", "")
166 ui.field.hidden{ name = "file_upload_session", value = file_upload_session }
167 if initiative then
168 local files = File:new_selector()
169 :left_join("draft_attachment", nil, "draft_attachment.file_id = file.id")
170 :add_where{ "draft_attachment.draft_id = ?", initiative.current_draft.id }
171 :reset_fields()
172 :add_field("file.id")
173 :add_field("draft_attachment.title")
174 :add_field("draft_attachment.description")
175 :add_order_by("draft_attachment.id")
176 :exec()
178 if #files > 0 then
179 ui.container {
180 content = function()
181 for i, file in ipairs(files) do
182 if param.get("file_delete_" .. file.id, atom.boolean) then
183 ui.field.hidden{ name = "file_delete_" .. file.id, value = "1" }
184 else
185 ui.image{ module = "file", view = "show.jpg", id = file.id, params = { preview = true } }
186 ui.container{ content = function()
187 ui.tag{ tag = "strong", content = file.title or "" }
188 end }
189 ui.container{ content = file.description or "" }
190 slot.put("<br /><br />")
191 end
192 end
193 end
194 }
195 end
196 end
197 local filename = encode.file_path(WEBMCP_BASE_PATH, 'tmp', "file_upload-" .. file_upload_session .. ".json")
198 local fh = io.open(filename, "r")
199 if fh then
200 local file_uploads = json.import(fh:read("*a"))
201 for i, file_upload in ipairs(file_uploads) do
202 ui.image{ module = "draft", view = "show_file_upload", params = {
203 file_upload_session = file_upload_session, file_id = file_upload.id, preview = true
204 } }
205 ui.container{ content = function()
206 ui.tag{ tag = "strong", content = file_upload.title or "" }
207 end }
208 ui.container{ content = file_upload.description or "" }
209 slot.put("<br />")
210 end
211 end
212 end
214 ui.tag{
215 tag = "input",
216 attr = {
217 type = "submit",
218 class = "mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--colored",
219 value = _'Publish now'
220 },
221 content = ""
222 }
223 slot.put(" &nbsp; ")
225 ui.tag{
226 tag = "input",
227 attr = {
228 type = "submit",
229 name = "edit",
230 class = "mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect",
231 value = _'Edit again'
232 },
233 content = ""
234 }
235 slot.put(" &nbsp; ")
237 ui.link{
238 attr = { class = "mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect" },
239 content = _"Cancel",
240 module = initiative and "initiative" or "index",
241 view = initiative and "show" or "index",
242 id = initiative_id,
243 params = { unit = area and area.unit_id or nil, area = area_id }
244 }
245 end )
247 -- -------- EDIT
248 else
250 if not issue_id and not initiative_id then
251 local tmp = { { id = -1, name = "" } }
252 for i, allowed_policy in ipairs(area.allowed_policies) do
253 if not allowed_policy.polling or app.session.member:has_polling_right_for_unit_id(area.unit_id) then
254 tmp[#tmp+1] = allowed_policy
255 end
256 end
257 if #area.allowed_policies > 1 then
258 ui.container{ content = _"Please choose a policy for the new issue:" }
259 ui.field.select{
260 name = "policy_id",
261 foreign_records = tmp,
262 foreign_id = "id",
263 foreign_name = "name",
264 value = param.get("policy_id", atom.integer) or area.default_policy and area.default_policy.id
265 }
266 else
267 ui.field.hidden{
268 name = "policy_id",
269 value = area.allowed_policies[1].id
270 }
271 end
272 if policy and policy.free_timeable then
273 local available_timings
274 if config.free_timing and config.free_timing.available_func then
275 available_timings = config.free_timing.available_func(policy)
276 if available_timings == false then
277 slot.put_into("error", "error in free timing config")
278 return false
279 end
280 end
281 ui.heading{ level = 4, content = _"Free timing:" }
282 if available_timings then
283 ui.field.select{
284 name = "free_timing",
285 foreign_records = available_timings,
286 foreign_id = "id",
287 foreign_name = "name",
288 value = param.get("free_timing")
289 }
290 else
291 ui.field.text{
292 name = "free_timing",
293 value = param.get("free_timing")
294 }
295 end
296 end
297 end
299 if issue and issue.policy.polling and app.session.member:has_polling_right_for_unit_id(area.unit_id) then
300 slot.put("<br />")
301 ui.field.boolean{ name = "polling", label = _"No admission needed", value = polling }
302 end
304 if not initiative then
305 ui.container{ attr = { class = "mdl-textfield mdl-js-textfield mdl-textfield--floating-label mdl-card__fullwidth" }, content = function ()
306 ui.field.text{
307 attr = { id = "lf-initiative__name", class = "mdl-textfield__input" },
308 label_attr = { class = "mdl-textfield__label", ["for"] = "lf-initiative__name" },
309 label = _"Title",
310 name = "name",
311 value = param.get("name")
312 }
313 end }
314 end
316 if config.initiative_abstract then
317 ui.container { content = _"Enter abstract:" }
318 ui.container{ attr = { class = "mdl-textfield mdl-js-textfield mdl-textfield--expandable mdl-textfield__fullwidth" }, content = function()
319 ui.field.text{
320 name = "abstract",
321 multiline = true,
322 attr = { id = "abstract", style = "height: 20ex; width: 100%;" },
323 value = param.get("abstract")
324 }
325 end }
326 end
328 ui.container { content = _"Enter your proposal and/or reasons:" }
329 ui.field.wysihtml{
330 name = "content",
331 multiline = true,
332 attr = { id = "draft", style = "height: 50ex; width: 100%;" },
333 value = param.get("content")
334 }
335 if not issue or issue.state == "admission" or issue.state == "discussion" then
336 ui.container { content = _"You can change your text again anytime during admission and discussion phase" }
337 else
338 ui.container { content = _"You cannot change your text again later, because this issue is already in verfication phase!" }
339 end
341 slot.put("<br />")
342 if config.attachments then
343 local file_upload_session = param.get("file_upload_session") or multirand.string(
344 32,
345 '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
346 )
347 file_upload_session = string.gsub(file_upload_session, "[^A-Za-z0-9]", "")
348 ui.field.hidden{ name = "file_upload_session", value = file_upload_session }
349 if initiative then
350 local files = File:new_selector()
351 :left_join("draft_attachment", nil, "draft_attachment.file_id = file.id")
352 :add_where{ "draft_attachment.draft_id = ?", initiative.current_draft.id }
353 :reset_fields()
354 :add_field("file.id")
355 :add_field("draft_attachment.title")
356 :add_field("draft_attachment.description")
357 :add_order_by("draft_attachment.id")
358 :exec()
360 if #files > 0 then
361 ui.container {
362 content = function()
363 for i, file in ipairs(files) do
364 ui.image{ module = "file", view = "show.jpg", id = file.id, params = { preview = true } }
365 ui.container{ content = function()
366 ui.tag{ tag = "strong", content = file.title or "" }
367 end }
368 ui.container{ content = file.description or "" }
369 ui.field.boolean{ label = _"delete", name = "file_delete_" .. file.id, value = param.get("file_delete_" .. file.id) and true or false }
370 slot.put("<br /><br />")
371 end
372 end
373 }
374 end
375 end
376 local filename = encode.file_path(WEBMCP_BASE_PATH, 'tmp', "file_upload-" .. file_upload_session .. ".json")
377 local fh = io.open(filename, "r")
378 if fh then
379 local file_uploads = json.import(fh:read("*a"))
380 for i, file_upload in ipairs(file_uploads) do
381 ui.image{ module = "draft", view = "show_file_upload", params = {
382 file_upload_session = file_upload_session, file_id = file_upload.id, preview = true
383 } }
384 ui.container{ content = function()
385 ui.tag{ tag = "strong", content = file_upload.title or "" }
386 end }
387 ui.container{ content = file_upload.description or "" }
388 ui.field.boolean{ label = _"delete", name = "file_upload_delete_" .. file_upload.id }
389 slot.put("<br />")
390 end
391 end
392 ui.container{ attr = { id = "file_upload_template", style = "display: none;" }, content = function()
393 ui.field.text{ label = _"Title", name = "__ID_title__" }
394 ui.field.text{ label = _"Description", name = "__ID_description__" }
395 ui.field.image{ field_name = "__ID_file__" }
396 end }
397 ui.container{ attr = { id = "file_upload" }, content = function()
398 end }
399 ui.field.hidden{ attr = { id = "file_upload_last_id" }, name = "file_upload_last_id" }
400 ui.script{ script = [[ var file_upload_id = 1; ]] }
401 ui.tag{ tag = "a", content = _"Attach image", attr = {
402 href = "#",
403 onclick = "var html = document.getElementById('file_upload_template').innerHTML; html = html.replace('__ID_file__', 'file_' + file_upload_id); html = html.replace('__ID_title__', 'title_' + file_upload_id); html = html.replace('__ID_description__', 'description_' + file_upload_id); var el = document.createElement('div'); el.innerHTML = html; document.getElementById('file_upload').appendChild(el); document.getElementById('file_upload_last_id').value = file_upload_id; file_upload_id++; return false;"
404 } }
405 slot.put("<br />")
407 slot.put("<br />")
409 end
411 ui.tag{
412 tag = "input",
413 attr = {
414 type = "submit",
415 name = "preview",
416 class = "mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--colored",
417 value = _'Preview'
418 },
419 content = ""
420 }
421 slot.put(" &nbsp; ")
423 ui.link{
424 content = _"Cancel",
425 module = initiative and "initiative" or issue and "issue" or "index",
426 view = area and not issue and "index" or "show",
427 id = initiative_id or issue_id,
428 params = { area = area_id, unit = area and area.unit_id or nil },
429 attr = { class = "mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect" }
430 }
432 end
433 end }
434 end }
435 end }
437 if config.map or config.firstlife then
438 ui.cell_sidebar{ content = function()
439 ui.container{ attr = { class = "mdl-special-card map mdl-shadow--2dp" }, content = function()
440 local location = param.get("location")
441 local lat = param.get("lat", atom.number)
442 local lon = param.get("lon", atom.number)
443 if lat and lon then
444 location = json.export(json.object{
445 type = "Point",
446 coordinates = json.array{ lon, lat }
447 })
448 end
449 ui.field.location{ name = "location", value = location }
450 end }
451 end }
452 end
454 if config.firstlife then
455 ui.field.hidden{ name = "external_reference", value = param.get("external_reference") }
456 end
458 end }
459 end
460 }

Impressum / About Us