bsw@1045: local initiative = param.get("initiative", "table")
bsw@1045: local member = param.get("member", "table") or app.session.member
bsw@1045: 
bsw@1045: -- TODO performance
bsw@1045: local initiator
bsw@1045: if member then
bsw@1045:   initiator = Initiator:by_pk(initiative.id, member.id)
bsw@1045: end
bsw@1045: 
bsw@1045: local initiators_members_selector = initiative:get_reference_selector("initiating_members")
bsw@1045:   :add_field("initiator.accepted", "accepted")
bsw@1045:   :add_order_by("member.name")
bsw@1045: if initiator and initiator.accepted then
bsw@1045:   initiators_members_selector:add_where("initiator.accepted ISNULL OR initiator.accepted")
bsw@1045: else
bsw@1045:   initiators_members_selector:add_where("initiator.accepted")
bsw@1045: end
bsw@1045: 
bsw@1045: local initiators = initiators_members_selector:exec()
bsw@1045: 
bsw@1045: 
bsw@1045: ui.sectionHead( "initiativeInfo", function ()
bsw@1045: 
bsw@1045:     ui.heading { 
bsw@1045:       level = 1,
bsw@1045:       content = initiative.display_name
bsw@1045:     }
bsw@1045: 
bsw@1045:     ui.container { attr = { class = "support" }, content = function ()
bsw@1045:       if initiative.supporter_count == nil then
bsw@1045:         ui.tag { 
bsw@1045:           attr = { class = "supporterCount" },
bsw@1045:           content = _"[calculating]"
bsw@1045:         }
bsw@1045:       elseif initiative.issue.closed == nil then
bsw@1045:         ui.tag { 
bsw@1045:           attr = { class = "satisfiedSupporterCount" },
bsw@1045:           content = _("#{count} supporter", { count = initiative.satisfied_supporter_count })
bsw@1045:         }
bsw@1045:         if initiative.potential_supporter_count and
bsw@1045:             initiative.potential_supporter_count > 0 
bsw@1045:         then
bsw@1045:           slot.put ( " " )
bsw@1045:           ui.tag { 
bsw@1045:             attr = { class = "potentialSupporterCount" },
bsw@1045:             content = _("(+ #{count} potential)", { count = initiative.potential_supporter_count })
bsw@1045:           }
bsw@1045:         end
bsw@1045:       
bsw@1045:       end 
bsw@1045:       
bsw@1045:       slot.put ( "
" )
bsw@1045:       
bsw@1045:       execute.view {
bsw@1045:         module = "initiative", view = "_bargraph", params = {
bsw@1045:           initiative = initiative
bsw@1045:         }
bsw@1045:       }
bsw@1045:     end }
bsw@1045:     
bsw@1045:     if member then
bsw@1045:       ui.container { attr = { class = "mySupport right" }, content = function ()
bsw@1045:         if initiative.issue.fully_frozen then
bsw@1045:           if initiative.issue.member_info.direct_voted then
bsw@1045:             --ui.image { attr = { class = "icon48 right" }, static = "icons/48/voted_ok.png" }
bsw@1045:             ui.tag { content = _"You have voted" }
bsw@1045:             slot.put("
")
bsw@1045:             if not initiative.issue.closed then
bsw@1045:               ui.link {
bsw@1045:                 module = "vote", view = "list", 
bsw@1045:                 params = { issue_id = initiative.issue.id },
bsw@1045:                 text = _"change vote"
bsw@1045:               }
bsw@1045:             else
bsw@1045:               ui.link {
bsw@1045:                 module = "vote", view = "list", 
bsw@1045:                 params = { issue_id = initiative.issue.id },
bsw@1045:                 text = _"show vote"
bsw@1045:               }
bsw@1045:             end
bsw@1045:             slot.put(" ")
bsw@1045:           elseif active_trustee_id then
bsw@1045:             ui.tag { content = _"You have voted via delegation" }
bsw@1045:             ui.link {
bsw@1045:               content = _"Show voting ballot",
bsw@1045:               module = "vote", view = "list", params = {
bsw@1045:                 issue_id = initiative.issue.id, member_id = active_trustee_id
bsw@1045:               }
bsw@1045:             }
bsw@1045:           elseif not initiative.issue.closed then
bsw@1045:             ui.link {
bsw@1045:               attr = { class = "btn btn-default" },
bsw@1045:               module = "vote", view = "list", 
bsw@1045:               params = { issue_id = initiative.issue.id },
bsw@1045:               text = _"vote now"
bsw@1045:             }
bsw@1045:           end
bsw@1045:         elseif initiative.member_info.supported then
bsw@1045:           if initiative.member_info.satisfied then
bsw@1045:             ui.image { attr = { class = "icon48 right" }, static = "icons/32/support_satisfied.png" }
bsw@1045:           else
bsw@1045:             ui.image { attr = { class = "icon48 right" }, static = "icons/32/support_unsatisfied.png" }
bsw@1045:           end           
bsw@1045:           ui.container { content = _"You are supporter" }
bsw@1045: 
bsw@1045:           if initiative.issue.member_info.own_participation then
bsw@1045:             ui.link {
bsw@1045:               attr = { class = "btn-link" },
bsw@1045:               module = "initiative", action = "remove_support", 
bsw@1045:               routing = { default = {
bsw@1045:                 mode = "redirect", module = "initiative", view = "show", id = initiative.id
bsw@1045:               } },
bsw@1045:               id = initiative.id,
bsw@1123:               text = _"remove my support"
bsw@1045:             }
bsw@1045:             
bsw@1045:           else
bsw@1045:             
bsw@1045:             ui.link {
bsw@1045:               module = "delegation", view = "show", params = {
bsw@1045:                 issue_id = initiative.issue_id,
bsw@1045:                 initiative_id = initiative.id
bsw@1045:               },
bsw@1045:               content = _"via delegation" 
bsw@1045:             }
bsw@1045:             
bsw@1045:           end
bsw@1045:           
bsw@1045:           slot.put(" ")
bsw@1045:       
bsw@1045: 
bsw@1144:         elseif not initiative.issue.closed then
bsw@1045:           ui.link {
bsw@1045:             attr = { class = "btn btn-default" },
bsw@1045:             module = "initiative", action = "add_support", 
bsw@1045:             routing = { default = {
bsw@1045:               mode = "redirect", module = "initiative", view = "show", id = initiative.id
bsw@1045:             } },
bsw@1045:             id = initiative.id,
bsw@1045:             text = _"add my support"
bsw@1045:           }
bsw@1045:             
bsw@1045:         end
bsw@1045:       end }
bsw@1045:       
bsw@1045:     end
bsw@1045:     
bsw@1045:     slot.put("
")
bsw@1045: 
bsw@1045:     ui.container {
bsw@1045:       attr = { class = "initiators" },
bsw@1045:       content = function ()
bsw@1045:       
bsw@1045:         if app.session:has_access("authors_pseudonymous") then
bsw@1045:           for i, member in ipairs(initiators) do
bsw@1045:             if i > 1 then
bsw@1045:               slot.put(" ")
bsw@1045:             end
bsw@1045:             util.micro_avatar(member)
bsw@1045:             if member.accepted == nil then
bsw@1045:               slot.put ( " " )
bsw@1045:               ui.tag { content = _"(invited)" }
bsw@1045:             end
bsw@1045:           end -- for i, member
bsw@1045:           
bsw@1045:         end
bsw@1045:           
bsw@1045:       end
bsw@1045:     } -- ui.container "initiators"
bsw@1045: 
bsw@1045:     ui.container {
bsw@1045:       attr = { class = "links" },
bsw@1045:       content = function ()
bsw@1045:         
bsw@1045:         local drafts_count = initiative:get_reference_selector("drafts"):count()
bsw@1045:         ui.link {
bsw@1045:           content = _("suggestions (#{count}) ↓", {
bsw@1045:             count = # ( initiative.suggestions )
bsw@1045:           }),
bsw@1045:           external = "#suggestions"
bsw@1045:         }
bsw@1045: 
bsw@1045:         slot.put ( " | " )
bsw@1045:           
bsw@1045:         ui.link{
bsw@1045:           module = "initiative", view = "history", id = initiative.id,
bsw@1045:           content = _("draft history (#{count})", { count = drafts_count })
bsw@1045:         }
bsw@1045:         
bsw@1045:       end
bsw@1045:     } -- ui.containers "links"
bsw@1045:   end )
bsw@1045:  
bsw@1045:   execute.view {
bsw@1045:     module = "initiative", view = "_sidebar_state",
bsw@1045:     params = { initiative = initiative }
bsw@1045:   }
bsw@1045: