liquid_feedback_frontend

view app/main/draft/new.lua @ 1576:b3517222d097

Fixed library name
author bsw
date Mon Dec 07 16:55:57 2020 +0100 (2020-12-07)
parents 3f3f802354b7
children 90af594c803e
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") then
130 ui.sectionRow( function()
131 if not issue and not initiative then
132 ui.container { content = policy.name }
133 end
134 if param.get("free_timing") then
135 ui.container { content = param.get("free_timing") }
136 end
137 slot.put("<br />")
138 ui.field.hidden{ name = "policy_id", value = param.get("policy_id") }
139 ui.field.hidden{ name = "name", value = param.get("name") }
140 if config.initiative_abstract then
141 ui.field.hidden{ name = "abstract", value = param.get("abstract") }
142 ui.container{
143 attr = { class = "abstract" },
144 content = param.get("abstract")
145 }
146 slot.put("<br />")
147 end
148 local draft_text = param.get("content")
149 local draft_text = util.wysihtml_preproc(draft_text)
150 ui.field.hidden{ name = "content", value = draft_text }
151 ui.container{
152 attr = { class = "draft" },
153 content = function()
154 slot.put(draft_text)
155 end
156 }
157 slot.put("<br />")
159 if config.attachments then
160 local file_upload_session = param.get("file_upload_session") or multirand.string(
161 32,
162 '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
163 )
164 file_upload_session = string.gsub(file_upload_session, "[^A-Za-z0-9]", "")
165 ui.field.hidden{ name = "file_upload_session", value = file_upload_session }
166 if initiative then
167 local files = File:new_selector()
168 :left_join("draft_attachment", nil, "draft_attachment.file_id = file.id")
169 :add_where{ "draft_attachment.draft_id = ?", initiative.current_draft.id }
170 :reset_fields()
171 :add_field("file.id")
172 :add_field("draft_attachment.title")
173 :add_field("draft_attachment.description")
174 :add_order_by("draft_attachment.id")
175 :exec()
177 if #files > 0 then
178 ui.container {
179 content = function()
180 for i, file in ipairs(files) do
181 if param.get("file_delete_" .. file.id, atom.boolean) then
182 ui.field.hidden{ name = "file_delete_" .. file.id, value = "1" }
183 else
184 ui.image{ module = "file", view = "show.jpg", id = file.id, params = { preview = true } }
185 ui.container{ content = function()
186 ui.tag{ tag = "strong", content = file.title or "" }
187 end }
188 ui.container{ content = file.description or "" }
189 slot.put("<br /><br />")
190 end
191 end
192 end
193 }
194 end
195 end
196 local filename = encode.file_path(WEBMCP_BASE_PATH, 'tmp', "file_upload-" .. file_upload_session .. ".json")
197 local fh = io.open(filename, "r")
198 if fh then
199 local file_uploads = json.import(fh:read("*a"))
200 for i, file_upload in ipairs(file_uploads) do
201 ui.image{ module = "draft", view = "show_file_upload", params = {
202 file_upload_session = file_upload_session, file_id = file_upload.id, preview = true
203 } }
204 ui.container{ content = function()
205 ui.tag{ tag = "strong", content = file_upload.title or "" }
206 end }
207 ui.container{ content = file_upload.description or "" }
208 slot.put("<br />")
209 end
210 end
211 end
213 ui.tag{
214 tag = "input",
215 attr = {
216 type = "submit",
217 class = "mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--colored",
218 value = _'Publish now'
219 },
220 content = ""
221 }
222 slot.put(" &nbsp; ")
224 ui.tag{
225 tag = "input",
226 attr = {
227 type = "submit",
228 name = "edit",
229 class = "mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect",
230 value = _'Edit again'
231 },
232 content = ""
233 }
234 slot.put(" &nbsp; ")
236 ui.link{
237 attr = { class = "mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect" },
238 content = _"Cancel",
239 module = initiative and "initiative" or "area",
240 view = "show",
241 id = initiative_id or area_id
242 }
243 end )
245 -- -------- EDIT
246 else
248 if not issue_id and not initiative_id then
249 local tmp = { { id = -1, name = "" } }
250 for i, allowed_policy in ipairs(area.allowed_policies) do
251 if not allowed_policy.polling or app.session.member:has_polling_right_for_unit_id(area.unit_id) then
252 tmp[#tmp+1] = allowed_policy
253 end
254 end
255 ui.container{ content = _"Please choose a policy for the new issue:" }
256 ui.field.select{
257 name = "policy_id",
258 foreign_records = tmp,
259 foreign_id = "id",
260 foreign_name = "name",
261 value = param.get("policy_id", atom.integer) or area.default_policy and area.default_policy.id
262 }
263 if policy and policy.free_timeable then
264 local available_timings
265 if config.free_timing and config.free_timing.available_func then
266 available_timings = config.free_timing.available_func(policy)
267 if available_timings == false then
268 slot.put_into("error", "error in free timing config")
269 return false
270 end
271 end
272 ui.heading{ level = 4, content = _"Free timing:" }
273 if available_timings then
274 ui.field.select{
275 name = "free_timing",
276 foreign_records = available_timings,
277 foreign_id = "id",
278 foreign_name = "name",
279 value = param.get("free_timing")
280 }
281 else
282 ui.field.text{
283 name = "free_timing",
284 value = param.get("free_timing")
285 }
286 end
287 end
288 end
290 if issue and issue.policy.polling and app.session.member:has_polling_right_for_unit_id(area.unit_id) then
291 slot.put("<br />")
292 ui.field.boolean{ name = "polling", label = _"No admission needed", value = polling }
293 end
295 if not initiative then
296 ui.container{ attr = { class = "mdl-textfield mdl-js-textfield mdl-textfield--floating-label mdl-card__fullwidth" }, content = function ()
297 ui.field.text{
298 attr = { id = "lf-initiative__name", class = "mdl-textfield__input" },
299 label_attr = { class = "mdl-textfield__label", ["for"] = "lf-initiative__name" },
300 label = _"Title",
301 name = "name",
302 value = param.get("name")
303 }
304 end }
305 end
307 if config.initiative_abstract then
308 ui.container { content = _"Enter abstract:" }
309 ui.container{ attr = { class = "mdl-textfield mdl-js-textfield mdl-textfield--expandable mdl-textfield__fullwidth" }, content = function()
310 ui.field.text{
311 name = "abstract",
312 multiline = true,
313 attr = { id = "abstract", style = "height: 20ex; width: 100%;" },
314 value = param.get("abstract")
315 }
316 end }
317 end
319 ui.container { content = _"Enter your proposal and/or reasons:" }
320 ui.field.wysihtml{
321 name = "content",
322 multiline = true,
323 attr = { id = "draft", style = "height: 50ex; width: 100%;" },
324 value = param.get("content")
325 }
326 if not issue or issue.state == "admission" or issue.state == "discussion" then
327 ui.container { content = _"You can change your text again anytime during admission and discussion phase" }
328 else
329 ui.container { content = _"You cannot change your text again later, because this issue is already in verfication phase!" }
330 end
332 slot.put("<br />")
333 if config.attachments then
334 local file_upload_session = param.get("file_upload_session") or multirand.string(
335 32,
336 '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
337 )
338 file_upload_session = string.gsub(file_upload_session, "[^A-Za-z0-9]", "")
339 ui.field.hidden{ name = "file_upload_session", value = file_upload_session }
340 if initiative then
341 local files = File:new_selector()
342 :left_join("draft_attachment", nil, "draft_attachment.file_id = file.id")
343 :add_where{ "draft_attachment.draft_id = ?", initiative.current_draft.id }
344 :reset_fields()
345 :add_field("file.id")
346 :add_field("draft_attachment.title")
347 :add_field("draft_attachment.description")
348 :add_order_by("draft_attachment.id")
349 :exec()
351 if #files > 0 then
352 ui.container {
353 content = function()
354 for i, file in ipairs(files) do
355 ui.image{ module = "file", view = "show.jpg", id = file.id, params = { preview = true } }
356 ui.container{ content = function()
357 ui.tag{ tag = "strong", content = file.title or "" }
358 end }
359 ui.container{ content = file.description or "" }
360 ui.field.boolean{ label = _"delete", name = "file_delete_" .. file.id, value = param.get("file_delete_" .. file.id) and true or false }
361 slot.put("<br /><br />")
362 end
363 end
364 }
365 end
366 end
367 local filename = encode.file_path(WEBMCP_BASE_PATH, 'tmp', "file_upload-" .. file_upload_session .. ".json")
368 local fh = io.open(filename, "r")
369 if fh then
370 local file_uploads = json.import(fh:read("*a"))
371 for i, file_upload in ipairs(file_uploads) do
372 ui.image{ module = "draft", view = "show_file_upload", params = {
373 file_upload_session = file_upload_session, file_id = file_upload.id, preview = true
374 } }
375 ui.container{ content = function()
376 ui.tag{ tag = "strong", content = file_upload.title or "" }
377 end }
378 ui.container{ content = file_upload.description or "" }
379 ui.field.boolean{ label = _"delete", name = "file_upload_delete_" .. file_upload.id }
380 slot.put("<br />")
381 end
382 end
383 ui.container{ attr = { id = "file_upload_template", style = "display: none;" }, content = function()
384 ui.field.text{ label = _"Title", name = "__ID_title__" }
385 ui.field.text{ label = _"Description", name = "__ID_description__" }
386 ui.field.image{ field_name = "__ID_file__" }
387 end }
388 ui.container{ attr = { id = "file_upload" }, content = function()
389 end }
390 ui.field.hidden{ attr = { id = "file_upload_last_id" }, name = "file_upload_last_id" }
391 ui.script{ script = [[ var file_upload_id = 1; ]] }
392 ui.tag{ tag = "a", content = _"Attach image", attr = {
393 href = "#",
394 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;"
395 } }
396 slot.put("<br />")
398 slot.put("<br />")
400 end
402 ui.tag{
403 tag = "input",
404 attr = {
405 type = "submit",
406 name = "preview",
407 class = "mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--colored",
408 value = _'Preview'
409 },
410 content = ""
411 }
412 slot.put(" &nbsp; ")
414 ui.link{
415 content = _"Cancel",
416 module = initiative and "initiative" or issue and "issue" or "index",
417 view = area and not issue and "index" or "show",
418 id = initiative_id or issue_id,
419 params = { area = area_id, unit = area and area.unit_id or nil },
420 attr = { class = "mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect" }
421 }
423 end
424 end }
425 end }
426 end }
428 if config.map or config.firstlife then
429 ui.cell_sidebar{ content = function()
430 ui.container{ attr = { class = "mdl-special-card map mdl-shadow--2dp" }, content = function()
431 local location = param.get("location")
432 local lat = param.get("lat")
433 local lon = param.get("lon")
434 if lat and lon then
435 location = json.export(JSON.object{
436 type = "Point",
437 coordinates = json.array{ lon, lat }
438 })
439 end
440 ui.field.location{ name = "location", value = location }
441 end }
442 end }
443 end
445 if config.firstlife then
446 ui.field.hidden{ name = "external_reference", value = param.get("external_reference") }
447 end
449 end }
450 end
451 }

Impressum / About Us