bsw@31: local initiative = param.get("initiative", "table") bsw@31: bsw@31: if not initiative.issue.closed then bsw@31: return bsw@31: end bsw@31: bsw@31: local battled_initiatives = Initiative:new_selector() bsw@31: :add_field("winning_battle.count", "winning_count") bsw@31: :add_field("losing_battle.count", "losing_count") bsw@31: :join("battle", "winning_battle", { "winning_battle.winning_initiative_id = ? AND winning_battle.losing_initiative_id = initiative.id", initiative.id }) bsw@31: :join("battle", "losing_battle", { "losing_battle.losing_initiative_id = ? AND losing_battle.winning_initiative_id = initiative.id", initiative.id }) bsw@31: :add_order_by("rank") bsw@31: :exec() bsw@31: bsw@31: bsw@31: local number_of_initiatives = Initiative:new_selector() bsw@31: :add_where{ "issue_id = ?", initiative.issue_id } bsw@31: :add_where("admitted") bsw@31: :count() bsw@31: bsw@31: if number_of_initiatives > 1 then bsw@31: ui.container{ bsw@31: attr = { class = "heading first" }, bsw@31: content = _"This initiative compared to alternative initiatives" bsw@31: } bsw@31: bsw@31: ui.list{ bsw@31: records = battled_initiatives, bsw@31: columns = { bsw@31: { bsw@31: content = function() bsw@31: slot.put(_"This initiative") bsw@31: end bsw@31: }, bsw@31: { bsw@31: content = function(record) bsw@31: local population = initiative.issue.voter_count bsw@31: local value = record.winning_count bsw@31: ui.bargraph{ bsw@31: class = "bargraph bargraph50", bsw@31: max_value = population, bsw@31: width = 50, bsw@31: bars = { bsw@31: { color = "#aaa", value = population - value }, bsw@31: { color = "#444", value = value }, bsw@31: } bsw@31: } bsw@31: end bsw@31: }, bsw@31: { bsw@31: content = function(record) bsw@31: slot.put(record.winning_count) bsw@31: end bsw@31: }, bsw@31: { bsw@31: content = function(record) bsw@31: if record.winning_count == record.losing_count then bsw@31: ui.image{ static = "icons/16/bullet_blue.png" } bsw@31: elseif record.winning_count > record.losing_count then bsw@31: ui.image{ static = "icons/16/resultset_previous.png" } bsw@31: else bsw@31: ui.image{ static = "icons/16/resultset_next.png" } bsw@31: end bsw@31: end bsw@31: }, bsw@31: { bsw@31: field_attr = { style = "text-align: right;" }, bsw@31: content = function(record) bsw@31: slot.put(record.losing_count) bsw@31: end bsw@31: }, bsw@31: { bsw@31: content = function(record) bsw@31: local population = initiative.issue.voter_count bsw@31: local value = record.losing_count bsw@31: ui.bargraph{ bsw@31: class = "bargraph bargraph50", bsw@31: max_value = population, bsw@31: width = 50, bsw@31: bars = { bsw@31: { color = "#444", value = value }, bsw@31: { color = "#aaa", value = population - value }, bsw@31: } bsw@31: } bsw@31: end bsw@31: }, bsw@31: { bsw@31: content = function(record) bsw@31: ui.link{ bsw@31: module = "initiative", bsw@31: view = "show", bsw@31: id = record.id, bsw@31: text = record.name bsw@31: } bsw@31: end bsw@31: } bsw@31: } bsw@31: } bsw@31: end