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