| rev | 
   line source | 
| 
bsw/jbe@1309
 | 
     1 local draft = Draft:new_selector():add_where{ "id = ?", param.get_id() }:optional_object_mode():exec()
 | 
| 
bsw/jbe@1309
 | 
     2 
 | 
| 
bsw/jbe@1309
 | 
     3 if not draft then
 | 
| 
bsw/jbe@1309
 | 
     4   execute.view { module = "index", view = "404" }
 | 
| 
bsw/jbe@1309
 | 
     5   request.set_status("404 Not Found")
 | 
| 
bsw/jbe@1309
 | 
     6   return
 | 
| 
bsw/jbe@1309
 | 
     7 end
 | 
| 
bsw/jbe@1309
 | 
     8 
 | 
| 
bsw@1495
 | 
     9 local member = app.session.member
 | 
| 
bsw@1495
 | 
    10 
 | 
| 
bsw@1495
 | 
    11 if member then
 | 
| 
bsw@1495
 | 
    12   draft.initiative:load_everything_for_member_id(member.id)
 | 
| 
bsw@1495
 | 
    13   draft.initiative.issue:load_everything_for_member_id(member.id)
 | 
| 
bsw@1495
 | 
    14 end
 | 
| 
bsw/jbe@1309
 | 
    15 
 | 
| 
poelzi@160
 | 
    16 local source = param.get("source", atom.boolean)
 | 
| 
poelzi@160
 | 
    17 
 | 
| 
bsw@1495
 | 
    18 execute.view{ module = "issue", view = "_head", params = { issue = draft.initiative.issue, link_issue = true } }
 | 
| 
bsw@1495
 | 
    19 
 | 
| 
bsw@1495
 | 
    20 ui.grid{ content = function()
 | 
| 
poelzi@160
 | 
    21 
 | 
| 
bsw@1495
 | 
    22   ui.cell_main{ content = function()
 | 
| 
bsw@1495
 | 
    23 
 | 
| 
bsw@1495
 | 
    24     ui.container{ attr = { class = "mdl-card mdl-card__fullwidth mdl-shadow--2dp" }, content = function()
 | 
| 
bsw@1495
 | 
    25 
 | 
| 
bsw@1495
 | 
    26       ui.container{ attr = { class = "mdl-card__title mdl-card--has-fab mdl-card--border" }, content = function ()
 | 
| 
bsw@1495
 | 
    27 
 | 
| 
bsw@1045
 | 
    28         ui.heading { 
 | 
| 
bsw@1495
 | 
    29           attr = { class = "mdl-card__title-text" },
 | 
| 
bsw@1495
 | 
    30           level = 2,
 | 
| 
bsw@1495
 | 
    31           content = function()
 | 
| 
bsw@1495
 | 
    32             ui.link{
 | 
| 
bsw@1495
 | 
    33               module = "initiative", view = "show", id = draft.initiative.id,
 | 
| 
bsw@1495
 | 
    34               content = draft.initiative.display_name
 | 
| 
bsw@1495
 | 
    35             }
 | 
| 
bsw@1495
 | 
    36             ui.container{ content = _("Draft revision #{id}", { id = draft.id } ) }
 | 
| 
bsw@1495
 | 
    37           end 
 | 
| 
bsw@1045
 | 
    38         }
 | 
| 
bsw@1495
 | 
    39       end }
 | 
| 
bsw@1495
 | 
    40 
 | 
| 
bsw@1495
 | 
    41       ui.container{ attr = { class = "draft mdl-card__title mdl-card--border" }, content = function()
 | 
| 
bsw@1495
 | 
    42         if config.render_external_reference and config.render_external_reference.draft then
 | 
| 
bsw@1495
 | 
    43           config.render_external_reference.draft(draft, function (callback)
 | 
| 
bsw@1495
 | 
    44             ui.sectionRow(callback)
 | 
| 
bsw@1495
 | 
    45           end)
 | 
| 
bsw@1495
 | 
    46         end
 | 
| 
bsw@1495
 | 
    47         
 | 
| 
bsw@1495
 | 
    48         execute.view{
 | 
| 
bsw@1045
 | 
    49           module = "draft",
 | 
| 
bsw@1495
 | 
    50           view = "_show",
 | 
| 
bsw@1495
 | 
    51           params = { draft = draft, source = source }
 | 
| 
bsw@1045
 | 
    52         }
 | 
| 
bsw@1495
 | 
    53 
 | 
| 
bsw@1495
 | 
    54 
 | 
| 
bsw@1495
 | 
    55 
 | 
| 
bsw@1495
 | 
    56       end }      
 | 
| 
bsw@1495
 | 
    57 
 | 
| 
bsw@1495
 | 
    58       if config.attachments then
 | 
| 
bsw@1495
 | 
    59 
 | 
| 
bsw@1495
 | 
    60         local files = File:new_selector()
 | 
| 
bsw@1495
 | 
    61           :left_join("draft_attachment", nil, "draft_attachment.file_id = file.id")
 | 
| 
bsw@1495
 | 
    62           :add_where{ "draft_attachment.draft_id = ?", draft.id }
 | 
| 
bsw@1495
 | 
    63           :reset_fields()
 | 
| 
bsw@1495
 | 
    64           :add_field("file.id")
 | 
| 
bsw@1495
 | 
    65           :add_field("draft_attachment.title")
 | 
| 
bsw@1495
 | 
    66           :add_field("draft_attachment.description")
 | 
| 
bsw@1495
 | 
    67           :add_order_by("draft_attachment.id")
 | 
| 
bsw@1495
 | 
    68           :exec()
 | 
| 
bsw@1495
 | 
    69 
 | 
| 
bsw@1495
 | 
    70         if #files > 0 then
 | 
| 
bsw@1495
 | 
    71           ui.container {
 | 
| 
bsw@1495
 | 
    72             attr = { class = "mdl-card__content mdl-card--border" },
 | 
| 
bsw@1495
 | 
    73             content = function()
 | 
| 
bsw@1495
 | 
    74               for i, file in ipairs(files) do
 | 
| 
bsw@1495
 | 
    75                 ui.link{ module = "file", view = "show.jpg", id = file.id, content = function()
 | 
| 
bsw@1495
 | 
    76                   ui.image{ module = "file", view = "show.jpg", id = file.id, params = { preview = true } }
 | 
| 
bsw@1495
 | 
    77                 end }
 | 
| 
bsw@1495
 | 
    78                 ui.container{ content = file.title or "" }
 | 
| 
bsw@1495
 | 
    79                 ui.container{ content = file.description or "" }
 | 
| 
bsw@1495
 | 
    80                 slot.put("<br /><br />")
 | 
| 
bsw@1495
 | 
    81               end
 | 
| 
bsw@1495
 | 
    82             end
 | 
| 
bsw@1495
 | 
    83           }
 | 
| 
bsw@1495
 | 
    84         end
 | 
| 
bsw@1045
 | 
    85       end
 | 
| 
bsw@1495
 | 
    86 
 | 
| 
bsw@1495
 | 
    87       ui.container{ attr = { class = "mdl-card__actions" }, content = function()
 | 
| 
bsw@1495
 | 
    88         if source then
 | 
| 
bsw@1495
 | 
    89           ui.link{
 | 
| 
bsw@1495
 | 
    90             attr = { class = "mdl-button mdl-js-button" },
 | 
| 
bsw@1495
 | 
    91             content = _"Rendered",
 | 
| 
bsw@1495
 | 
    92             module = "draft",
 | 
| 
bsw@1495
 | 
    93             view = "show",
 | 
| 
bsw@1495
 | 
    94             id = param.get_id(),
 | 
| 
bsw@1495
 | 
    95             params = { source = false }
 | 
| 
bsw@1495
 | 
    96           }
 | 
| 
bsw@1495
 | 
    97         else
 | 
| 
bsw@1495
 | 
    98           ui.link{
 | 
| 
bsw@1495
 | 
    99             attr = { class = "mdl-button mdl-js-button" },
 | 
| 
bsw@1495
 | 
   100             content = _"Source",
 | 
| 
bsw@1495
 | 
   101             module = "draft",
 | 
| 
bsw@1495
 | 
   102             view = "show",
 | 
| 
bsw@1495
 | 
   103             id = param.get_id(),
 | 
| 
bsw@1495
 | 
   104             params = { source = true }
 | 
| 
bsw@1495
 | 
   105           }
 | 
| 
bsw@1495
 | 
   106         end
 | 
| 
bsw@1495
 | 
   107         
 | 
| 
bsw@1495
 | 
   108       end }
 | 
| 
bsw@1045
 | 
   109     end }
 | 
| 
bsw@1495
 | 
   110 
 | 
| 
bsw@1495
 | 
   111   end }
 | 
| 
bsw@1495
 | 
   112 
 | 
| 
bsw@1495
 | 
   113   ui.cell_sidebar{ content = function()
 | 
| 
bsw@1495
 | 
   114     if config.logo then
 | 
| 
bsw@1495
 | 
   115       config.logo()
 | 
| 
bsw@1495
 | 
   116     end
 | 
| 
bsw@1495
 | 
   117     execute.view {
 | 
| 
bsw@1495
 | 
   118       module = "issue", view = "_sidebar", 
 | 
| 
bsw@1495
 | 
   119       params = {
 | 
| 
bsw@1495
 | 
   120         issue = draft.initiative.issue,
 | 
| 
bsw@1495
 | 
   121         initiative = draft.initiative,
 | 
| 
bsw@1495
 | 
   122         member = app.session.member
 | 
| 
bsw@1495
 | 
   123       }
 | 
| 
bsw@1045
 | 
   124     }
 | 
| 
bsw@1495
 | 
   125   end }
 | 
| 
bsw@1495
 | 
   126 
 | 
| 
bsw@1495
 | 
   127 end }
 |