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