liquid_feedback_frontend

annotate app/main/draft/new.lua @ 1534:0d9bb3937310

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

Impressum / About Us