bsw/jbe@19: local initiative = param.get("initiative", "table")
bsw/jbe@19: 
bsw@272: local initiators_members_selector = initiative:get_reference_selector("initiating_members")
bsw@272:   :add_field("initiator.accepted", "accepted")
bsw@280:   :add_order_by("member.name")
bsw@280: if initiator and initiator.accepted then
bsw@280:   initiators_members_selector:add_where("initiator.accepted ISNULL OR initiator.accepted")
bsw@280: else
bsw@272:   initiators_members_selector:add_where("initiator.accepted")
bsw@272: end
bsw@272: 
bsw@272: local initiators = initiators_members_selector:exec()
bsw@272: 
bsw@274: 
bsw@274: local initiatives_selector = initiative.issue:get_reference_selector("initiatives")
bsw@525: slot.select("head", function()
bsw@274:   execute.view{
bsw@525:     module = "issue",
bsw@525:     view = "_show",
bsw@274:     params = {
bsw@274:       issue = initiative.issue,
bsw@525:       initiative_limit = 3
bsw@274:     }
bsw@274:   }
bsw@274: end)
bsw@274: 
bsw@525: ui.container{ attr = { class = "initiative_head" }, content = function()
bsw@272: 
bsw@272:   ui.container{
bsw@525:     attr = { class = "title" },
bsw@272:     content = _("Initiative i#{id}: #{name}", { id = initiative.id, name = initiative.name })
bsw@272:   }
bsw@286: 
bsw@525:   ui.container{ attr = { class = "content" }, content = function()
bsw@525:     if app.session.member_id or config.public_access == "pseudonym" or config.public_access == "full" then
bsw@525:       ui.tag{
bsw@525:         attr = { class = "initiator_names" },
bsw@525:         content = function()
bsw@525:           for i, initiator in ipairs(initiators) do
bsw@525:             slot.put(" ")
bsw@527:             if app.session.member_id or config.public_access == "full" then
bsw@525:               ui.link{
bsw@525:                 content = function ()
bsw@525:                   execute.view{
bsw@525:                     module = "member_image",
bsw@525:                     view = "_show",
bsw@525:                     params = {
bsw@525:                       member = initiator,
bsw@525:                       image_type = "avatar",
bsw@525:                       show_dummy = true,
bsw@525:                       class = "micro_avatar",
bsw@525:                       popup_text = text
bsw@525:                     }
bsw@525:                   }
bsw@525:                 end,
bsw@525:                 module = "member", view = "show", id = initiator.id
bsw@525:               }
bsw@525:               slot.put(" ")
bsw@525:             end
bsw@458:             ui.link{
bsw@525:               text = initiator.name,
bsw@458:               module = "member", view = "show", id = initiator.id
bsw@458:             }
bsw@525:             if not initiator.accepted then
bsw@525:               ui.tag{ attr = { title = _"Not accepted yet" }, content = "?" }
bsw@525:             end
bsw@313:           end
bsw@272:         end
bsw@313:       }
bsw@313:     end
bsw@525: 
bsw@525:     if initiator and initiator.accepted and not initiative.issue.fully_frozen and not initiative.issue.closed and not initiative.revoked then
bsw@313:       slot.put(" · ")
bsw@313:       ui.link{
bsw@525:         attr = { class = "action" },
bsw@525:         content = function()
bsw@525:           slot.put(_"Invite initiator")
bsw@525:         end,
bsw@313:         module = "initiative",
bsw@525:         view = "add_initiator",
bsw@525:         params = { initiative_id = initiative.id }
bsw@525:       }
bsw@525:       if #initiators > 1 then
bsw@525:         slot.put(" · ")
bsw@525:         ui.link{
bsw@525:           content = function()
bsw@525:             slot.put(_"Remove initiator")
bsw@525:           end,
bsw@525:           module = "initiative",
bsw@525:           view = "remove_initiator",
bsw@525:           params = { initiative_id = initiative.id }
bsw@525:         }
bsw@525:       end
bsw@525:     end
bsw@525:     if initiator and initiator.accepted == false then
bsw@525:         slot.put(" · ")
bsw@525:         ui.link{
bsw@525:           text   = _"Cancel refuse of invitation",
bsw@525:           module = "initiative",
bsw@525:           action = "remove_initiator",
bsw@525:           params = {
bsw@525:             initiative_id = initiative.id,
bsw@525:             member_id = app.session.member.id
bsw@525:           },
bsw@525:           routing = {
bsw@525:             ok = {
bsw@525:               mode = "redirect",
bsw@525:               module = "initiative",
bsw@525:               view = "show",
bsw@525:               id = initiative.id
bsw@525:             }
bsw@313:           }
bsw@313:         }
bsw@525:     end
bsw@525:   end }
bsw@525:   ui.container{ attr = { class = "content" }, content = function()
bsw@525:     if app.session.member_id then
bsw@525:       execute.view{
bsw@525:         module = "supporter",
bsw@525:         view = "_show_box",
bsw@525:         params = {
bsw@525:           initiative = initiative
bsw@525:         }
bsw@313:       }
bsw@525:     end
bsw@313: 
bsw@525:   end }
bsw@525: 
bsw@525: end }
bsw@313: 
bsw@313: 
bsw/jbe@19: util.help("initiative.show")
bsw/jbe@19: 
bsw@525: --slot.select("initiative_head", function()
bsw@272: 
bsw@493:   if initiative.issue.ranks_available and initiative.admitted then
bsw@493:     local class = initiative.winner and "admitted_info" or "not_admitted_info"
bsw@493:     ui.container{
bsw@493:       attr = { class = class },
bsw@493:       content = function()
bsw@493:         local max_value = initiative.issue.voter_count
bsw@493:         slot.put(" ")
bsw@493:         local positive_votes = initiative.positive_votes
bsw@493:         local negative_votes = initiative.negative_votes
bsw@493:         local sum_votes = initiative.positive_votes + initiative.negative_votes
bsw@493:         local function perc(votes, sum)
bsw@493:           if sum > 0 and votes > 0 then return " (" .. string.format( "%.f", votes * 100 / sum ) .. "%)" end
bsw@493:           return ""
bsw@493:         end
bsw@493:         slot.put(_"Yes" .. ": " .. tostring(positive_votes) .. perc(positive_votes, sum_votes) .. "")
bsw@493:         slot.put(" · ")
bsw@493:         slot.put(_"Abstention" .. ": " .. tostring(max_value - initiative.negative_votes - initiative.positive_votes)  .. "")
bsw@493:         slot.put(" · ")
bsw@493:         slot.put(_"No" .. ": " .. tostring(initiative.negative_votes) .. perc(negative_votes, sum_votes) .. "")
bsw@493:         slot.put(" · ")
bsw@493:         slot.put("")
bsw@493:         if initiative.winner then
bsw@493:           slot.put(_"Approved")
bsw@493:         elseif initiative.rank then
bsw@493:           slot.put(_("Not approved (rank #{rank})", { rank = initiative.rank }))
bsw@493:         else
bsw@493:           slot.put(_"Not approved")
bsw@493:         end
bsw@493:         slot.put("")
poelzi@167:       end
bsw@493:     }
bsw@493:   end
bsw/jbe@19: 
bsw@493:   if initiative.admitted == false then
bsw@493:     local policy = initiative.issue.policy
bsw@493:     ui.container{
bsw@493:       attr = { class = "not_admitted_info" },
bsw@493:       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@493:     }
bsw@493:   end
bsw/jbe@19: 
bsw@493:   if initiative.revoked then
bsw@493:     ui.container{
bsw@493:       attr = { class = "revoked_info" },
bsw@493:       content = function()
bsw@493:         slot.put(_("This initiative has been revoked at #{revoked}", { revoked = format.timestamp(initiative.revoked) }))
bsw@493:         local suggested_initiative = initiative.suggested_initiative
bsw@493:         if suggested_initiative then
bsw@493:           slot.put("
")
bsw@493:           slot.put(_("The initiators suggest to support the following initiative:"))
bsw@493:           slot.put(" ")
bsw@493:           ui.link{
bsw@493:             content = _("Issue ##{id}", { id = suggested_initiative.issue.id } ) .. ": " .. encode.html(suggested_initiative.name),
bsw@493:             module = "initiative",
bsw@493:             view = "show",
bsw@493:             id = suggested_initiative.id
bsw@493:           }
bsw@493:         end
bsw/jbe@19:       end
bsw@493:     }
bsw@493:   end
bsw@493: 
bsw@525: --end)
bsw/jbe@19: 
bsw@41: if initiator and initiator.accepted == nil and not initiative.issue.half_frozen and not initiative.issue.closed then
bsw/jbe@19:   ui.container{
bsw/jbe@19:     attr = { class = "initiator_invite_info" },
bsw/jbe@19:     content = function()
bsw/jbe@19:       slot.put(_"You are invited to become initiator of this initiative.")
bsw/jbe@19:       slot.put(" ")
bsw/jbe@19:       ui.link{
bsw/jbe@19:         image  = { static = "icons/16/tick.png" },
bsw/jbe@19:         text   = _"Accept invitation",
bsw/jbe@19:         module = "initiative",
bsw/jbe@19:         action = "accept_invitation",
bsw/jbe@19:         id     = initiative.id,
bsw/jbe@19:         routing = {
bsw/jbe@19:           default = {
bsw/jbe@19:             mode = "redirect",
bsw/jbe@19:             module = request.get_module(),
bsw/jbe@19:             view = request.get_view(),
bsw/jbe@19:             id = param.get_id_cgi(),
bsw/jbe@19:             params = param.get_all_cgi()
bsw/jbe@19:           }
bsw/jbe@19:         }
bsw/jbe@19:       }
bsw/jbe@19:       slot.put(" ")
bsw/jbe@19:       ui.link{
bsw/jbe@19:         image  = { static = "icons/16/cross.png" },
bsw/jbe@19:         text   = _"Refuse invitation",
bsw/jbe@19:         module = "initiative",
bsw/jbe@19:         action = "reject_initiator_invitation",
bsw/jbe@19:         params = {
bsw/jbe@19:           initiative_id = initiative.id,
bsw/jbe@19:           member_id = app.session.member.id
bsw/jbe@19:         },
bsw/jbe@19:         routing = {
bsw/jbe@19:           default = {
bsw/jbe@19:             mode = "redirect",
bsw/jbe@19:             module = request.get_module(),
bsw/jbe@19:             view = request.get_view(),
bsw/jbe@19:             id = param.get_id_cgi(),
bsw/jbe@19:             params = param.get_all_cgi()
bsw/jbe@19:           }
bsw/jbe@19:         }
bsw/jbe@19:       }
bsw/jbe@19:     end
bsw/jbe@19:   }
bsw/jbe@19:   slot.put("
")
bsw/jbe@19: end
bsw/jbe@19: 
bsw/jbe@19: 
bsw@51: local supporter
bsw@51: 
bsw@51: if app.session.member_id then
bsw@51:   supporter = app.session.member:get_reference_selector("supporters")
bsw@51:     :add_where{ "initiative_id = ?", initiative.id }
bsw@51:     :optional_object_mode()
bsw@51:     :exec()
bsw@51: end
bsw/jbe@19: 
bsw/jbe@19: if supporter and not initiative.issue.closed then
bsw/jbe@19:   local old_draft_id = supporter.draft_id
bsw/jbe@19:   local new_draft_id = initiative.current_draft.id
bsw/jbe@19:   if old_draft_id ~= new_draft_id then
bsw/jbe@19:     ui.container{
bsw/jbe@19:       attr = { class = "draft_updated_info" },
bsw/jbe@19:       content = function()
bsw/jbe@19:         slot.put(_"The draft of this initiative has been updated!")
bsw/jbe@19:         slot.put(" ")
bsw/jbe@19:         ui.link{
bsw/jbe@19:           content = _"Show diff",
bsw/jbe@19:           module = "draft",
bsw/jbe@19:           view = "diff",
bsw/jbe@19:           params = {
bsw/jbe@19:             old_draft_id = old_draft_id,
bsw/jbe@19:             new_draft_id = new_draft_id
bsw/jbe@19:           }
bsw/jbe@19:         }
bsw@75:         if not initiative.revoked then
bsw@75:           slot.put(" ")
bsw@75:           ui.link{
bsw@75:             text   = _"Refresh support to current draft",
bsw@75:             module = "initiative",
bsw@75:             action = "add_support",
bsw@75:             id     = initiative.id,
bsw@75:             routing = {
bsw@75:               default = {
bsw@75:                 mode = "redirect",
bsw@75:                 module = "initiative",
bsw@75:                 view = "show",
bsw@75:                 id = initiative.id
bsw@75:               }
bsw/jbe@19:             }
bsw/jbe@19:           }
bsw@75:         end
bsw/jbe@19:       end
bsw/jbe@19:     }
bsw/jbe@19:   end
bsw/jbe@19: end
bsw/jbe@19: 
bsw/jbe@19: execute.view{
bsw/jbe@19:   module = "initiative",
bsw/jbe@19:   view = "show_tab",
bsw/jbe@19:   params = {
bsw/jbe@19:     initiative = initiative,
bsw/jbe@19:     initiator = initiator
bsw/jbe@19:   }
bsw/jbe@19: }
bsw/jbe@19: 
bsw@280: if initiative.issue.snapshot then
bsw@431:   slot.put("
")
bsw@280:   ui.field.timestamp{ label = _"Last snapshot:", value = initiative.issue.snapshot }
bsw@280: end
bsw@280: 
bsw@280: 
bsw@286: