liquid_feedback_frontend

annotate app/main/initiative/_show.lua @ 552:3344717939f0

Improved interest and support filters for issues
author bsw
date Fri Jun 15 20:46:25 2012 +0200 (2012-06-15)
parents 4cee33ad5e16
children e7baf2713987
rev   line source
bsw/jbe@19 1 local initiative = param.get("initiative", "table")
bsw/jbe@19 2
bsw@272 3 local initiators_members_selector = initiative:get_reference_selector("initiating_members")
bsw@272 4 :add_field("initiator.accepted", "accepted")
bsw@280 5 :add_order_by("member.name")
bsw@280 6 if initiator and initiator.accepted then
bsw@280 7 initiators_members_selector:add_where("initiator.accepted ISNULL OR initiator.accepted")
bsw@280 8 else
bsw@272 9 initiators_members_selector:add_where("initiator.accepted")
bsw@272 10 end
bsw@272 11
bsw@272 12 local initiators = initiators_members_selector:exec()
bsw@272 13
bsw@274 14
bsw@274 15 local initiatives_selector = initiative.issue:get_reference_selector("initiatives")
bsw@525 16 slot.select("head", function()
bsw@274 17 execute.view{
bsw@525 18 module = "issue",
bsw@525 19 view = "_show",
bsw@274 20 params = {
bsw@274 21 issue = initiative.issue,
bsw@525 22 initiative_limit = 3
bsw@274 23 }
bsw@274 24 }
bsw@274 25 end)
bsw@274 26
bsw@525 27 ui.container{ attr = { class = "initiative_head" }, content = function()
bsw@272 28
bsw@272 29 ui.container{
bsw@525 30 attr = { class = "title" },
bsw@272 31 content = _("Initiative i#{id}: #{name}", { id = initiative.id, name = initiative.name })
bsw@272 32 }
bsw@286 33
bsw@525 34 ui.container{ attr = { class = "content" }, content = function()
bsw@525 35 if app.session.member_id or config.public_access == "pseudonym" or config.public_access == "full" then
bsw@525 36 ui.tag{
bsw@525 37 attr = { class = "initiator_names" },
bsw@525 38 content = function()
bsw@525 39 for i, initiator in ipairs(initiators) do
bsw@525 40 slot.put(" ")
bsw@527 41 if app.session.member_id or config.public_access == "full" then
bsw@525 42 ui.link{
bsw@525 43 content = function ()
bsw@525 44 execute.view{
bsw@525 45 module = "member_image",
bsw@525 46 view = "_show",
bsw@525 47 params = {
bsw@525 48 member = initiator,
bsw@525 49 image_type = "avatar",
bsw@525 50 show_dummy = true,
bsw@525 51 class = "micro_avatar",
bsw@525 52 popup_text = text
bsw@525 53 }
bsw@525 54 }
bsw@525 55 end,
bsw@525 56 module = "member", view = "show", id = initiator.id
bsw@525 57 }
bsw@525 58 slot.put(" ")
bsw@525 59 end
bsw@458 60 ui.link{
bsw@525 61 text = initiator.name,
bsw@458 62 module = "member", view = "show", id = initiator.id
bsw@458 63 }
bsw@525 64 if not initiator.accepted then
bsw@525 65 ui.tag{ attr = { title = _"Not accepted yet" }, content = "?" }
bsw@525 66 end
bsw@313 67 end
bsw@272 68 end
bsw@313 69 }
bsw@313 70 end
bsw@525 71
bsw@525 72 if initiator and initiator.accepted and not initiative.issue.fully_frozen and not initiative.issue.closed and not initiative.revoked then
bsw@313 73 slot.put(" · ")
bsw@313 74 ui.link{
bsw@525 75 attr = { class = "action" },
bsw@525 76 content = function()
bsw@525 77 slot.put(_"Invite initiator")
bsw@525 78 end,
bsw@313 79 module = "initiative",
bsw@525 80 view = "add_initiator",
bsw@525 81 params = { initiative_id = initiative.id }
bsw@525 82 }
bsw@525 83 if #initiators > 1 then
bsw@525 84 slot.put(" · ")
bsw@525 85 ui.link{
bsw@525 86 content = function()
bsw@525 87 slot.put(_"Remove initiator")
bsw@525 88 end,
bsw@525 89 module = "initiative",
bsw@525 90 view = "remove_initiator",
bsw@525 91 params = { initiative_id = initiative.id }
bsw@525 92 }
bsw@525 93 end
bsw@525 94 end
bsw@525 95 if initiator and initiator.accepted == false then
bsw@525 96 slot.put(" · ")
bsw@525 97 ui.link{
bsw@525 98 text = _"Cancel refuse of invitation",
bsw@525 99 module = "initiative",
bsw@525 100 action = "remove_initiator",
bsw@525 101 params = {
bsw@525 102 initiative_id = initiative.id,
bsw@525 103 member_id = app.session.member.id
bsw@525 104 },
bsw@525 105 routing = {
bsw@525 106 ok = {
bsw@525 107 mode = "redirect",
bsw@525 108 module = "initiative",
bsw@525 109 view = "show",
bsw@525 110 id = initiative.id
bsw@525 111 }
bsw@313 112 }
bsw@313 113 }
bsw@525 114 end
bsw@525 115 end }
bsw@525 116 ui.container{ attr = { class = "content" }, content = function()
bsw@525 117 if app.session.member_id then
bsw@525 118 execute.view{
bsw@525 119 module = "supporter",
bsw@525 120 view = "_show_box",
bsw@525 121 params = {
bsw@525 122 initiative = initiative
bsw@525 123 }
bsw@313 124 }
bsw@525 125 end
bsw@313 126
bsw@525 127 end }
bsw@525 128
bsw@525 129 end }
bsw@313 130
bsw@313 131
bsw/jbe@19 132 util.help("initiative.show")
bsw/jbe@19 133
bsw@525 134 --slot.select("initiative_head", function()
bsw@272 135
bsw@493 136 if initiative.issue.ranks_available and initiative.admitted then
bsw@493 137 local class = initiative.winner and "admitted_info" or "not_admitted_info"
bsw@493 138 ui.container{
bsw@493 139 attr = { class = class },
bsw@493 140 content = function()
bsw@493 141 local max_value = initiative.issue.voter_count
bsw@493 142 slot.put(" ")
bsw@493 143 local positive_votes = initiative.positive_votes
bsw@493 144 local negative_votes = initiative.negative_votes
bsw@493 145 local sum_votes = initiative.positive_votes + initiative.negative_votes
bsw@493 146 local function perc(votes, sum)
bsw@493 147 if sum > 0 and votes > 0 then return " (" .. string.format( "%.f", votes * 100 / sum ) .. "%)" end
bsw@493 148 return ""
bsw@493 149 end
bsw@493 150 slot.put(_"Yes" .. ": <b>" .. tostring(positive_votes) .. perc(positive_votes, sum_votes) .. "</b>")
bsw@493 151 slot.put(" &middot; ")
bsw@493 152 slot.put(_"Abstention" .. ": <b>" .. tostring(max_value - initiative.negative_votes - initiative.positive_votes) .. "</b>")
bsw@493 153 slot.put(" &middot; ")
bsw@493 154 slot.put(_"No" .. ": <b>" .. tostring(initiative.negative_votes) .. perc(negative_votes, sum_votes) .. "</b>")
bsw@493 155 slot.put(" &middot; ")
bsw@493 156 slot.put("<b>")
bsw@493 157 if initiative.winner then
bsw@493 158 slot.put(_"Approved")
bsw@493 159 elseif initiative.rank then
bsw@493 160 slot.put(_("Not approved (rank #{rank})", { rank = initiative.rank }))
bsw@493 161 else
bsw@493 162 slot.put(_"Not approved")
bsw@493 163 end
bsw@493 164 slot.put("</b>")
poelzi@167 165 end
bsw@493 166 }
bsw@493 167 end
bsw/jbe@19 168
bsw@493 169 if initiative.admitted == false then
bsw@493 170 local policy = initiative.issue.policy
bsw@493 171 ui.container{
bsw@493 172 attr = { class = "not_admitted_info" },
bsw@493 173 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 174 }
bsw@493 175 end
bsw/jbe@19 176
bsw@493 177 if initiative.revoked then
bsw@493 178 ui.container{
bsw@493 179 attr = { class = "revoked_info" },
bsw@493 180 content = function()
bsw@493 181 slot.put(_("This initiative has been revoked at #{revoked}", { revoked = format.timestamp(initiative.revoked) }))
bsw@493 182 local suggested_initiative = initiative.suggested_initiative
bsw@493 183 if suggested_initiative then
bsw@493 184 slot.put("<br /><br />")
bsw@493 185 slot.put(_("The initiators suggest to support the following initiative:"))
bsw@493 186 slot.put(" ")
bsw@493 187 ui.link{
bsw@493 188 content = _("Issue ##{id}", { id = suggested_initiative.issue.id } ) .. ": " .. encode.html(suggested_initiative.name),
bsw@493 189 module = "initiative",
bsw@493 190 view = "show",
bsw@493 191 id = suggested_initiative.id
bsw@493 192 }
bsw@493 193 end
bsw/jbe@19 194 end
bsw@493 195 }
bsw@493 196 end
bsw@493 197
bsw@525 198 --end)
bsw/jbe@19 199
bsw@41 200 if initiator and initiator.accepted == nil and not initiative.issue.half_frozen and not initiative.issue.closed then
bsw/jbe@19 201 ui.container{
bsw/jbe@19 202 attr = { class = "initiator_invite_info" },
bsw/jbe@19 203 content = function()
bsw/jbe@19 204 slot.put(_"You are invited to become initiator of this initiative.")
bsw/jbe@19 205 slot.put(" ")
bsw/jbe@19 206 ui.link{
bsw/jbe@19 207 image = { static = "icons/16/tick.png" },
bsw/jbe@19 208 text = _"Accept invitation",
bsw/jbe@19 209 module = "initiative",
bsw/jbe@19 210 action = "accept_invitation",
bsw/jbe@19 211 id = initiative.id,
bsw/jbe@19 212 routing = {
bsw/jbe@19 213 default = {
bsw/jbe@19 214 mode = "redirect",
bsw/jbe@19 215 module = request.get_module(),
bsw/jbe@19 216 view = request.get_view(),
bsw/jbe@19 217 id = param.get_id_cgi(),
bsw/jbe@19 218 params = param.get_all_cgi()
bsw/jbe@19 219 }
bsw/jbe@19 220 }
bsw/jbe@19 221 }
bsw/jbe@19 222 slot.put(" ")
bsw/jbe@19 223 ui.link{
bsw/jbe@19 224 image = { static = "icons/16/cross.png" },
bsw/jbe@19 225 text = _"Refuse invitation",
bsw/jbe@19 226 module = "initiative",
bsw/jbe@19 227 action = "reject_initiator_invitation",
bsw/jbe@19 228 params = {
bsw/jbe@19 229 initiative_id = initiative.id,
bsw/jbe@19 230 member_id = app.session.member.id
bsw/jbe@19 231 },
bsw/jbe@19 232 routing = {
bsw/jbe@19 233 default = {
bsw/jbe@19 234 mode = "redirect",
bsw/jbe@19 235 module = request.get_module(),
bsw/jbe@19 236 view = request.get_view(),
bsw/jbe@19 237 id = param.get_id_cgi(),
bsw/jbe@19 238 params = param.get_all_cgi()
bsw/jbe@19 239 }
bsw/jbe@19 240 }
bsw/jbe@19 241 }
bsw/jbe@19 242 end
bsw/jbe@19 243 }
bsw/jbe@19 244 slot.put("<br />")
bsw/jbe@19 245 end
bsw/jbe@19 246
bsw/jbe@19 247
bsw@51 248 local supporter
bsw@51 249
bsw@51 250 if app.session.member_id then
bsw@51 251 supporter = app.session.member:get_reference_selector("supporters")
bsw@51 252 :add_where{ "initiative_id = ?", initiative.id }
bsw@51 253 :optional_object_mode()
bsw@51 254 :exec()
bsw@51 255 end
bsw/jbe@19 256
bsw/jbe@19 257 if supporter and not initiative.issue.closed then
bsw/jbe@19 258 local old_draft_id = supporter.draft_id
bsw/jbe@19 259 local new_draft_id = initiative.current_draft.id
bsw/jbe@19 260 if old_draft_id ~= new_draft_id then
bsw/jbe@19 261 ui.container{
bsw/jbe@19 262 attr = { class = "draft_updated_info" },
bsw/jbe@19 263 content = function()
bsw/jbe@19 264 slot.put(_"The draft of this initiative has been updated!")
bsw/jbe@19 265 slot.put(" ")
bsw/jbe@19 266 ui.link{
bsw/jbe@19 267 content = _"Show diff",
bsw/jbe@19 268 module = "draft",
bsw/jbe@19 269 view = "diff",
bsw/jbe@19 270 params = {
bsw/jbe@19 271 old_draft_id = old_draft_id,
bsw/jbe@19 272 new_draft_id = new_draft_id
bsw/jbe@19 273 }
bsw/jbe@19 274 }
bsw@75 275 if not initiative.revoked then
bsw@75 276 slot.put(" ")
bsw@75 277 ui.link{
bsw@75 278 text = _"Refresh support to current draft",
bsw@75 279 module = "initiative",
bsw@75 280 action = "add_support",
bsw@75 281 id = initiative.id,
bsw@75 282 routing = {
bsw@75 283 default = {
bsw@75 284 mode = "redirect",
bsw@75 285 module = "initiative",
bsw@75 286 view = "show",
bsw@75 287 id = initiative.id
bsw@75 288 }
bsw/jbe@19 289 }
bsw/jbe@19 290 }
bsw@75 291 end
bsw/jbe@19 292 end
bsw/jbe@19 293 }
bsw/jbe@19 294 end
bsw/jbe@19 295 end
bsw/jbe@19 296
bsw/jbe@19 297 execute.view{
bsw/jbe@19 298 module = "initiative",
bsw/jbe@19 299 view = "show_tab",
bsw/jbe@19 300 params = {
bsw/jbe@19 301 initiative = initiative,
bsw/jbe@19 302 initiator = initiator
bsw/jbe@19 303 }
bsw/jbe@19 304 }
bsw/jbe@19 305
bsw@280 306 if initiative.issue.snapshot then
bsw@431 307 slot.put("<br />")
bsw@280 308 ui.field.timestamp{ label = _"Last snapshot:", value = initiative.issue.snapshot }
bsw@280 309 end
bsw@280 310
bsw@280 311
bsw@286 312

Impressum / About Us