bsw/jbe@1309: local draft = Draft:new_selector():add_where{ "id = ?", param.get_id() }:optional_object_mode():exec()
bsw/jbe@1309: 
bsw/jbe@1309: if not draft then
bsw/jbe@1309:   execute.view { module = "index", view = "404" }
bsw/jbe@1309:   request.set_status("404 Not Found")
bsw/jbe@1309:   return
bsw/jbe@1309: end
bsw/jbe@1309: 
bsw@1495: local member = app.session.member
bsw@1495: 
bsw@1495: if member then
bsw@1495:   draft.initiative:load_everything_for_member_id(member.id)
bsw@1495:   draft.initiative.issue:load_everything_for_member_id(member.id)
bsw@1495: end
bsw/jbe@1309: 
poelzi@160: local source = param.get("source", atom.boolean)
poelzi@160: 
bsw@1495: execute.view{ module = "issue", view = "_head", params = { issue = draft.initiative.issue, link_issue = true } }
bsw@1495: 
bsw@1495: ui.grid{ content = function()
poelzi@160: 
bsw@1495:   ui.cell_main{ content = function()
bsw@1495: 
bsw@1495:     ui.container{ attr = { class = "mdl-card mdl-card__fullwidth mdl-shadow--2dp" }, content = function()
bsw@1495: 
bsw@1495:       ui.container{ attr = { class = "mdl-card__title mdl-card--has-fab mdl-card--border" }, content = function ()
bsw@1495: 
bsw@1045:         ui.heading { 
bsw@1495:           attr = { class = "mdl-card__title-text" },
bsw@1495:           level = 2,
bsw@1495:           content = function()
bsw@1495:             ui.link{
bsw@1495:               module = "initiative", view = "show", id = draft.initiative.id,
bsw@1495:               content = draft.initiative.display_name
bsw@1495:             }
bsw@1495:             ui.container{ content = _("Draft revision #{id}", { id = draft.id } ) }
bsw@1495:           end 
bsw@1045:         }
bsw@1495:       end }
bsw@1495: 
bsw@1495:       ui.container{ attr = { class = "draft mdl-card__title mdl-card--border" }, content = function()
bsw@1495:         if config.render_external_reference and config.render_external_reference.draft then
bsw@1495:           config.render_external_reference.draft(draft, function (callback)
bsw@1495:             ui.sectionRow(callback)
bsw@1495:           end)
bsw@1495:         end
bsw@1495:         
bsw@1495:         execute.view{
bsw@1045:           module = "draft",
bsw@1495:           view = "_show",
bsw@1495:           params = { draft = draft, source = source }
bsw@1045:         }
bsw@1495: 
bsw@1495: 
bsw@1495: 
bsw@1495:       end }      
bsw@1495: 
bsw@1495:       if config.attachments then
bsw@1495: 
bsw@1495:         local files = File:new_selector()
bsw@1495:           :left_join("draft_attachment", nil, "draft_attachment.file_id = file.id")
bsw@1495:           :add_where{ "draft_attachment.draft_id = ?", draft.id }
bsw@1495:           :reset_fields()
bsw@1495:           :add_field("file.id")
bsw@1495:           :add_field("draft_attachment.title")
bsw@1495:           :add_field("draft_attachment.description")
bsw@1495:           :add_order_by("draft_attachment.id")
bsw@1495:           :exec()
bsw@1495: 
bsw@1495:         if #files > 0 then
bsw@1495:           ui.container {
bsw@1495:             attr = { class = "mdl-card__content mdl-card--border" },
bsw@1495:             content = function()
bsw@1495:               for i, file in ipairs(files) do
bsw@1495:                 ui.link{ module = "file", view = "show.jpg", id = file.id, content = function()
bsw@1495:                   ui.image{ module = "file", view = "show.jpg", id = file.id, params = { preview = true } }
bsw@1495:                 end }
bsw@1495:                 ui.container{ content = file.title or "" }
bsw@1495:                 ui.container{ content = file.description or "" }
bsw@1495:                 slot.put("
")
bsw@1495:               end
bsw@1495:             end
bsw@1495:           }
bsw@1495:         end
bsw@1045:       end
bsw@1495: 
bsw@1495:       ui.container{ attr = { class = "mdl-card__actions" }, content = function()
bsw@1495:         if source then
bsw@1495:           ui.link{
bsw@1495:             attr = { class = "mdl-button mdl-js-button" },
bsw@1495:             content = _"Rendered",
bsw@1495:             module = "draft",
bsw@1495:             view = "show",
bsw@1495:             id = param.get_id(),
bsw@1495:             params = { source = false }
bsw@1495:           }
bsw@1495:         else
bsw@1495:           ui.link{
bsw@1495:             attr = { class = "mdl-button mdl-js-button" },
bsw@1495:             content = _"Source",
bsw@1495:             module = "draft",
bsw@1495:             view = "show",
bsw@1495:             id = param.get_id(),
bsw@1495:             params = { source = true }
bsw@1495:           }
bsw@1495:         end
bsw@1495:         
bsw@1495:       end }
bsw@1045:     end }
bsw@1495: 
bsw@1495:   end }
bsw@1495: 
bsw@1495:   ui.cell_sidebar{ content = function()
bsw@1495:     if config.logo then
bsw@1495:       config.logo()
bsw@1495:     end
bsw@1495:     execute.view {
bsw@1495:       module = "issue", view = "_sidebar", 
bsw@1495:       params = {
bsw@1495:         issue = draft.initiative.issue,
bsw@1495:         initiative = draft.initiative,
bsw@1495:         member = app.session.member
bsw@1495:       }
bsw@1045:     }
bsw@1495:   end }
bsw@1495: 
bsw@1495: end }