liquid_feedback_frontend
view app/main/initiative/_list_element.lua @ 1856:7d60ede7005e
Allow to hide password reset and login recover feature
| author | bsw | 
|---|---|
| date | Sat Sep 17 21:30:43 2022 +0200 (2022-09-17) | 
| parents | 8d36c14128d4 | 
| children | 
 line source
     1 local initiative = param.get("initiative", "table")
     2 local for_event = param.get("for_event", atom.boolean)
     3 local for_member = param.get("for_member", "table")
     5 local issue = initiative.issue
     7 local position = param.get("position", atom.number)
     9 local class = "initiative mdl-list__item-primary-content"
    10 if initiative.rank == 1 then
    11   class = class .. " rank1"
    12 end
    13 if initiative.revoked then
    14   class = class .. " revoked"
    15 end
    17 ui.container{
    18   attr = { class = class },
    19   content = function ()
    20     if position == 1 and not for_member and (
    21       initiative.issue.state == "finished_with_winner" 
    22       or initiative.issue.state == "finished_without_winner"
    23     ) then
    24       util.initiative_pie(initiative)
    25     end
    26     ui.container {
    27       attr = { class = "initiative_name" },
    28       content = function()
    29         if initiative.vote_grade ~= nil then
    30           if initiative.vote_grade > 0 then
    31             local text = _"voted yes"
    32             ui.container{ attr = { class = "mdl-list__item-avatar positive" }, content = function()
    33               ui.tag{ tag = "i", attr = { class = "material-icons", title = text }, content = "thumb_up" }
    34             end }
    35           elseif initiative.vote_grade == 0 then
    36           elseif initiative.vote_grade < 0 then
    37             local text = _"voted no"
    38             ui.container{ attr = { class = "mdl-list__item-avatar negative" }, content = function()
    39               ui.tag{ tag = "i", attr = { class = "material-icons", title = text }, content = "thumb_down" }
    40             end }
    41           end
    42         end
    43         if not for_member and app.session.member then
    44           if initiative.member_info.supported then
    45             if initiative.member_info.satisfied then
    46               ui.tag{ tag = "i", attr = { id = "lf-initiative__support-" .. initiative.id, class = "material-icons material-icons-small" }, content = "thumb_up" }
    47               --ui.container { attr = { class = "mdl-tooltip", ["for"] = "lf-initiative__support-" .. initiative.id }, content = _"You are supporter of this initiative" }
    48             else
    49               ui.tag{ tag = "i", attr = { id = "lf-initiative__support-" .. initiative.id, class = "material-icons material-icons-small mdl-color-text--orange-500" }, content = "thumb_up" }
    50               --ui.container { attr = { class = "mdl-tooltip", ["for"] = "lf-initiative__support-" .. initiative.id }, content = _"supporter with restricting suggestions" }
    51             end 
    52             slot.put(" ")
    53           end
    54         end
    55         ui.link {
    56           text = initiative.display_name,
    57           module = "initiative", view = "show", id = initiative.id
    58         }
    59       end
    60     }
    61     ui.container{ attr = { class = "mdl-list__item-text-body" }, content = function()
    62       local draft_content = initiative.current_draft.content
    63       if config.initiative_abstract then
    64         local abstract = string.match(draft_content, "(.+)<!%--END_OF_ABSTRACT%-->")
    65         if abstract then
    66           slot.put(abstract)
    67         end
    68       end
    69       if not config.voting_only then
    70         if app.session:has_access("authors_pseudonymous") then
    71           local initiator_members = initiative:get_reference_selector("initiating_members")
    72             :add_field("initiator.accepted", "accepted")
    73             :add_order_by("member.name")
    74             :add_where("initiator.accepted")
    75             :exec()
    77           local initiators = {}
    78           for i, member in ipairs(initiator_members) do
    79             if member.accepted then
    80               initiators[#initiators+1] = member.name
    81             end
    82           end
    83           ui.tag{ content = _"by" }
    84           slot.put(" ")
    85           ui.tag{ content = table.concat(initiators, ", ") }
    86           slot.put("<br />")
    87         end
    88       end
    89       if initiative.rank ~= 1 and (issue.voter_count == nil or issue.voter_count > 0) and not for_event then
    90         if not config.voting_only or issue.closed then
    91           execute.view {
    92             module = "initiative", view = "_bargraph", params = {
    93               initiative = initiative,
    94               battled_initiative = issue.initiatives[1]
    95             }
    96           }
    98           slot.put("   ")
   100           ui.supporter_count(initiative)
   101         end
   102       end
   104       if initiative.positive_votes ~= nil then
   106         local result_text = ""
   108         if issue.voter_count == 0 then
   109           result_text = _("No votes (0)", { result = result })
   111         elseif initiative.rank == 1 and not for_event then
   112           local result = ""
   113           if initiative.eligible then
   114             result = _("Reached #{sign}#{num}/#{den}", {
   115               sign = issue.policy.direct_majority_strict and ">" or "≥",
   116               num = issue.policy.direct_majority_num,
   117               den = issue.policy.direct_majority_den
   118             })
   119           else
   120             result = _("Failed  #{sign}#{num}/#{den}", {
   121               sign = issue.policy.direct_majority_strict and ">" or "≥",
   122               num = issue.policy.direct_majority_num,
   123               den = issue.policy.direct_majority_den
   124             })
   125           end
   126           local neutral_count = issue.voter_count - initiative.positive_votes - initiative.negative_votes
   128           result_text = _("#{result}: #{yes_count} Yes (#{yes_percent}), #{no_count} No (#{no_percent}), #{neutral_count} Abstention (#{neutral_percent})", {
   129             result = result,
   130             yes_count = initiative.positive_votes,
   131             yes_percent = format.percent_floor(initiative.positive_votes, issue.voter_count),
   132             neutral_count = neutral_count,
   133             neutral_percent = format.percent_floor(neutral_count, issue.voter_count),
   134             no_count = initiative.negative_votes,
   135             no_percent = format.percent_floor(initiative.negative_votes, issue.voter_count)
   136           })
   138         end
   140         ui.container { attr = { class = "result" }, content = result_text }
   142       end
   144     end }
   145   end
   146 }
   148 if config.attachments and config.attachments.preview_in_listing then
   150   local file = File:new_selector()
   151     :left_join("draft_attachment", nil, "draft_attachment.file_id = file.id")
   152     :add_where{ "draft_attachment.draft_id = ?", initiative.current_draft.id }
   153     :reset_fields()
   154     :add_field("file.id")
   155     :add_field("draft_attachment.title")
   156     :add_field("draft_attachment.description")
   157     :add_order_by("draft_attachment.id")
   158     :limit(1)
   159     :optional_object_mode()
   160     :exec()
   162   if file then
   163     ui.image{ attr = { class = "attachment" }, module = "file", view = "show.jpg", id = file.id, params = { preview = true } }
   164   end
   165 end
