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