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