bsw/jbe@19: local initiative = param.get("initiative", "table")
bsw/jbe@19: local initiator = param.get("initiator", "table")
bsw/jbe@19: 
bsw/jbe@19: util.help("initiative.show")
bsw/jbe@19: 
bsw/jbe@19: if initiative.issue.ranks_available and initiative.admitted then
bsw/jbe@19:   local class = initiative.rank == 1 and "admitted_info" or "not_admitted_info"
bsw/jbe@19:   ui.container{
bsw/jbe@19:     attr = { class = class },
bsw/jbe@19:     content = function()
bsw/jbe@19:       local max_value = initiative.issue.voter_count
bsw/jbe@19:       slot.put(" ")
bsw/jbe@19:       local positive_votes = initiative.positive_votes
bsw/jbe@19:       local negative_votes = initiative.negative_votes
jorges@104:       local sum_votes = initiative.positive_votes + initiative.negative_votes
poelzi@167:       local function perc(votes, sum)
poelzi@167:         if sum > 0 and votes > 0 then return " (" .. string.format( "%.f", votes * 100 / sum ) .. "%)" end
poelzi@167:         return ""
poelzi@167:       end
poelzi@167:       slot.put(_"Yes" .. ": " .. tostring(positive_votes) .. perc(positive_votes, sum_votes) .. "")
bsw/jbe@19:       slot.put(" · ")
bsw/jbe@19:       slot.put(_"Abstention" .. ": " .. tostring(max_value - initiative.negative_votes - initiative.positive_votes)  .. "")
bsw/jbe@19:       slot.put(" · ")
poelzi@167:       slot.put(_"No" .. ": " .. tostring(initiative.negative_votes) .. perc(negative_votes, sum_votes) .. "")
bsw/jbe@19:       slot.put(" · ")
bsw/jbe@19:       slot.put("")
bsw/jbe@19:       if initiative.rank == 1 then
bsw/jbe@19:         slot.put(_"Approved")
bsw/jbe@19:       elseif initiative.rank then
bsw/jbe@19:         slot.put(_("Not approved (rank #{rank})", { rank = initiative.rank }))
bsw@24:       else
bsw@24:         slot.put(_"Not approved")
bsw/jbe@19:       end
bsw/jbe@19:       slot.put("")
bsw/jbe@19:     end
bsw/jbe@19:   }
bsw/jbe@19: end
bsw/jbe@19: 
bsw/jbe@19: if initiative.admitted == false then
bsw/jbe@19:   local policy = initiative.issue.policy
bsw/jbe@19:   ui.container{
bsw/jbe@19:     attr = { class = "not_admitted_info" },
bsw/jbe@19:     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:   }
bsw/jbe@19: end
bsw/jbe@19: 
bsw/jbe@19: local web20 = config.user_tab_mode == "accordeon"
bsw/jbe@19:   or config.user_tab_mode == "accordeon_first_expanded"
bsw/jbe@19:   or config.user_tab_mode == "accordeon_all_expanded"
bsw/jbe@19: 
bsw/jbe@19: if not web20 and initiative.issue.state == "cancelled" then
bsw/jbe@19:   local policy = initiative.issue.policy
bsw/jbe@19:   ui.container{
bsw/jbe@19:     attr = { class = "not_admitted_info" },
bsw/jbe@19:     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:   }
bsw/jbe@19: end
bsw/jbe@19: 
bsw/jbe@19: if initiative.revoked then
bsw/jbe@19:   ui.container{
bsw/jbe@19:     attr = { class = "revoked_info" },
bsw/jbe@19:     content = function()
bsw/jbe@19:       slot.put(_("This initiative has been revoked at #{revoked}", { revoked = format.timestamp(initiative.revoked) }))
bsw/jbe@19:       local suggested_initiative = initiative.suggested_initiative
bsw/jbe@19:       if suggested_initiative then
bsw/jbe@19:         slot.put("
")
bsw/jbe@19:         slot.put(_("The initiators suggest to support the following initiative:"))
bsw/jbe@19:         slot.put(" ")
bsw/jbe@19:         ui.link{
bsw/jbe@19:           content = _("Issue ##{id}", { id = suggested_initiative.issue.id } ) .. ": " .. encode.html(suggested_initiative.name),
bsw/jbe@19:           module = "initiative",
bsw/jbe@19:           view = "show",
bsw/jbe@19:           id = suggested_initiative.id
bsw/jbe@19:         }
bsw/jbe@19:       end
bsw/jbe@19:     end
bsw/jbe@19:   }
bsw/jbe@19: 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: 
bsw@51: if app.session.member_id then
bsw@51:   ui.container{
bsw@51:     attr = {
bsw@51:       id = "initiative_" .. tostring(initiative.id) .. "_support"
bsw@51:     },
bsw@51:     content = function()
bsw@51:       execute.view{
bsw@51:         module = "initiative",
bsw@51:         view = "show_support",
bsw@51:         params = {
bsw@51:           initiative = initiative
bsw@51:         }
bsw/jbe@19:       }
bsw@51:     end
bsw@51:   }
bsw@51: end
bsw/jbe@19: 
bsw/jbe@19: if (initiative.discussion_url and #initiative.discussion_url > 0)
bsw/jbe@19:   or (initiator and initiator.accepted and not initiative.issue.half_frozen and not initiative.issue.closed and not initiative.revoked) then
bsw/jbe@19:   ui.container{
bsw/jbe@19:     attr = { class = "vertical" },
bsw/jbe@19:     content = function()
bsw/jbe@19:       ui.container{
bsw/jbe@19:         attr = { class = "ui_field_label" },
bsw/jbe@19:         content = _"Discussion with initiators"
bsw/jbe@19:       }
bsw/jbe@19:       ui.tag{
bsw/jbe@19:         tag = "span",
bsw/jbe@19:         content = function()
bsw/jbe@19:           if initiative.discussion_url:find("^https?://") then
bsw/jbe@19:             if initiative.discussion_url and #initiative.discussion_url > 0 then
bsw/jbe@19:               ui.link{
bsw/jbe@19:                 attr = {
bsw/jbe@19:                   class = "actions",
bsw/jbe@19:                   target = "_blank",
bsw/jbe@19:                   title = initiative.discussion_url
bsw/jbe@19:                 },
bsw/jbe@19:                 content = function()
bsw/jbe@19:                   slot.put(encode.html(initiative.discussion_url))
bsw/jbe@19:                 end,
bsw/jbe@19:                 external = initiative.discussion_url
bsw/jbe@19:               }
bsw/jbe@19:             end
bsw/jbe@19:           else
bsw/jbe@19:             slot.put(encode.html(initiative.discussion_url))
bsw/jbe@19:           end
bsw/jbe@19:           slot.put(" ")
bsw/jbe@19:           if initiator and initiator.accepted and not initiative.issue.half_frozen and not initiative.issue.closed and not initiative.revoked then
bsw/jbe@19:             ui.link{
bsw/jbe@19:               attr   = { class = "actions" },
bsw/jbe@19:               text   = _"(change URL)",
bsw/jbe@19:               module = "initiative",
bsw/jbe@19:               view   = "edit",
bsw/jbe@19:               id     = initiative.id
bsw/jbe@19:             }
bsw/jbe@19:           end
bsw/jbe@19:         end
bsw/jbe@19:       }
bsw/jbe@19:     end
bsw/jbe@19:   }
bsw/jbe@19: end
bsw/jbe@19: 
bsw/jbe@19: 
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: