liquid_feedback_frontend
view app/main/initiative/show.lua @ 1749:c723f01a092f
Fixed mdl class name
| author | bsw | 
|---|---|
| date | Mon Oct 11 10:58:53 2021 +0200 (2021-10-11) | 
| parents | fcf0bc8706f4 | 
| children | 
 line source
     1 local initiative = Initiative:by_id ( param.get_id() )
     2 local member = app.session.member
     4 if not initiative then
     5   execute.view { module = "index", view = "404" }
     6   request.set_status("404 Not Found")
     7   return
     8 end
    10 app.current_initiative = initiative
    12 local issue_info
    14 if member then
    15   initiative:load_everything_for_member_id(member.id)
    16   initiative.issue:load_everything_for_member_id(member.id)
    17   issue_info = initiative.issue.member_info
    18 end
    20 local direct_supporter
    22 if app.session.member_id then
    23   direct_supporter = initiative.issue.member_info.own_participation and initiative.member_info.supported
    24 end
    26 slot.put_into("header", initiative.display_name)
    28 execute.view{ module = "issue", view = "_head", params = { issue = initiative.issue, link_issue = true } }
    30 ui.grid{ content = function()
    32   ui.cell_main{ content = function()
    33     ui.container{ attr = { class = "mdl-card mdl-card__fullwidth mdl-shadow--2dp" }, content = function()
    34       execute.view{
    35         module = "initiative", view = "_head", params = {
    36           initiative = initiative
    37         }
    38       }
    40       if initiative.location and initiative.location.marker_link then
    41         ui.container {
    42           attr = { class = "mdl-card__content mdl-card--no-bottom-pad" },
    43           content = function()
    44             ui.tag{ content = _"This initiative references a FirstLife object." }
    45             slot.put(" ")
    46             ui.link{ external = initiative.location.marker_link, content = _"Open in FirstLife" }
    47           end
    48         }
    49       end
    51       if direct_supporter and not initiative.issue.closed then
    52         local supporter = app.session.member:get_reference_selector("supporters")
    53           :add_where{ "initiative_id = ?", initiative.id }
    54           :optional_object_mode()
    55           :exec()
    57         if supporter then
    59           local old_draft_id = supporter.draft_id
    60           local new_draft_id = initiative.current_draft.id
    62           if old_draft_id ~= new_draft_id then
    63             ui.container {
    64               attr = { class = "mdl-card__content mdl-card--no-bottom-pad mdl-card--notice" },
    65               content = _"The draft of this initiative has been updated!"
    66             }
    67             ui.container {
    68               attr = { class = "mdl-card__actions mdl-card--action-border  mdl-card--notice" },
    69               content = function ()
    70                 if not initiative.revoked then
    71                   ui.link{
    72                     attr = { class = "mdl-button mdl-js-button mdl-button--raised" },
    73                     text   = _"refresh my support",
    74                     module = "initiative",
    75                     action = "add_support",
    76                     id     = initiative.id,
    77                     params = { draft_id = initiative.current_draft.id },
    78                     routing = {
    79                       default = {
    80                         mode = "redirect",
    81                         module = "initiative",
    82                         view = "show",
    83                         id = initiative.id
    84                       }
    85                     }
    86                   }
    87                   slot.put("   ")
    88                   ui.link{
    89                     attr = { class = "mdl-button mdl-js-button mdl-button--raised" },
    90                     content = _"show differences",
    91                     module = "draft",
    92                     view = "diff",
    93                     params = {
    94                       old_draft_id = old_draft_id,
    95                       new_draft_id = new_draft_id
    96                     }
    97                   }
    98                   slot.put("   ")
    99                 end
   100                 ui.link{
   101                   attr = { class = "mdl-button mdl-js-button mdl-button--raised" },
   102                   text   = _"remove my support",
   103                   module = "initiative",
   104                   action = "remove_support",
   105                   id     = initiative.id,
   106                   routing = {
   107                     default = {
   108                       mode = "redirect",
   109                       module = "initiative",
   110                       view = "show",
   111                       id = initiative.id
   112                     }
   113                   }
   114                 }
   116               end
   117             }
   118           end
   119         end
   120       end
   122       if config.render_external_reference and config.render_external_reference.initiative then
   123         config.render_external_reference.initiative(initiative, function (callback)
   124           ui.sectionRow(callback)
   125         end)
   126       end
   127       local draft_content = initiative.current_draft.content
   128       if config.initiative_abstract then
   129         local abstract = string.match(draft_content, "(.+)<!%--END_OF_ABSTRACT%-->")
   130         if abstract then
   131           draft_content = string.match(draft_content, "<!%--END_OF_ABSTRACT%-->(.*)")
   132         end
   133       end
   134       ui.container {
   135         attr = { class = "draft mdl-card__content mdl-card--border" },
   136         content = function ()
   137           if initiative.current_draft.formatting_engine == "html" or not initiative.current_draft.formatting_engine then
   138             if config.draft_filter then
   139               slot.put(config.draft_filter(draft_content))
   140             else
   141               slot.put(draft_content)
   142             end
   143           else
   144             slot.put ( initiative.current_draft:get_content ( "html" ) )
   145           end
   146         end
   147       }
   149       if config.attachments then
   151         local files = File:new_selector()
   152           :left_join("draft_attachment", nil, "draft_attachment.file_id = file.id")
   153           :add_where{ "draft_attachment.draft_id = ?", initiative.current_draft.id }
   154           :reset_fields()
   155           :add_field("file.id")
   156           :add_field("draft_attachment.title")
   157           :add_field("draft_attachment.description")
   158           :add_order_by("draft_attachment.id")
   159           :exec()
   161         if #files > 0 then
   162           ui.container {
   163             attr = { class = "mdl-card__content mdl-card--border attachments" },
   164             content = function()
   165               for i, file in ipairs(files) do
   166                 ui.link{ module = "file", view = "show.jpg", id = file.id, content = function()
   167                   ui.image{ module = "file", view = "show.jpg", id = file.id, params = { preview = true } }
   168                 end }
   169                 ui.container{ content = function()
   170                   ui.tag{ tag = "strong", content = file.title or "" }
   171                 end }
   172                 ui.container{ content = file.description or "" }
   173               end
   174             end
   175           }
   176         end
   177       end
   179       local drafts_count = initiative:get_reference_selector("drafts"):count()
   181       if not config.voting_only then
   182         ui.container {
   183           attr = { class = "mdl-card__actions" },
   184           content = function()
   185             ui.link{
   186               attr = { class = "mdl-button mdl-js-button" },
   187               module = "initiative", view = "history", id = initiative.id,
   188               content = _("draft history (#{count})", { count = drafts_count })
   189             }
   190           end
   191         }
   192       end
   194     end }
   196     execute.view{ module = "initiative", view = "_suggestions", params = { initiative = initiative } }
   198   end }
   200   ui.cell_sidebar{ content = function()
   201     if config.logo then
   202       config.logo()
   203     end
   205     execute.view {
   206       module = "issue", view = "_sidebar", 
   207       params = {
   208         issue = initiative.issue,
   209         initiative = initiative,
   210         member = app.session.member
   211       }
   212     }
   214     execute.view {
   215       module = "issue", view = "_sidebar_whatcanido", 
   216       params = {
   217         issue = initiative.issue,
   218         initiative = initiative,
   219         member = app.session.member
   220       }
   221     }
   223     execute.view { 
   224       module = "issue", view = "_sidebar_members", params = {
   225         issue = initiative.issue, initiative = initiative
   226       }
   227     }
   229   end }
   231 end }
