bsw@725: local initiative = param.get("initiative", "table") bsw@725: bsw@725: local show_as_head = param.get("show_as_head", atom.boolean) bsw@725: bsw@725: initiative:load_everything_for_member_id(app.session.member_id) bsw@725: bsw@725: local issue = initiative.issue bsw@725: bsw@725: -- TODO performance bsw@725: local initiator bsw@725: if app.session.member_id then bsw@725: initiator = Initiator:by_pk(initiative.id, app.session.member.id) bsw@725: end bsw@725: bsw@725: if app.session.member_id then bsw@725: issue:load_everything_for_member_id(app.session.member_id) bsw@725: end bsw@725: bsw@725: app.html_title.title = initiative.name bsw@725: app.html_title.subtitle = _("Initiative ##{id}", { id = initiative.id }) bsw@725: bsw@725: slot.select("head", function() bsw@725: execute.view{ bsw@725: module = "issue", view = "_head", bsw@725: params = { issue = issue, initiative = initiative } bsw@725: } bsw@725: end) bsw@725: bsw@725: local initiators_members_selector = initiative:get_reference_selector("initiating_members") bsw@725: :add_field("initiator.accepted", "accepted") bsw@725: :add_order_by("member.name") bsw@725: if initiator and initiator.accepted then bsw@725: initiators_members_selector:add_where("initiator.accepted ISNULL OR initiator.accepted") bsw@725: else bsw@725: initiators_members_selector:add_where("initiator.accepted") bsw@725: end bsw@725: bsw@725: local initiators = initiators_members_selector:exec() bsw@725: bsw@725: bsw@725: local initiatives_selector = initiative.issue:get_reference_selector("initiatives") bsw@725: slot.select("head", function() bsw@725: execute.view{ bsw@725: module = "issue", bsw@725: view = "_show", bsw@725: params = { bsw@725: issue = initiative.issue, bsw@725: initiative_limit = 3, bsw@725: for_initiative = initiative bsw@725: } bsw@725: } bsw@725: end) bsw@725: bsw@725: util.help("initiative.show") bsw@725: bsw@898: local class = "initiative_head" bsw@898: bsw@898: if initiative.polling then bsw@898: class = class .. " polling" bsw@898: end bsw@898: bsw@898: ui.container{ attr = { class = class }, content = function() bsw@725: bsw@725: local text = _("Initiative i#{id}: #{name}", { id = initiative.id, name = initiative.name }) bsw@725: if show_as_head then bsw@725: ui.link{ bsw@725: attr = { class = "title" }, text = text, bsw@725: module = "initiative", view = "show", id = initiative.id bsw@725: } bsw@725: else bsw@725: ui.container{ attr = { class = "title" }, content = text } bsw@725: end bsw@813: if app.session:has_access("authors_pseudonymous") then bsw@727: ui.container{ attr = { class = "content" }, content = function() bsw@725: ui.tag{ bsw@725: attr = { class = "initiator_names" }, bsw@725: content = function() bsw@725: for i, initiator in ipairs(initiators) do bsw@725: slot.put(" ") bsw@813: if app.session:has_access("all_pseudonymous") then bsw@725: ui.link{ bsw@725: content = function () bsw@725: execute.view{ bsw@725: module = "member_image", bsw@725: view = "_show", bsw@725: params = { bsw@725: member = initiator, bsw@725: image_type = "avatar", bsw@725: show_dummy = true, bsw@725: class = "micro_avatar", bsw@725: popup_text = text bsw@725: } bsw@725: } bsw@725: end, bsw@725: module = "member", view = "show", id = initiator.id bsw@725: } bsw@725: slot.put(" ") bsw@725: end bsw@725: ui.link{ bsw@725: text = initiator.name, bsw@725: module = "member", view = "show", id = initiator.id bsw@725: } bsw@725: if not initiator.accepted then bsw@725: ui.tag{ attr = { title = _"Not accepted yet" }, content = "?" } bsw@725: end bsw@725: end bsw@725: if initiator and initiator.accepted and not initiative.issue.fully_frozen and not initiative.issue.closed and not initiative.revoked then bsw@725: slot.put(" · ") bsw@725: ui.link{ bsw@725: attr = { class = "action" }, bsw@725: content = function() bsw@725: slot.put(_"Invite initiator") bsw@725: end, bsw@725: module = "initiative", bsw@725: view = "add_initiator", bsw@725: params = { initiative_id = initiative.id } bsw@725: } bsw@725: if #initiators > 1 then bsw@725: slot.put(" · ") bsw@725: ui.link{ bsw@725: content = function() bsw@725: slot.put(_"Remove initiator") bsw@725: end, bsw@725: module = "initiative", bsw@725: view = "remove_initiator", bsw@725: params = { initiative_id = initiative.id } bsw@725: } bsw@725: end bsw@725: end bsw@725: if initiator and initiator.accepted == false then bsw@725: slot.put(" · ") bsw@725: ui.link{ bsw@725: text = _"Cancel refuse of invitation", bsw@725: module = "initiative", bsw@725: action = "remove_initiator", bsw@725: params = { bsw@725: initiative_id = initiative.id, bsw@725: member_id = app.session.member.id bsw@725: }, bsw@725: routing = { bsw@725: ok = { bsw@725: mode = "redirect", bsw@725: module = "initiative", bsw@725: view = "show", bsw@725: id = initiative.id bsw@725: } bsw@725: } bsw@725: } bsw@725: end bsw@725: if (initiative.discussion_url and #initiative.discussion_url > 0) then bsw@725: slot.put(" · ") bsw@725: if initiative.discussion_url:find("^https?://") then bsw@725: if initiative.discussion_url and #initiative.discussion_url > 0 then bsw@725: ui.link{ bsw@725: attr = { bsw@725: target = "_blank", bsw@725: title = _"Discussion with initiators" bsw@725: }, bsw@725: text = _"Discuss with initiators", bsw@725: external = initiative.discussion_url bsw@725: } bsw@725: end bsw@725: else bsw@725: slot.put(encode.html(initiative.discussion_url)) bsw@725: end bsw@725: end bsw@725: if initiator and initiator.accepted and not initiative.issue.half_frozen and not initiative.issue.closed and not initiative.revoked then bsw@725: slot.put(" · ") bsw@725: ui.link{ bsw@725: text = _"change discussion URL", bsw@725: module = "initiative", bsw@725: view = "edit", bsw@725: id = initiative.id bsw@725: } bsw@725: slot.put(" ") bsw@725: end bsw@725: end bsw@725: } bsw@727: end } bsw@727: end bsw@725: bsw@727: if app.session.member_id then bsw@727: ui.container{ attr = { class = "content" }, content = function() bsw@725: execute.view{ bsw@725: module = "supporter", bsw@725: view = "_show_box", bsw@725: params = { bsw@725: initiative = initiative bsw@725: } bsw@725: } bsw@727: end } bsw@727: end bsw@725: bsw@725: bsw@725: -- voting results bsw@725: if initiative.issue.ranks_available and initiative.admitted then bsw@725: local class = initiative.winner and "admitted_info" or "not_admitted_info" bsw@725: ui.container{ bsw@725: attr = { class = class }, bsw@725: content = function() bsw@725: local max_value = initiative.issue.voter_count bsw@725: slot.put(" ") bsw@725: local positive_votes = initiative.positive_votes bsw@725: local negative_votes = initiative.negative_votes bsw@725: local sum_votes = initiative.positive_votes + initiative.negative_votes bsw@725: local function perc(votes, sum) bsw@725: if sum > 0 and votes > 0 then return " (" .. string.format( "%.f", votes * 100 / sum ) .. "%)" end bsw@725: return "" bsw@725: end bsw@725: slot.put(_"Yes" .. ": " .. tostring(positive_votes) .. perc(positive_votes, sum_votes) .. "") bsw@725: slot.put(" · ") bsw@725: slot.put(_"Abstention" .. ": " .. tostring(max_value - initiative.negative_votes - initiative.positive_votes) .. "") bsw@725: slot.put(" · ") bsw@725: slot.put(_"No" .. ": " .. tostring(initiative.negative_votes) .. perc(negative_votes, sum_votes) .. "") bsw@725: slot.put(" · ") bsw@725: slot.put("") bsw@725: if initiative.winner then bsw@725: slot.put(_"Approved") bsw@725: elseif initiative.rank then bsw@725: slot.put(_("Not approved (rank #{rank})", { rank = initiative.rank })) bsw@725: else bsw@725: slot.put(_"Not approved") bsw@725: end bsw@725: slot.put("") bsw@725: end bsw@725: } bsw@725: end bsw@725: bsw@725: ui.container{ attr = { class = "content" }, content = function() bsw@725: execute.view{ bsw@725: module = "initiative", bsw@725: view = "_battles", bsw@725: params = { initiative = initiative } bsw@725: } bsw@725: end } bsw@725: bsw@725: -- initiative not admitted info bsw@725: if initiative.admitted == false then bsw@725: local policy = initiative.issue.policy bsw@725: ui.container{ bsw@725: attr = { class = "not_admitted_info" }, bsw@725: 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: } bsw@725: end bsw@725: bsw@725: -- initiative revoked info bsw@725: if initiative.revoked then bsw@725: ui.container{ bsw@725: attr = { class = "revoked_info" }, bsw@725: content = function() bsw@725: slot.put(_("This initiative has been revoked at #{revoked}", { revoked = format.timestamp(initiative.revoked) })) bsw@725: local suggested_initiative = initiative.suggested_initiative bsw@725: if suggested_initiative then bsw@725: slot.put("

") bsw@725: slot.put(_("The initiators suggest to support the following initiative:")) bsw@725: slot.put(" ") bsw@725: ui.link{ bsw@725: content = _("Issue ##{id}", { id = suggested_initiative.issue.id } ) .. ": " .. encode.html(suggested_initiative.name), bsw@725: module = "initiative", bsw@725: view = "show", bsw@725: id = suggested_initiative.id bsw@725: } bsw@725: end bsw@725: end bsw@725: } bsw@725: end bsw@725: bsw@725: bsw@725: -- invited as initiator bsw@725: if initiator and initiator.accepted == nil and not initiative.issue.half_frozen and not initiative.issue.closed then bsw@725: ui.container{ bsw@725: attr = { class = "initiator_invite_info" }, bsw@725: content = function() bsw@725: slot.put(_"You are invited to become initiator of this initiative.") bsw@725: slot.put(" ") bsw@725: ui.link{ bsw@725: image = { static = "icons/16/tick.png" }, bsw@725: text = _"Accept invitation", bsw@725: module = "initiative", bsw@725: action = "accept_invitation", bsw@725: id = initiative.id, bsw@725: routing = { bsw@725: default = { bsw@725: mode = "redirect", bsw@725: module = request.get_module(), bsw@725: view = request.get_view(), bsw@725: id = param.get_id_cgi(), bsw@725: params = param.get_all_cgi() bsw@725: } bsw@725: } bsw@725: } bsw@725: slot.put(" ") bsw@725: ui.link{ bsw@725: image = { static = "icons/16/cross.png" }, bsw@725: text = _"Refuse invitation", bsw@725: module = "initiative", bsw@725: action = "reject_initiator_invitation", bsw@725: params = { bsw@725: initiative_id = initiative.id, bsw@725: member_id = app.session.member.id bsw@725: }, bsw@725: routing = { bsw@725: default = { bsw@725: mode = "redirect", bsw@725: module = request.get_module(), bsw@725: view = request.get_view(), bsw@725: id = param.get_id_cgi(), bsw@725: params = param.get_all_cgi() bsw@725: } bsw@725: } bsw@725: } bsw@725: end bsw@725: } bsw@725: end bsw@725: bsw@725: -- draft updated bsw@725: local supporter bsw@725: bsw@725: if app.session.member_id then bsw@725: supporter = app.session.member:get_reference_selector("supporters") bsw@725: :add_where{ "initiative_id = ?", initiative.id } bsw@725: :optional_object_mode() bsw@725: :exec() bsw@725: end bsw@725: bsw@725: if supporter and not initiative.issue.closed then bsw@725: local old_draft_id = supporter.draft_id bsw@725: local new_draft_id = initiative.current_draft.id bsw@725: if old_draft_id ~= new_draft_id then bsw@725: ui.container{ bsw@725: attr = { class = "draft_updated_info" }, bsw@725: content = function() bsw@725: slot.put(_"The draft of this initiative has been updated!") bsw@725: slot.put(" ") bsw@725: ui.link{ bsw@725: content = _"Show diff", bsw@725: module = "draft", bsw@725: view = "diff", bsw@725: params = { bsw@725: old_draft_id = old_draft_id, bsw@725: new_draft_id = new_draft_id bsw@725: } bsw@725: } bsw@725: if not initiative.revoked then bsw@725: slot.put(" ") bsw@725: ui.link{ bsw@725: text = _"Refresh support to current draft", bsw@725: module = "initiative", bsw@725: action = "add_support", bsw@725: id = initiative.id, bsw@725: routing = { bsw@725: default = { bsw@725: mode = "redirect", bsw@725: module = "initiative", bsw@725: view = "show", bsw@725: id = initiative.id bsw@725: } bsw@725: } bsw@725: } bsw@725: end bsw@725: end bsw@725: } bsw@725: end bsw@725: end bsw@725: bsw@725: if not show_as_head then bsw@725: local drafts_count = initiative:get_reference_selector("drafts"):count() bsw@725: bsw@725: ui.container{ attr = { class = "content" }, content = function() bsw@725: bsw@725: if initiator and initiator.accepted and not initiative.issue.half_frozen and not initiative.issue.closed and not initiative.revoked then bsw@725: ui.link{ bsw@725: content = function() bsw@725: slot.put(_"Edit draft") bsw@725: end, bsw@725: module = "draft", bsw@725: view = "new", bsw@725: params = { initiative_id = initiative.id } bsw@725: } bsw@725: slot.put(" · ") bsw@725: ui.link{ bsw@725: content = function() bsw@725: slot.put(_"Revoke initiative") bsw@725: end, bsw@725: module = "initiative", bsw@725: view = "revoke", bsw@725: id = initiative.id bsw@725: } bsw@725: slot.put(" · ") bsw@725: end bsw@725: bsw@725: ui.tag{ bsw@725: attr = { class = "draft_version" }, bsw@725: content = _("Latest draft created at #{date} #{time}", { bsw@725: date = format.date(initiative.current_draft.created), bsw@725: time = format.time(initiative.current_draft.created) bsw@725: }) bsw@725: } bsw@725: if drafts_count > 1 then bsw@725: slot.put(" · ") bsw@725: ui.link{ bsw@725: module = "draft", view = "list", params = { initiative_id = initiative.id }, bsw@725: text = _("List all revisions (#{count})", { count = drafts_count }) bsw@725: } bsw@725: end bsw@725: end } bsw@725: bsw@725: execute.view{ bsw@725: module = "draft", bsw@725: view = "_show", bsw@725: params = { bsw@725: draft = initiative.current_draft bsw@725: } bsw@725: } bsw@725: end bsw@725: end } bsw@725: bsw@725: if not show_as_head then bsw@725: execute.view{ bsw@725: module = "suggestion", bsw@725: view = "_list", bsw@725: params = { bsw@725: initiative = initiative, bsw@725: suggestions_selector = initiative:get_reference_selector("suggestions"), bsw@725: tab_id = param.get("tab_id") bsw@725: } bsw@725: } bsw@725: bsw@725: bsw@813: if app.session:has_access("all_pseudonymous") then bsw@725: if initiative.issue.ranks_available then bsw@725: local members_selector = initiative.issue:get_reference_selector("direct_voters") bsw@725: :left_join("vote", nil, { "vote.initiative_id = ? AND vote.member_id = member.id", initiative.id }) bsw@725: :add_field("direct_voter.weight as voter_weight") bsw@725: :add_field("coalesce(vote.grade, 0) as grade") bsw@879: :add_field("direct_voter.comment as voter_comment") bsw@725: :left_join("initiative", nil, "initiative.id = vote.initiative_id") bsw@725: :left_join("issue", nil, "issue.id = initiative.issue_id") bsw@725: bsw@907: ui.anchor{ name = "voter", attr = { class = "heading" }, content = _"Voters" } bsw@725: bsw@725: execute.view{ bsw@725: module = "member", bsw@725: view = "_list", bsw@725: params = { bsw@725: initiative = initiative, bsw@725: for_votes = true, bsw@725: members_selector = members_selector, bsw@725: paginator_name = "voter" bsw@725: } bsw@725: } bsw@725: end bsw@725: bsw@725: local members_selector = initiative:get_reference_selector("supporting_members_snapshot") bsw@725: :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id") bsw@725: :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: :add_field("direct_interest_snapshot.weight") bsw@725: :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event") bsw@725: :add_where("direct_supporter_snapshot.satisfied") bsw@725: :add_field("direct_supporter_snapshot.informed", "is_informed") bsw@725: bsw@725: if members_selector:count() > 0 then bsw@725: if issue.fully_frozen then bsw@725: ui.anchor{ name = "supporters", attr = { class = "heading" }, content = _"Supporters (before begin of voting)" } bsw@725: else bsw@725: ui.anchor{ name = "supporters", attr = { class = "heading" }, content = _"Supporters" } bsw@725: end bsw@725: bsw@725: execute.view{ bsw@725: module = "member", bsw@725: view = "_list", bsw@725: params = { bsw@725: initiative = initiative, bsw@725: members_selector = members_selector, bsw@725: paginator_name = "supporters" bsw@725: } bsw@725: } bsw@725: else bsw@725: if issue.fully_frozen then bsw@725: ui.anchor{ name = "supporters", attr = { class = "heading" }, content = _"No supporters (before begin of voting)" } bsw@725: else bsw@725: ui.anchor{ name = "supporters", attr = { class = "heading" }, content = _"No supporters" } bsw@725: end bsw@725: slot.put("
") bsw@725: end bsw@725: bsw@725: local members_selector = initiative:get_reference_selector("supporting_members_snapshot") bsw@725: :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id") bsw@725: :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: :add_field("direct_interest_snapshot.weight") bsw@725: :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event") bsw@725: :add_where("NOT direct_supporter_snapshot.satisfied") bsw@725: :add_field("direct_supporter_snapshot.informed", "is_informed") bsw@725: bsw@725: if members_selector:count() > 0 then bsw@725: if issue.fully_frozen then bsw@725: ui.anchor{ name = "potential_supporters", attr = { class = "heading" }, content = _"Potential supporters (before begin of voting)" } bsw@725: else bsw@725: ui.anchor{ name = "potential_supporters", attr = { class = "heading" }, content = _"Potential supporters" } bsw@725: end bsw@725: bsw@725: execute.view{ bsw@725: module = "member", bsw@725: view = "_list", bsw@725: params = { bsw@725: initiative = initiative, bsw@725: members_selector = members_selector, bsw@725: paginator_name = "potential_supporters" bsw@725: } bsw@725: } bsw@725: else bsw@725: if issue.fully_frozen then bsw@725: ui.anchor{ name = "potential_supporters", attr = { class = "heading" }, content = _"No potential supporters (before begin of voting)" } bsw@725: else bsw@725: ui.anchor{ name = "potential_supporters", attr = { class = "heading" }, content = _"No potential supporters" } bsw@725: end bsw@725: slot.put("
") bsw@725: end bsw@725: bsw@725: ui.container{ attr = { class = "heading" }, content = _"Details" } bsw@725: execute.view { bsw@725: module = "initiative", bsw@725: view = "_details", bsw@725: params = { bsw@725: initiative = initiative, bsw@725: members_selector = members_selector bsw@725: } bsw@725: } bsw@725: bsw@725: end bsw@725: end