| rev | 
   line source | 
| 
bsw/jbe@19
 | 
     1 local initiative = param.get("initiative", "table")
 | 
| 
bsw/jbe@19
 | 
     2 local initiator = param.get("initiator", "table")
 | 
| 
bsw/jbe@19
 | 
     3 
 | 
| 
bsw@272
 | 
     4 local initiators_members_selector = initiative:get_reference_selector("initiating_members")
 | 
| 
bsw@272
 | 
     5   :add_field("initiator.accepted", "accepted")
 | 
| 
bsw@272
 | 
     6 
 | 
| 
bsw@272
 | 
     7 if not (initiator and initiator.accepted) then
 | 
| 
bsw@272
 | 
     8   initiators_members_selector:add_where("initiator.accepted")
 | 
| 
bsw@272
 | 
     9 end
 | 
| 
bsw@272
 | 
    10 
 | 
| 
bsw@272
 | 
    11 local initiators = initiators_members_selector:exec()
 | 
| 
bsw@272
 | 
    12 
 | 
| 
bsw@274
 | 
    13 
 | 
| 
bsw@274
 | 
    14 local initiatives_selector = initiative.issue:get_reference_selector("initiatives")
 | 
| 
bsw@274
 | 
    15 slot.select("initiatives_list", function()
 | 
| 
bsw@274
 | 
    16   execute.view{
 | 
| 
bsw@274
 | 
    17     module = "initiative",
 | 
| 
bsw@274
 | 
    18     view = "_list",
 | 
| 
bsw@274
 | 
    19     params = {
 | 
| 
bsw@274
 | 
    20       issue = initiative.issue,
 | 
| 
bsw@274
 | 
    21       initiatives_selector = initiatives_selector,
 | 
| 
bsw@274
 | 
    22       no_sort = true, highlight_initiative = initiative, limit = 3
 | 
| 
bsw@274
 | 
    23     }
 | 
| 
bsw@274
 | 
    24   }
 | 
| 
bsw@274
 | 
    25 end)
 | 
| 
bsw@274
 | 
    26 
 | 
| 
bsw@272
 | 
    27 slot.select("initiative_head", function()
 | 
| 
bsw@272
 | 
    28 
 | 
| 
bsw@272
 | 
    29   ui.container{
 | 
| 
bsw@272
 | 
    30     attr = { class = "initiative_name" },
 | 
| 
bsw@272
 | 
    31     content = _("Initiative i#{id}: #{name}", { id = initiative.id, name = initiative.name })
 | 
| 
bsw@272
 | 
    32   }
 | 
| 
bsw@276
 | 
    33   if app.session.member_id or config.public_access == "pseudonym" or config.public_access == "full" then
 | 
| 
bsw@276
 | 
    34     ui.tag{
 | 
| 
bsw@276
 | 
    35       attr = { class = "initiator_names" },
 | 
| 
bsw@276
 | 
    36       content = function()
 | 
| 
bsw@276
 | 
    37         ui.tag{ content = _"by" }
 | 
| 
bsw@276
 | 
    38         slot.put(" ")
 | 
| 
bsw@276
 | 
    39         for i, initiator in ipairs(initiators) do
 | 
| 
bsw@276
 | 
    40           if i == #initiators and i > 1 then
 | 
| 
bsw@276
 | 
    41             slot.put(" ", _"and", " ")
 | 
| 
bsw@276
 | 
    42           elseif i > 1 then
 | 
| 
bsw@276
 | 
    43             slot.put(", ")
 | 
| 
bsw@276
 | 
    44           end
 | 
| 
bsw@276
 | 
    45           ui.link{
 | 
| 
bsw@276
 | 
    46             text = initiator.name,
 | 
| 
bsw@276
 | 
    47             module = "member", view = "show", id = initiator.id
 | 
| 
bsw@276
 | 
    48           }
 | 
| 
bsw@272
 | 
    49         end
 | 
| 
bsw@272
 | 
    50       end
 | 
| 
bsw@276
 | 
    51     }
 | 
| 
bsw@276
 | 
    52   end
 | 
| 
bsw@272
 | 
    53 
 | 
| 
bsw@272
 | 
    54   if initiator and initiator.accepted and not initiative.issue.fully_frozen and not initiative.issue.closed and not initiative.revoked then
 | 
| 
bsw@272
 | 
    55     slot.put(" · ")
 | 
| 
bsw@272
 | 
    56     ui.link{
 | 
| 
bsw@272
 | 
    57       attr = { class = "action" },
 | 
| 
bsw@272
 | 
    58       content = function()
 | 
| 
bsw@272
 | 
    59         slot.put(_"Invite initiator")
 | 
| 
bsw@272
 | 
    60       end,
 | 
| 
bsw@272
 | 
    61       module = "initiative",
 | 
| 
bsw@272
 | 
    62       view = "add_initiator",
 | 
| 
bsw@272
 | 
    63       params = { initiative_id = initiative.id }
 | 
| 
bsw@272
 | 
    64     }
 | 
| 
bsw@272
 | 
    65     if #initiators > 1 then
 | 
| 
bsw@272
 | 
    66       slot.put(" · ")
 | 
| 
bsw@272
 | 
    67       ui.link{
 | 
| 
bsw@272
 | 
    68         content = function()
 | 
| 
bsw@272
 | 
    69           slot.put(_"Remove initiator")
 | 
| 
bsw@272
 | 
    70         end,
 | 
| 
bsw@272
 | 
    71         module = "initiative",
 | 
| 
bsw@272
 | 
    72         view = "remove_initiator",
 | 
| 
bsw@272
 | 
    73         params = { initiative_id = initiative.id }
 | 
| 
bsw@272
 | 
    74       }
 | 
| 
bsw@272
 | 
    75     end
 | 
| 
bsw@272
 | 
    76   end
 | 
| 
bsw@272
 | 
    77   if initiator and initiator.accepted == false then
 | 
| 
bsw@272
 | 
    78       slot.put(" · ")
 | 
| 
bsw@272
 | 
    79       ui.link{
 | 
| 
bsw@272
 | 
    80         text   = _"Cancel refuse of invitation",
 | 
| 
bsw@272
 | 
    81         module = "initiative",
 | 
| 
bsw@272
 | 
    82         action = "remove_initiator",
 | 
| 
bsw@272
 | 
    83         params = {
 | 
| 
bsw@272
 | 
    84           initiative_id = initiative.id,
 | 
| 
bsw@272
 | 
    85           member_id = app.session.member.id
 | 
| 
bsw@272
 | 
    86         },
 | 
| 
bsw@272
 | 
    87         routing = {
 | 
| 
bsw@272
 | 
    88           ok = {
 | 
| 
bsw@272
 | 
    89             mode = "redirect",
 | 
| 
bsw@272
 | 
    90             module = "initiative",
 | 
| 
bsw@272
 | 
    91             view = "show",
 | 
| 
bsw@272
 | 
    92             id = initiative.id
 | 
| 
bsw@272
 | 
    93           }
 | 
| 
bsw@272
 | 
    94         }
 | 
| 
bsw@272
 | 
    95       }
 | 
| 
bsw@272
 | 
    96   end
 | 
| 
bsw@272
 | 
    97 
 | 
| 
bsw@272
 | 
    98   
 | 
| 
bsw@272
 | 
    99 end )
 | 
| 
bsw@272
 | 
   100   
 | 
| 
bsw/jbe@19
 | 
   101 util.help("initiative.show")
 | 
| 
bsw/jbe@19
 | 
   102 
 | 
| 
bsw@272
 | 
   103 
 | 
| 
bsw/jbe@19
 | 
   104 if initiative.issue.ranks_available and initiative.admitted then
 | 
| 
bsw/jbe@19
 | 
   105   local class = initiative.rank == 1 and "admitted_info" or "not_admitted_info"
 | 
| 
bsw/jbe@19
 | 
   106   ui.container{
 | 
| 
bsw/jbe@19
 | 
   107     attr = { class = class },
 | 
| 
bsw/jbe@19
 | 
   108     content = function()
 | 
| 
bsw/jbe@19
 | 
   109       local max_value = initiative.issue.voter_count
 | 
| 
bsw/jbe@19
 | 
   110       slot.put(" ")
 | 
| 
bsw/jbe@19
 | 
   111       local positive_votes = initiative.positive_votes
 | 
| 
bsw/jbe@19
 | 
   112       local negative_votes = initiative.negative_votes
 | 
| 
jorges@104
 | 
   113       local sum_votes = initiative.positive_votes + initiative.negative_votes
 | 
| 
poelzi@167
 | 
   114       local function perc(votes, sum)
 | 
| 
poelzi@167
 | 
   115         if sum > 0 and votes > 0 then return " (" .. string.format( "%.f", votes * 100 / sum ) .. "%)" end
 | 
| 
poelzi@167
 | 
   116         return ""
 | 
| 
poelzi@167
 | 
   117       end
 | 
| 
poelzi@167
 | 
   118       slot.put(_"Yes" .. ": <b>" .. tostring(positive_votes) .. perc(positive_votes, sum_votes) .. "</b>")
 | 
| 
bsw/jbe@19
 | 
   119       slot.put(" · ")
 | 
| 
bsw/jbe@19
 | 
   120       slot.put(_"Abstention" .. ": <b>" .. tostring(max_value - initiative.negative_votes - initiative.positive_votes)  .. "</b>")
 | 
| 
bsw/jbe@19
 | 
   121       slot.put(" · ")
 | 
| 
poelzi@167
 | 
   122       slot.put(_"No" .. ": <b>" .. tostring(initiative.negative_votes) .. perc(negative_votes, sum_votes) .. "</b>")
 | 
| 
bsw/jbe@19
 | 
   123       slot.put(" · ")
 | 
| 
bsw/jbe@19
 | 
   124       slot.put("<b>")
 | 
| 
bsw/jbe@19
 | 
   125       if initiative.rank == 1 then
 | 
| 
bsw/jbe@19
 | 
   126         slot.put(_"Approved")
 | 
| 
bsw/jbe@19
 | 
   127       elseif initiative.rank then
 | 
| 
bsw/jbe@19
 | 
   128         slot.put(_("Not approved (rank #{rank})", { rank = initiative.rank }))
 | 
| 
bsw@24
 | 
   129       else
 | 
| 
bsw@24
 | 
   130         slot.put(_"Not approved")
 | 
| 
bsw/jbe@19
 | 
   131       end
 | 
| 
bsw/jbe@19
 | 
   132       slot.put("</b>")
 | 
| 
bsw/jbe@19
 | 
   133     end
 | 
| 
bsw/jbe@19
 | 
   134   }
 | 
| 
bsw/jbe@19
 | 
   135 end
 | 
| 
bsw/jbe@19
 | 
   136 
 | 
| 
bsw/jbe@19
 | 
   137 if initiative.admitted == false then
 | 
| 
bsw/jbe@19
 | 
   138   local policy = initiative.issue.policy
 | 
| 
bsw/jbe@19
 | 
   139   ui.container{
 | 
| 
bsw/jbe@19
 | 
   140     attr = { class = "not_admitted_info" },
 | 
| 
bsw/jbe@19
 | 
   141     content = _("This initiative has not been admitted! It failed the quorum of #{quorum}.", { quorum = format.percentage(policy.initiative_quorum_num / policy.initiative_quorum_den) })
 | 
| 
bsw/jbe@19
 | 
   142   }
 | 
| 
bsw/jbe@19
 | 
   143 end
 | 
| 
bsw/jbe@19
 | 
   144 
 | 
| 
bsw@278
 | 
   145 if initiative.issue.state == "cancelled" then
 | 
| 
bsw/jbe@19
 | 
   146   local policy = initiative.issue.policy
 | 
| 
bsw/jbe@19
 | 
   147   ui.container{
 | 
| 
bsw/jbe@19
 | 
   148     attr = { class = "not_admitted_info" },
 | 
| 
bsw/jbe@19
 | 
   149     content = _("This issue has been cancelled. It failed the quorum of #{quorum}.", { quorum = format.percentage(policy.issue_quorum_num / policy.issue_quorum_den) })
 | 
| 
bsw/jbe@19
 | 
   150   }
 | 
| 
bsw/jbe@19
 | 
   151 end
 | 
| 
bsw/jbe@19
 | 
   152 
 | 
| 
bsw/jbe@19
 | 
   153 if initiative.revoked then
 | 
| 
bsw/jbe@19
 | 
   154   ui.container{
 | 
| 
bsw/jbe@19
 | 
   155     attr = { class = "revoked_info" },
 | 
| 
bsw/jbe@19
 | 
   156     content = function()
 | 
| 
bsw/jbe@19
 | 
   157       slot.put(_("This initiative has been revoked at #{revoked}", { revoked = format.timestamp(initiative.revoked) }))
 | 
| 
bsw/jbe@19
 | 
   158       local suggested_initiative = initiative.suggested_initiative
 | 
| 
bsw/jbe@19
 | 
   159       if suggested_initiative then
 | 
| 
bsw/jbe@19
 | 
   160         slot.put("<br /><br />")
 | 
| 
bsw/jbe@19
 | 
   161         slot.put(_("The initiators suggest to support the following initiative:"))
 | 
| 
bsw/jbe@19
 | 
   162         slot.put(" ")
 | 
| 
bsw/jbe@19
 | 
   163         ui.link{
 | 
| 
bsw/jbe@19
 | 
   164           content = _("Issue ##{id}", { id = suggested_initiative.issue.id } ) .. ": " .. encode.html(suggested_initiative.name),
 | 
| 
bsw/jbe@19
 | 
   165           module = "initiative",
 | 
| 
bsw/jbe@19
 | 
   166           view = "show",
 | 
| 
bsw/jbe@19
 | 
   167           id = suggested_initiative.id
 | 
| 
bsw/jbe@19
 | 
   168         }
 | 
| 
bsw/jbe@19
 | 
   169       end
 | 
| 
bsw/jbe@19
 | 
   170     end
 | 
| 
bsw/jbe@19
 | 
   171   }
 | 
| 
bsw/jbe@19
 | 
   172 end
 | 
| 
bsw/jbe@19
 | 
   173 
 | 
| 
bsw@41
 | 
   174 if initiator and initiator.accepted == nil and not initiative.issue.half_frozen and not initiative.issue.closed then
 | 
| 
bsw/jbe@19
 | 
   175   ui.container{
 | 
| 
bsw/jbe@19
 | 
   176     attr = { class = "initiator_invite_info" },
 | 
| 
bsw/jbe@19
 | 
   177     content = function()
 | 
| 
bsw/jbe@19
 | 
   178       slot.put(_"You are invited to become initiator of this initiative.")
 | 
| 
bsw/jbe@19
 | 
   179       slot.put(" ")
 | 
| 
bsw/jbe@19
 | 
   180       ui.link{
 | 
| 
bsw/jbe@19
 | 
   181         image  = { static = "icons/16/tick.png" },
 | 
| 
bsw/jbe@19
 | 
   182         text   = _"Accept invitation",
 | 
| 
bsw/jbe@19
 | 
   183         module = "initiative",
 | 
| 
bsw/jbe@19
 | 
   184         action = "accept_invitation",
 | 
| 
bsw/jbe@19
 | 
   185         id     = initiative.id,
 | 
| 
bsw/jbe@19
 | 
   186         routing = {
 | 
| 
bsw/jbe@19
 | 
   187           default = {
 | 
| 
bsw/jbe@19
 | 
   188             mode = "redirect",
 | 
| 
bsw/jbe@19
 | 
   189             module = request.get_module(),
 | 
| 
bsw/jbe@19
 | 
   190             view = request.get_view(),
 | 
| 
bsw/jbe@19
 | 
   191             id = param.get_id_cgi(),
 | 
| 
bsw/jbe@19
 | 
   192             params = param.get_all_cgi()
 | 
| 
bsw/jbe@19
 | 
   193           }
 | 
| 
bsw/jbe@19
 | 
   194         }
 | 
| 
bsw/jbe@19
 | 
   195       }
 | 
| 
bsw/jbe@19
 | 
   196       slot.put(" ")
 | 
| 
bsw/jbe@19
 | 
   197       ui.link{
 | 
| 
bsw/jbe@19
 | 
   198         image  = { static = "icons/16/cross.png" },
 | 
| 
bsw/jbe@19
 | 
   199         text   = _"Refuse invitation",
 | 
| 
bsw/jbe@19
 | 
   200         module = "initiative",
 | 
| 
bsw/jbe@19
 | 
   201         action = "reject_initiator_invitation",
 | 
| 
bsw/jbe@19
 | 
   202         params = {
 | 
| 
bsw/jbe@19
 | 
   203           initiative_id = initiative.id,
 | 
| 
bsw/jbe@19
 | 
   204           member_id = app.session.member.id
 | 
| 
bsw/jbe@19
 | 
   205         },
 | 
| 
bsw/jbe@19
 | 
   206         routing = {
 | 
| 
bsw/jbe@19
 | 
   207           default = {
 | 
| 
bsw/jbe@19
 | 
   208             mode = "redirect",
 | 
| 
bsw/jbe@19
 | 
   209             module = request.get_module(),
 | 
| 
bsw/jbe@19
 | 
   210             view = request.get_view(),
 | 
| 
bsw/jbe@19
 | 
   211             id = param.get_id_cgi(),
 | 
| 
bsw/jbe@19
 | 
   212             params = param.get_all_cgi()
 | 
| 
bsw/jbe@19
 | 
   213           }
 | 
| 
bsw/jbe@19
 | 
   214         }
 | 
| 
bsw/jbe@19
 | 
   215       }
 | 
| 
bsw/jbe@19
 | 
   216     end
 | 
| 
bsw/jbe@19
 | 
   217   }
 | 
| 
bsw/jbe@19
 | 
   218   slot.put("<br />")
 | 
| 
bsw/jbe@19
 | 
   219 end
 | 
| 
bsw/jbe@19
 | 
   220 
 | 
| 
bsw/jbe@19
 | 
   221 
 | 
| 
bsw@51
 | 
   222 local supporter
 | 
| 
bsw@51
 | 
   223 
 | 
| 
bsw@51
 | 
   224 if app.session.member_id then
 | 
| 
bsw@51
 | 
   225   supporter = app.session.member:get_reference_selector("supporters")
 | 
| 
bsw@51
 | 
   226     :add_where{ "initiative_id = ?", initiative.id }
 | 
| 
bsw@51
 | 
   227     :optional_object_mode()
 | 
| 
bsw@51
 | 
   228     :exec()
 | 
| 
bsw@51
 | 
   229 end
 | 
| 
bsw/jbe@19
 | 
   230 
 | 
| 
bsw/jbe@19
 | 
   231 if supporter and not initiative.issue.closed then
 | 
| 
bsw/jbe@19
 | 
   232   local old_draft_id = supporter.draft_id
 | 
| 
bsw/jbe@19
 | 
   233   local new_draft_id = initiative.current_draft.id
 | 
| 
bsw/jbe@19
 | 
   234   if old_draft_id ~= new_draft_id then
 | 
| 
bsw/jbe@19
 | 
   235     ui.container{
 | 
| 
bsw/jbe@19
 | 
   236       attr = { class = "draft_updated_info" },
 | 
| 
bsw/jbe@19
 | 
   237       content = function()
 | 
| 
bsw/jbe@19
 | 
   238         slot.put(_"The draft of this initiative has been updated!")
 | 
| 
bsw/jbe@19
 | 
   239         slot.put(" ")
 | 
| 
bsw/jbe@19
 | 
   240         ui.link{
 | 
| 
bsw/jbe@19
 | 
   241           content = _"Show diff",
 | 
| 
bsw/jbe@19
 | 
   242           module = "draft",
 | 
| 
bsw/jbe@19
 | 
   243           view = "diff",
 | 
| 
bsw/jbe@19
 | 
   244           params = {
 | 
| 
bsw/jbe@19
 | 
   245             old_draft_id = old_draft_id,
 | 
| 
bsw/jbe@19
 | 
   246             new_draft_id = new_draft_id
 | 
| 
bsw/jbe@19
 | 
   247           }
 | 
| 
bsw/jbe@19
 | 
   248         }
 | 
| 
bsw@75
 | 
   249         if not initiative.revoked then
 | 
| 
bsw@75
 | 
   250           slot.put(" ")
 | 
| 
bsw@75
 | 
   251           ui.link{
 | 
| 
bsw@75
 | 
   252             text   = _"Refresh support to current draft",
 | 
| 
bsw@75
 | 
   253             module = "initiative",
 | 
| 
bsw@75
 | 
   254             action = "add_support",
 | 
| 
bsw@75
 | 
   255             id     = initiative.id,
 | 
| 
bsw@75
 | 
   256             routing = {
 | 
| 
bsw@75
 | 
   257               default = {
 | 
| 
bsw@75
 | 
   258                 mode = "redirect",
 | 
| 
bsw@75
 | 
   259                 module = "initiative",
 | 
| 
bsw@75
 | 
   260                 view = "show",
 | 
| 
bsw@75
 | 
   261                 id = initiative.id
 | 
| 
bsw@75
 | 
   262               }
 | 
| 
bsw/jbe@19
 | 
   263             }
 | 
| 
bsw/jbe@19
 | 
   264           }
 | 
| 
bsw@75
 | 
   265         end
 | 
| 
bsw/jbe@19
 | 
   266       end
 | 
| 
bsw/jbe@19
 | 
   267     }
 | 
| 
bsw/jbe@19
 | 
   268   end
 | 
| 
bsw/jbe@19
 | 
   269 end
 | 
| 
bsw/jbe@19
 | 
   270 
 | 
| 
bsw/jbe@19
 | 
   271 
 | 
| 
bsw@51
 | 
   272 if app.session.member_id then
 | 
| 
bsw@278
 | 
   273   execute.view{
 | 
| 
bsw@278
 | 
   274     module = "supporter",
 | 
| 
bsw@278
 | 
   275     view = "_show_box",
 | 
| 
bsw@278
 | 
   276     params = {
 | 
| 
bsw@278
 | 
   277       initiative = initiative
 | 
| 
bsw@278
 | 
   278     }
 | 
| 
bsw@51
 | 
   279   }
 | 
| 
bsw@51
 | 
   280 end
 | 
| 
bsw/jbe@19
 | 
   281 
 | 
| 
bsw/jbe@19
 | 
   282 execute.view{
 | 
| 
bsw/jbe@19
 | 
   283   module = "initiative",
 | 
| 
bsw/jbe@19
 | 
   284   view = "show_tab",
 | 
| 
bsw/jbe@19
 | 
   285   params = {
 | 
| 
bsw/jbe@19
 | 
   286     initiative = initiative,
 | 
| 
bsw/jbe@19
 | 
   287     initiator = initiator
 | 
| 
bsw/jbe@19
 | 
   288   }
 | 
| 
bsw/jbe@19
 | 
   289 }
 | 
| 
bsw/jbe@19
 | 
   290 
 |