| rev | 
   line source | 
| 
bsw@725
 | 
     1 local initiative = param.get("initiative", "table")
 | 
| 
bsw@725
 | 
     2 
 | 
| 
bsw@725
 | 
     3 local show_as_head = param.get("show_as_head", atom.boolean)
 | 
| 
bsw@725
 | 
     4 
 | 
| 
bsw@725
 | 
     5 initiative:load_everything_for_member_id(app.session.member_id)
 | 
| 
bsw@725
 | 
     6 
 | 
| 
bsw@725
 | 
     7 local issue = initiative.issue
 | 
| 
bsw@725
 | 
     8 
 | 
| 
bsw@725
 | 
     9 -- TODO performance
 | 
| 
bsw@725
 | 
    10 local initiator
 | 
| 
bsw@725
 | 
    11 if app.session.member_id then
 | 
| 
bsw@725
 | 
    12   initiator = Initiator:by_pk(initiative.id, app.session.member.id)
 | 
| 
bsw@725
 | 
    13 end
 | 
| 
bsw@725
 | 
    14 
 | 
| 
bsw@725
 | 
    15 if app.session.member_id then
 | 
| 
bsw@725
 | 
    16   issue:load_everything_for_member_id(app.session.member_id)
 | 
| 
bsw@725
 | 
    17 end
 | 
| 
bsw@725
 | 
    18 
 | 
| 
bsw@725
 | 
    19 app.html_title.title = initiative.name
 | 
| 
bsw@725
 | 
    20 app.html_title.subtitle = _("Initiative ##{id}", { id = initiative.id })
 | 
| 
bsw@725
 | 
    21 
 | 
| 
bsw@725
 | 
    22 slot.select("head", function()
 | 
| 
bsw@725
 | 
    23   execute.view{
 | 
| 
bsw@725
 | 
    24     module = "issue", view = "_head",
 | 
| 
bsw@725
 | 
    25     params = { issue = issue, initiative = initiative }
 | 
| 
bsw@725
 | 
    26   }
 | 
| 
bsw@725
 | 
    27 end)
 | 
| 
bsw@725
 | 
    28   
 | 
| 
bsw@725
 | 
    29 local initiators_members_selector = initiative:get_reference_selector("initiating_members")
 | 
| 
bsw@725
 | 
    30   :add_field("initiator.accepted", "accepted")
 | 
| 
bsw@725
 | 
    31   :add_order_by("member.name")
 | 
| 
bsw@725
 | 
    32 if initiator and initiator.accepted then
 | 
| 
bsw@725
 | 
    33   initiators_members_selector:add_where("initiator.accepted ISNULL OR initiator.accepted")
 | 
| 
bsw@725
 | 
    34 else
 | 
| 
bsw@725
 | 
    35   initiators_members_selector:add_where("initiator.accepted")
 | 
| 
bsw@725
 | 
    36 end
 | 
| 
bsw@725
 | 
    37 
 | 
| 
bsw@725
 | 
    38 local initiators = initiators_members_selector:exec()
 | 
| 
bsw@725
 | 
    39 
 | 
| 
bsw@725
 | 
    40 
 | 
| 
bsw@725
 | 
    41 local initiatives_selector = initiative.issue:get_reference_selector("initiatives")
 | 
| 
bsw@725
 | 
    42 slot.select("head", function()
 | 
| 
bsw@725
 | 
    43   execute.view{
 | 
| 
bsw@725
 | 
    44     module = "issue",
 | 
| 
bsw@725
 | 
    45     view = "_show",
 | 
| 
bsw@725
 | 
    46     params = {
 | 
| 
bsw@725
 | 
    47       issue = initiative.issue,
 | 
| 
bsw@725
 | 
    48       initiative_limit = 3,
 | 
| 
bsw@725
 | 
    49       for_initiative = initiative
 | 
| 
bsw@725
 | 
    50     }
 | 
| 
bsw@725
 | 
    51   }
 | 
| 
bsw@725
 | 
    52 end)
 | 
| 
bsw@725
 | 
    53 
 | 
| 
bsw@725
 | 
    54 util.help("initiative.show")
 | 
| 
bsw@725
 | 
    55 
 | 
| 
bsw@725
 | 
    56 ui.container{ attr = { class = "initiative_head" }, content = function()
 | 
| 
bsw@725
 | 
    57 
 | 
| 
bsw@725
 | 
    58   local text = _("Initiative i#{id}: #{name}", { id = initiative.id, name = initiative.name }) 
 | 
| 
bsw@725
 | 
    59   if show_as_head then
 | 
| 
bsw@725
 | 
    60     ui.link{
 | 
| 
bsw@725
 | 
    61       attr = { class = "title" }, text = text,
 | 
| 
bsw@725
 | 
    62       module = "initiative", view = "show", id = initiative.id
 | 
| 
bsw@725
 | 
    63     }
 | 
| 
bsw@725
 | 
    64   else
 | 
| 
bsw@725
 | 
    65     ui.container{ attr = { class = "title" }, content = text }
 | 
| 
bsw@725
 | 
    66   end
 | 
| 
bsw@813
 | 
    67   if app.session:has_access("authors_pseudonymous") then
 | 
| 
bsw@727
 | 
    68     ui.container{ attr = { class = "content" }, content = function()
 | 
| 
bsw@725
 | 
    69       ui.tag{
 | 
| 
bsw@725
 | 
    70         attr = { class = "initiator_names" },
 | 
| 
bsw@725
 | 
    71         content = function()
 | 
| 
bsw@725
 | 
    72           for i, initiator in ipairs(initiators) do
 | 
| 
bsw@725
 | 
    73             slot.put(" ")
 | 
| 
bsw@813
 | 
    74             if app.session:has_access("all_pseudonymous") then
 | 
| 
bsw@725
 | 
    75               ui.link{
 | 
| 
bsw@725
 | 
    76                 content = function ()
 | 
| 
bsw@725
 | 
    77                   execute.view{
 | 
| 
bsw@725
 | 
    78                     module = "member_image",
 | 
| 
bsw@725
 | 
    79                     view = "_show",
 | 
| 
bsw@725
 | 
    80                     params = {
 | 
| 
bsw@725
 | 
    81                       member = initiator,
 | 
| 
bsw@725
 | 
    82                       image_type = "avatar",
 | 
| 
bsw@725
 | 
    83                       show_dummy = true,
 | 
| 
bsw@725
 | 
    84                       class = "micro_avatar",
 | 
| 
bsw@725
 | 
    85                       popup_text = text
 | 
| 
bsw@725
 | 
    86                     }
 | 
| 
bsw@725
 | 
    87                   }
 | 
| 
bsw@725
 | 
    88                 end,
 | 
| 
bsw@725
 | 
    89                 module = "member", view = "show", id = initiator.id
 | 
| 
bsw@725
 | 
    90               }
 | 
| 
bsw@725
 | 
    91               slot.put(" ")
 | 
| 
bsw@725
 | 
    92             end
 | 
| 
bsw@725
 | 
    93             ui.link{
 | 
| 
bsw@725
 | 
    94               text = initiator.name,
 | 
| 
bsw@725
 | 
    95               module = "member", view = "show", id = initiator.id
 | 
| 
bsw@725
 | 
    96             }
 | 
| 
bsw@725
 | 
    97             if not initiator.accepted then
 | 
| 
bsw@725
 | 
    98               ui.tag{ attr = { title = _"Not accepted yet" }, content = "?" }
 | 
| 
bsw@725
 | 
    99             end
 | 
| 
bsw@725
 | 
   100           end
 | 
| 
bsw@725
 | 
   101           if initiator and initiator.accepted and not initiative.issue.fully_frozen and not initiative.issue.closed and not initiative.revoked then
 | 
| 
bsw@725
 | 
   102             slot.put(" · ")
 | 
| 
bsw@725
 | 
   103             ui.link{
 | 
| 
bsw@725
 | 
   104               attr = { class = "action" },
 | 
| 
bsw@725
 | 
   105               content = function()
 | 
| 
bsw@725
 | 
   106                 slot.put(_"Invite initiator")
 | 
| 
bsw@725
 | 
   107               end,
 | 
| 
bsw@725
 | 
   108               module = "initiative",
 | 
| 
bsw@725
 | 
   109               view = "add_initiator",
 | 
| 
bsw@725
 | 
   110               params = { initiative_id = initiative.id }
 | 
| 
bsw@725
 | 
   111             }
 | 
| 
bsw@725
 | 
   112             if #initiators > 1 then
 | 
| 
bsw@725
 | 
   113               slot.put(" · ")
 | 
| 
bsw@725
 | 
   114               ui.link{
 | 
| 
bsw@725
 | 
   115                 content = function()
 | 
| 
bsw@725
 | 
   116                   slot.put(_"Remove initiator")
 | 
| 
bsw@725
 | 
   117                 end,
 | 
| 
bsw@725
 | 
   118                 module = "initiative",
 | 
| 
bsw@725
 | 
   119                 view = "remove_initiator",
 | 
| 
bsw@725
 | 
   120                 params = { initiative_id = initiative.id }
 | 
| 
bsw@725
 | 
   121               }
 | 
| 
bsw@725
 | 
   122             end
 | 
| 
bsw@725
 | 
   123           end
 | 
| 
bsw@725
 | 
   124           if initiator and initiator.accepted == false then
 | 
| 
bsw@725
 | 
   125               slot.put(" · ")
 | 
| 
bsw@725
 | 
   126               ui.link{
 | 
| 
bsw@725
 | 
   127                 text   = _"Cancel refuse of invitation",
 | 
| 
bsw@725
 | 
   128                 module = "initiative",
 | 
| 
bsw@725
 | 
   129                 action = "remove_initiator",
 | 
| 
bsw@725
 | 
   130                 params = {
 | 
| 
bsw@725
 | 
   131                   initiative_id = initiative.id,
 | 
| 
bsw@725
 | 
   132                   member_id = app.session.member.id
 | 
| 
bsw@725
 | 
   133                 },
 | 
| 
bsw@725
 | 
   134                 routing = {
 | 
| 
bsw@725
 | 
   135                   ok = {
 | 
| 
bsw@725
 | 
   136                     mode = "redirect",
 | 
| 
bsw@725
 | 
   137                     module = "initiative",
 | 
| 
bsw@725
 | 
   138                     view = "show",
 | 
| 
bsw@725
 | 
   139                     id = initiative.id
 | 
| 
bsw@725
 | 
   140                   }
 | 
| 
bsw@725
 | 
   141                 }
 | 
| 
bsw@725
 | 
   142               }
 | 
| 
bsw@725
 | 
   143           end
 | 
| 
bsw@725
 | 
   144           if (initiative.discussion_url and #initiative.discussion_url > 0) then
 | 
| 
bsw@725
 | 
   145             slot.put(" · ")
 | 
| 
bsw@725
 | 
   146             if initiative.discussion_url:find("^https?://") then
 | 
| 
bsw@725
 | 
   147               if initiative.discussion_url and #initiative.discussion_url > 0 then
 | 
| 
bsw@725
 | 
   148                 ui.link{
 | 
| 
bsw@725
 | 
   149                   attr = {
 | 
| 
bsw@725
 | 
   150                     target = "_blank",
 | 
| 
bsw@725
 | 
   151                     title = _"Discussion with initiators"
 | 
| 
bsw@725
 | 
   152                   },
 | 
| 
bsw@725
 | 
   153                   text = _"Discuss with initiators",
 | 
| 
bsw@725
 | 
   154                   external = initiative.discussion_url
 | 
| 
bsw@725
 | 
   155                 }
 | 
| 
bsw@725
 | 
   156               end
 | 
| 
bsw@725
 | 
   157             else
 | 
| 
bsw@725
 | 
   158               slot.put(encode.html(initiative.discussion_url))
 | 
| 
bsw@725
 | 
   159             end
 | 
| 
bsw@725
 | 
   160           end
 | 
| 
bsw@725
 | 
   161           if initiator and initiator.accepted and not initiative.issue.half_frozen and not initiative.issue.closed and not initiative.revoked then
 | 
| 
bsw@725
 | 
   162             slot.put(" · ")
 | 
| 
bsw@725
 | 
   163             ui.link{
 | 
| 
bsw@725
 | 
   164               text   = _"change discussion URL",
 | 
| 
bsw@725
 | 
   165               module = "initiative",
 | 
| 
bsw@725
 | 
   166               view   = "edit",
 | 
| 
bsw@725
 | 
   167               id     = initiative.id
 | 
| 
bsw@725
 | 
   168             }
 | 
| 
bsw@725
 | 
   169             slot.put(" ")
 | 
| 
bsw@725
 | 
   170           end
 | 
| 
bsw@725
 | 
   171         end
 | 
| 
bsw@725
 | 
   172       }
 | 
| 
bsw@727
 | 
   173     end }
 | 
| 
bsw@727
 | 
   174   end
 | 
| 
bsw@725
 | 
   175 
 | 
| 
bsw@727
 | 
   176   if app.session.member_id then
 | 
| 
bsw@727
 | 
   177     ui.container{ attr = { class = "content" }, content = function()
 | 
| 
bsw@725
 | 
   178       execute.view{
 | 
| 
bsw@725
 | 
   179         module = "supporter",
 | 
| 
bsw@725
 | 
   180         view = "_show_box",
 | 
| 
bsw@725
 | 
   181         params = {
 | 
| 
bsw@725
 | 
   182           initiative = initiative
 | 
| 
bsw@725
 | 
   183         }
 | 
| 
bsw@725
 | 
   184       }
 | 
| 
bsw@727
 | 
   185     end }
 | 
| 
bsw@727
 | 
   186   end
 | 
| 
bsw@725
 | 
   187 
 | 
| 
bsw@725
 | 
   188   
 | 
| 
bsw@725
 | 
   189   -- voting results
 | 
| 
bsw@725
 | 
   190   if initiative.issue.ranks_available and initiative.admitted then
 | 
| 
bsw@725
 | 
   191     local class = initiative.winner and "admitted_info" or "not_admitted_info"
 | 
| 
bsw@725
 | 
   192     ui.container{
 | 
| 
bsw@725
 | 
   193       attr = { class = class },
 | 
| 
bsw@725
 | 
   194       content = function()
 | 
| 
bsw@725
 | 
   195         local max_value = initiative.issue.voter_count
 | 
| 
bsw@725
 | 
   196         slot.put(" ")
 | 
| 
bsw@725
 | 
   197         local positive_votes = initiative.positive_votes
 | 
| 
bsw@725
 | 
   198         local negative_votes = initiative.negative_votes
 | 
| 
bsw@725
 | 
   199         local sum_votes = initiative.positive_votes + initiative.negative_votes
 | 
| 
bsw@725
 | 
   200         local function perc(votes, sum)
 | 
| 
bsw@725
 | 
   201           if sum > 0 and votes > 0 then return " (" .. string.format( "%.f", votes * 100 / sum ) .. "%)" end
 | 
| 
bsw@725
 | 
   202           return ""
 | 
| 
bsw@725
 | 
   203         end
 | 
| 
bsw@725
 | 
   204         slot.put(_"Yes" .. ": <b>" .. tostring(positive_votes) .. perc(positive_votes, sum_votes) .. "</b>")
 | 
| 
bsw@725
 | 
   205         slot.put(" · ")
 | 
| 
bsw@725
 | 
   206         slot.put(_"Abstention" .. ": <b>" .. tostring(max_value - initiative.negative_votes - initiative.positive_votes)  .. "</b>")
 | 
| 
bsw@725
 | 
   207         slot.put(" · ")
 | 
| 
bsw@725
 | 
   208         slot.put(_"No" .. ": <b>" .. tostring(initiative.negative_votes) .. perc(negative_votes, sum_votes) .. "</b>")
 | 
| 
bsw@725
 | 
   209         slot.put(" · ")
 | 
| 
bsw@725
 | 
   210         slot.put("<b>")
 | 
| 
bsw@725
 | 
   211         if initiative.winner then
 | 
| 
bsw@725
 | 
   212           slot.put(_"Approved")
 | 
| 
bsw@725
 | 
   213         elseif initiative.rank then
 | 
| 
bsw@725
 | 
   214           slot.put(_("Not approved (rank #{rank})", { rank = initiative.rank }))
 | 
| 
bsw@725
 | 
   215         else
 | 
| 
bsw@725
 | 
   216           slot.put(_"Not approved")
 | 
| 
bsw@725
 | 
   217         end
 | 
| 
bsw@725
 | 
   218         slot.put("</b>")
 | 
| 
bsw@725
 | 
   219       end
 | 
| 
bsw@725
 | 
   220     }
 | 
| 
bsw@725
 | 
   221   end
 | 
| 
bsw@725
 | 
   222 
 | 
| 
bsw@725
 | 
   223   ui.container{ attr = { class = "content" }, content = function()
 | 
| 
bsw@725
 | 
   224     execute.view{
 | 
| 
bsw@725
 | 
   225       module = "initiative",
 | 
| 
bsw@725
 | 
   226       view = "_battles",
 | 
| 
bsw@725
 | 
   227       params = { initiative = initiative }
 | 
| 
bsw@725
 | 
   228     }
 | 
| 
bsw@725
 | 
   229   end }
 | 
| 
bsw@725
 | 
   230     
 | 
| 
bsw@725
 | 
   231   -- initiative not admitted info
 | 
| 
bsw@725
 | 
   232   if initiative.admitted == false then
 | 
| 
bsw@725
 | 
   233     local policy = initiative.issue.policy
 | 
| 
bsw@725
 | 
   234     ui.container{
 | 
| 
bsw@725
 | 
   235       attr = { class = "not_admitted_info" },
 | 
| 
bsw@725
 | 
   236       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@725
 | 
   237     }
 | 
| 
bsw@725
 | 
   238   end
 | 
| 
bsw@725
 | 
   239 
 | 
| 
bsw@725
 | 
   240   -- initiative revoked info
 | 
| 
bsw@725
 | 
   241   if initiative.revoked then
 | 
| 
bsw@725
 | 
   242     ui.container{
 | 
| 
bsw@725
 | 
   243       attr = { class = "revoked_info" },
 | 
| 
bsw@725
 | 
   244       content = function()
 | 
| 
bsw@725
 | 
   245         slot.put(_("This initiative has been revoked at #{revoked}", { revoked = format.timestamp(initiative.revoked) }))
 | 
| 
bsw@725
 | 
   246         local suggested_initiative = initiative.suggested_initiative
 | 
| 
bsw@725
 | 
   247         if suggested_initiative then
 | 
| 
bsw@725
 | 
   248           slot.put("<br /><br />")
 | 
| 
bsw@725
 | 
   249           slot.put(_("The initiators suggest to support the following initiative:"))
 | 
| 
bsw@725
 | 
   250           slot.put(" ")
 | 
| 
bsw@725
 | 
   251           ui.link{
 | 
| 
bsw@725
 | 
   252             content = _("Issue ##{id}", { id = suggested_initiative.issue.id } ) .. ": " .. encode.html(suggested_initiative.name),
 | 
| 
bsw@725
 | 
   253             module = "initiative",
 | 
| 
bsw@725
 | 
   254             view = "show",
 | 
| 
bsw@725
 | 
   255             id = suggested_initiative.id
 | 
| 
bsw@725
 | 
   256           }
 | 
| 
bsw@725
 | 
   257         end
 | 
| 
bsw@725
 | 
   258       end
 | 
| 
bsw@725
 | 
   259     }
 | 
| 
bsw@725
 | 
   260   end
 | 
| 
bsw@725
 | 
   261 
 | 
| 
bsw@725
 | 
   262 
 | 
| 
bsw@725
 | 
   263   -- invited as initiator
 | 
| 
bsw@725
 | 
   264   if initiator and initiator.accepted == nil and not initiative.issue.half_frozen and not initiative.issue.closed then
 | 
| 
bsw@725
 | 
   265     ui.container{
 | 
| 
bsw@725
 | 
   266       attr = { class = "initiator_invite_info" },
 | 
| 
bsw@725
 | 
   267       content = function()
 | 
| 
bsw@725
 | 
   268         slot.put(_"You are invited to become initiator of this initiative.")
 | 
| 
bsw@725
 | 
   269         slot.put(" ")
 | 
| 
bsw@725
 | 
   270         ui.link{
 | 
| 
bsw@725
 | 
   271           image  = { static = "icons/16/tick.png" },
 | 
| 
bsw@725
 | 
   272           text   = _"Accept invitation",
 | 
| 
bsw@725
 | 
   273           module = "initiative",
 | 
| 
bsw@725
 | 
   274           action = "accept_invitation",
 | 
| 
bsw@725
 | 
   275           id     = initiative.id,
 | 
| 
bsw@725
 | 
   276           routing = {
 | 
| 
bsw@725
 | 
   277             default = {
 | 
| 
bsw@725
 | 
   278               mode = "redirect",
 | 
| 
bsw@725
 | 
   279               module = request.get_module(),
 | 
| 
bsw@725
 | 
   280               view = request.get_view(),
 | 
| 
bsw@725
 | 
   281               id = param.get_id_cgi(),
 | 
| 
bsw@725
 | 
   282               params = param.get_all_cgi()
 | 
| 
bsw@725
 | 
   283             }
 | 
| 
bsw@725
 | 
   284           }
 | 
| 
bsw@725
 | 
   285         }
 | 
| 
bsw@725
 | 
   286         slot.put(" ")
 | 
| 
bsw@725
 | 
   287         ui.link{
 | 
| 
bsw@725
 | 
   288           image  = { static = "icons/16/cross.png" },
 | 
| 
bsw@725
 | 
   289           text   = _"Refuse invitation",
 | 
| 
bsw@725
 | 
   290           module = "initiative",
 | 
| 
bsw@725
 | 
   291           action = "reject_initiator_invitation",
 | 
| 
bsw@725
 | 
   292           params = {
 | 
| 
bsw@725
 | 
   293             initiative_id = initiative.id,
 | 
| 
bsw@725
 | 
   294             member_id = app.session.member.id
 | 
| 
bsw@725
 | 
   295           },
 | 
| 
bsw@725
 | 
   296           routing = {
 | 
| 
bsw@725
 | 
   297             default = {
 | 
| 
bsw@725
 | 
   298               mode = "redirect",
 | 
| 
bsw@725
 | 
   299               module = request.get_module(),
 | 
| 
bsw@725
 | 
   300               view = request.get_view(),
 | 
| 
bsw@725
 | 
   301               id = param.get_id_cgi(),
 | 
| 
bsw@725
 | 
   302               params = param.get_all_cgi()
 | 
| 
bsw@725
 | 
   303             }
 | 
| 
bsw@725
 | 
   304           }
 | 
| 
bsw@725
 | 
   305         }
 | 
| 
bsw@725
 | 
   306       end
 | 
| 
bsw@725
 | 
   307     }
 | 
| 
bsw@725
 | 
   308   end
 | 
| 
bsw@725
 | 
   309 
 | 
| 
bsw@725
 | 
   310   -- draft updated
 | 
| 
bsw@725
 | 
   311   local supporter
 | 
| 
bsw@725
 | 
   312 
 | 
| 
bsw@725
 | 
   313   if app.session.member_id then
 | 
| 
bsw@725
 | 
   314     supporter = app.session.member:get_reference_selector("supporters")
 | 
| 
bsw@725
 | 
   315       :add_where{ "initiative_id = ?", initiative.id }
 | 
| 
bsw@725
 | 
   316       :optional_object_mode()
 | 
| 
bsw@725
 | 
   317       :exec()
 | 
| 
bsw@725
 | 
   318   end
 | 
| 
bsw@725
 | 
   319 
 | 
| 
bsw@725
 | 
   320   if supporter and not initiative.issue.closed then
 | 
| 
bsw@725
 | 
   321     local old_draft_id = supporter.draft_id
 | 
| 
bsw@725
 | 
   322     local new_draft_id = initiative.current_draft.id
 | 
| 
bsw@725
 | 
   323     if old_draft_id ~= new_draft_id then
 | 
| 
bsw@725
 | 
   324       ui.container{
 | 
| 
bsw@725
 | 
   325         attr = { class = "draft_updated_info" },
 | 
| 
bsw@725
 | 
   326         content = function()
 | 
| 
bsw@725
 | 
   327           slot.put(_"The draft of this initiative has been updated!")
 | 
| 
bsw@725
 | 
   328           slot.put(" ")
 | 
| 
bsw@725
 | 
   329           ui.link{
 | 
| 
bsw@725
 | 
   330             content = _"Show diff",
 | 
| 
bsw@725
 | 
   331             module = "draft",
 | 
| 
bsw@725
 | 
   332             view = "diff",
 | 
| 
bsw@725
 | 
   333             params = {
 | 
| 
bsw@725
 | 
   334               old_draft_id = old_draft_id,
 | 
| 
bsw@725
 | 
   335               new_draft_id = new_draft_id
 | 
| 
bsw@725
 | 
   336             }
 | 
| 
bsw@725
 | 
   337           }
 | 
| 
bsw@725
 | 
   338           if not initiative.revoked then
 | 
| 
bsw@725
 | 
   339             slot.put(" ")
 | 
| 
bsw@725
 | 
   340             ui.link{
 | 
| 
bsw@725
 | 
   341               text   = _"Refresh support to current draft",
 | 
| 
bsw@725
 | 
   342               module = "initiative",
 | 
| 
bsw@725
 | 
   343               action = "add_support",
 | 
| 
bsw@725
 | 
   344               id     = initiative.id,
 | 
| 
bsw@725
 | 
   345               routing = {
 | 
| 
bsw@725
 | 
   346                 default = {
 | 
| 
bsw@725
 | 
   347                   mode = "redirect",
 | 
| 
bsw@725
 | 
   348                   module = "initiative",
 | 
| 
bsw@725
 | 
   349                   view = "show",
 | 
| 
bsw@725
 | 
   350                   id = initiative.id
 | 
| 
bsw@725
 | 
   351                 }
 | 
| 
bsw@725
 | 
   352               }
 | 
| 
bsw@725
 | 
   353             }
 | 
| 
bsw@725
 | 
   354           end
 | 
| 
bsw@725
 | 
   355         end
 | 
| 
bsw@725
 | 
   356       }
 | 
| 
bsw@725
 | 
   357     end
 | 
| 
bsw@725
 | 
   358   end
 | 
| 
bsw@725
 | 
   359 
 | 
| 
bsw@725
 | 
   360   if not show_as_head then
 | 
| 
bsw@725
 | 
   361     local drafts_count = initiative:get_reference_selector("drafts"):count()
 | 
| 
bsw@725
 | 
   362 
 | 
| 
bsw@725
 | 
   363     ui.container{ attr = { class = "content" }, content = function()
 | 
| 
bsw@725
 | 
   364     
 | 
| 
bsw@725
 | 
   365       if initiator and initiator.accepted and not initiative.issue.half_frozen and not initiative.issue.closed and not initiative.revoked then
 | 
| 
bsw@725
 | 
   366         ui.link{
 | 
| 
bsw@725
 | 
   367           content = function()
 | 
| 
bsw@725
 | 
   368             slot.put(_"Edit draft")
 | 
| 
bsw@725
 | 
   369           end,
 | 
| 
bsw@725
 | 
   370           module = "draft",
 | 
| 
bsw@725
 | 
   371           view = "new",
 | 
| 
bsw@725
 | 
   372           params = { initiative_id = initiative.id }
 | 
| 
bsw@725
 | 
   373         }
 | 
| 
bsw@725
 | 
   374         slot.put(" · ")
 | 
| 
bsw@725
 | 
   375         ui.link{
 | 
| 
bsw@725
 | 
   376           content = function()
 | 
| 
bsw@725
 | 
   377             slot.put(_"Revoke initiative")
 | 
| 
bsw@725
 | 
   378           end,
 | 
| 
bsw@725
 | 
   379           module = "initiative",
 | 
| 
bsw@725
 | 
   380           view = "revoke",
 | 
| 
bsw@725
 | 
   381           id = initiative.id
 | 
| 
bsw@725
 | 
   382         }
 | 
| 
bsw@725
 | 
   383         slot.put(" · ")
 | 
| 
bsw@725
 | 
   384       end
 | 
| 
bsw@725
 | 
   385 
 | 
| 
bsw@725
 | 
   386       ui.tag{
 | 
| 
bsw@725
 | 
   387         attr = { class = "draft_version" },
 | 
| 
bsw@725
 | 
   388         content = _("Latest draft created at #{date} #{time}", {
 | 
| 
bsw@725
 | 
   389           date = format.date(initiative.current_draft.created),
 | 
| 
bsw@725
 | 
   390           time = format.time(initiative.current_draft.created)
 | 
| 
bsw@725
 | 
   391         })
 | 
| 
bsw@725
 | 
   392       }
 | 
| 
bsw@725
 | 
   393       if drafts_count > 1 then
 | 
| 
bsw@725
 | 
   394         slot.put(" · ")
 | 
| 
bsw@725
 | 
   395         ui.link{
 | 
| 
bsw@725
 | 
   396           module = "draft", view = "list", params = { initiative_id = initiative.id },
 | 
| 
bsw@725
 | 
   397           text = _("List all revisions (#{count})", { count = drafts_count })
 | 
| 
bsw@725
 | 
   398         }
 | 
| 
bsw@725
 | 
   399       end
 | 
| 
bsw@725
 | 
   400     end }
 | 
| 
bsw@725
 | 
   401 
 | 
| 
bsw@725
 | 
   402     execute.view{
 | 
| 
bsw@725
 | 
   403       module = "draft",
 | 
| 
bsw@725
 | 
   404       view = "_show",
 | 
| 
bsw@725
 | 
   405       params = {
 | 
| 
bsw@725
 | 
   406         draft = initiative.current_draft
 | 
| 
bsw@725
 | 
   407       }
 | 
| 
bsw@725
 | 
   408     }
 | 
| 
bsw@725
 | 
   409   end
 | 
| 
bsw@725
 | 
   410 end }
 | 
| 
bsw@725
 | 
   411 
 | 
| 
bsw@725
 | 
   412 if not show_as_head then
 | 
| 
bsw@725
 | 
   413   execute.view{
 | 
| 
bsw@725
 | 
   414     module = "suggestion",
 | 
| 
bsw@725
 | 
   415     view = "_list",
 | 
| 
bsw@725
 | 
   416     params = {
 | 
| 
bsw@725
 | 
   417       initiative = initiative,
 | 
| 
bsw@725
 | 
   418       suggestions_selector = initiative:get_reference_selector("suggestions"),
 | 
| 
bsw@725
 | 
   419       tab_id = param.get("tab_id")
 | 
| 
bsw@725
 | 
   420     }
 | 
| 
bsw@725
 | 
   421   }
 | 
| 
bsw@725
 | 
   422 
 | 
| 
bsw@725
 | 
   423 
 | 
| 
bsw@813
 | 
   424   if app.session:has_access("all_pseudonymous") then
 | 
| 
bsw@725
 | 
   425     if initiative.issue.ranks_available then
 | 
| 
bsw@725
 | 
   426       local members_selector = initiative.issue:get_reference_selector("direct_voters")
 | 
| 
bsw@725
 | 
   427             :left_join("vote", nil, { "vote.initiative_id = ? AND vote.member_id = member.id", initiative.id })
 | 
| 
bsw@725
 | 
   428             :add_field("direct_voter.weight as voter_weight")
 | 
| 
bsw@725
 | 
   429             :add_field("coalesce(vote.grade, 0) as grade")
 | 
| 
bsw@725
 | 
   430             :left_join("initiative", nil, "initiative.id = vote.initiative_id")
 | 
| 
bsw@725
 | 
   431             :left_join("issue", nil, "issue.id = initiative.issue_id")
 | 
| 
bsw@725
 | 
   432       
 | 
| 
bsw@725
 | 
   433       ui.anchor{ name = "voter", attr = { class = "heading" }, content = _"Member voter" }
 | 
| 
bsw@725
 | 
   434       
 | 
| 
bsw@725
 | 
   435       execute.view{
 | 
| 
bsw@725
 | 
   436         module = "member",
 | 
| 
bsw@725
 | 
   437         view = "_list",
 | 
| 
bsw@725
 | 
   438         params = {
 | 
| 
bsw@725
 | 
   439           initiative = initiative,
 | 
| 
bsw@725
 | 
   440           for_votes = true,
 | 
| 
bsw@725
 | 
   441           members_selector = members_selector,
 | 
| 
bsw@725
 | 
   442           paginator_name = "voter"
 | 
| 
bsw@725
 | 
   443         }
 | 
| 
bsw@725
 | 
   444       }
 | 
| 
bsw@725
 | 
   445     end
 | 
| 
bsw@725
 | 
   446     
 | 
| 
bsw@725
 | 
   447     local members_selector = initiative:get_reference_selector("supporting_members_snapshot")
 | 
| 
bsw@725
 | 
   448               :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id")
 | 
| 
bsw@725
 | 
   449               :join("direct_interest_snapshot", nil, "direct_interest_snapshot.event = issue.latest_snapshot_event AND direct_interest_snapshot.issue_id = issue.id AND direct_interest_snapshot.member_id = member.id")
 | 
| 
bsw@725
 | 
   450               :add_field("direct_interest_snapshot.weight")
 | 
| 
bsw@725
 | 
   451               :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event")
 | 
| 
bsw@725
 | 
   452               :add_where("direct_supporter_snapshot.satisfied")
 | 
| 
bsw@725
 | 
   453               :add_field("direct_supporter_snapshot.informed", "is_informed")
 | 
| 
bsw@725
 | 
   454 
 | 
| 
bsw@725
 | 
   455     if members_selector:count() > 0 then
 | 
| 
bsw@725
 | 
   456       if issue.fully_frozen then
 | 
| 
bsw@725
 | 
   457         ui.anchor{ name = "supporters", attr = { class = "heading" }, content = _"Supporters (before begin of voting)" }
 | 
| 
bsw@725
 | 
   458       else
 | 
| 
bsw@725
 | 
   459         ui.anchor{ name = "supporters", attr = { class = "heading" }, content = _"Supporters" }
 | 
| 
bsw@725
 | 
   460       end      
 | 
| 
bsw@725
 | 
   461       
 | 
| 
bsw@725
 | 
   462       execute.view{
 | 
| 
bsw@725
 | 
   463         module = "member",
 | 
| 
bsw@725
 | 
   464         view = "_list",
 | 
| 
bsw@725
 | 
   465         params = {
 | 
| 
bsw@725
 | 
   466           initiative = initiative,
 | 
| 
bsw@725
 | 
   467           members_selector = members_selector,
 | 
| 
bsw@725
 | 
   468           paginator_name = "supporters"
 | 
| 
bsw@725
 | 
   469         }
 | 
| 
bsw@725
 | 
   470     }
 | 
| 
bsw@725
 | 
   471     else
 | 
| 
bsw@725
 | 
   472       if issue.fully_frozen then
 | 
| 
bsw@725
 | 
   473         ui.anchor{ name = "supporters", attr = { class = "heading" }, content = _"No supporters (before begin of voting)" }
 | 
| 
bsw@725
 | 
   474       else
 | 
| 
bsw@725
 | 
   475         ui.anchor{ name = "supporters", attr = { class = "heading" }, content = _"No supporters" }
 | 
| 
bsw@725
 | 
   476       end
 | 
| 
bsw@725
 | 
   477       slot.put("<br />")
 | 
| 
bsw@725
 | 
   478     end
 | 
| 
bsw@725
 | 
   479 
 | 
| 
bsw@725
 | 
   480     local members_selector = initiative:get_reference_selector("supporting_members_snapshot")
 | 
| 
bsw@725
 | 
   481               :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id")
 | 
| 
bsw@725
 | 
   482               :join("direct_interest_snapshot", nil, "direct_interest_snapshot.event = issue.latest_snapshot_event AND direct_interest_snapshot.issue_id = issue.id AND direct_interest_snapshot.member_id = member.id")
 | 
| 
bsw@725
 | 
   483               :add_field("direct_interest_snapshot.weight")
 | 
| 
bsw@725
 | 
   484               :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event")
 | 
| 
bsw@725
 | 
   485               :add_where("NOT direct_supporter_snapshot.satisfied")
 | 
| 
bsw@725
 | 
   486               :add_field("direct_supporter_snapshot.informed", "is_informed")
 | 
| 
bsw@725
 | 
   487 
 | 
| 
bsw@725
 | 
   488     if members_selector:count() > 0 then
 | 
| 
bsw@725
 | 
   489       if issue.fully_frozen then
 | 
| 
bsw@725
 | 
   490         ui.anchor{ name = "potential_supporters", attr = { class = "heading" }, content = _"Potential supporters (before begin of voting)" }
 | 
| 
bsw@725
 | 
   491       else
 | 
| 
bsw@725
 | 
   492         ui.anchor{ name = "potential_supporters", attr = { class = "heading" }, content = _"Potential supporters" }
 | 
| 
bsw@725
 | 
   493       end
 | 
| 
bsw@725
 | 
   494                 
 | 
| 
bsw@725
 | 
   495       execute.view{
 | 
| 
bsw@725
 | 
   496         module = "member",
 | 
| 
bsw@725
 | 
   497         view = "_list",
 | 
| 
bsw@725
 | 
   498         params = {
 | 
| 
bsw@725
 | 
   499           initiative = initiative,
 | 
| 
bsw@725
 | 
   500           members_selector = members_selector,
 | 
| 
bsw@725
 | 
   501           paginator_name = "potential_supporters"
 | 
| 
bsw@725
 | 
   502         }
 | 
| 
bsw@725
 | 
   503       }
 | 
| 
bsw@725
 | 
   504     else
 | 
| 
bsw@725
 | 
   505       if issue.fully_frozen then
 | 
| 
bsw@725
 | 
   506         ui.anchor{ name = "potential_supporters", attr = { class = "heading" }, content = _"No potential supporters (before begin of voting)" }
 | 
| 
bsw@725
 | 
   507       else
 | 
| 
bsw@725
 | 
   508         ui.anchor{ name = "potential_supporters", attr = { class = "heading" }, content = _"No potential supporters" }
 | 
| 
bsw@725
 | 
   509       end
 | 
| 
bsw@725
 | 
   510       slot.put("<br />")
 | 
| 
bsw@725
 | 
   511     end
 | 
| 
bsw@725
 | 
   512     
 | 
| 
bsw@725
 | 
   513     ui.container{ attr = { class = "heading" }, content = _"Details" }
 | 
| 
bsw@725
 | 
   514     execute.view {
 | 
| 
bsw@725
 | 
   515       module = "initiative",
 | 
| 
bsw@725
 | 
   516       view = "_details",
 | 
| 
bsw@725
 | 
   517       params = {
 | 
| 
bsw@725
 | 
   518         initiative = initiative,
 | 
| 
bsw@725
 | 
   519         members_selector = members_selector
 | 
| 
bsw@725
 | 
   520       }
 | 
| 
bsw@725
 | 
   521     }
 | 
| 
bsw@725
 | 
   522 
 | 
| 
bsw@725
 | 
   523   end
 | 
| 
bsw@725
 | 
   524 end |