liquid_feedback_frontend

annotate app/main/draft/new.lua @ 1517:4f182720a2ec

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

Impressum / About Us