liquid_feedback_frontend

annotate app/main/initiative/_show.lua @ 725:344e5fdce8c9

Fixed public search, made draft history available again
author bsw
date Thu Jun 28 13:52:42 2012 +0200 (2012-06-28)
parents
children 161cebfc44d4
rev   line source
bsw@725 1 local initiative = param.get("initiative", "table")
bsw@725 2
bsw@725 3 local show_as_head = param.get("show_as_head", atom.boolean)
bsw@725 4
bsw@725 5 initiative:load_everything_for_member_id(app.session.member_id)
bsw@725 6
bsw@725 7 local issue = initiative.issue
bsw@725 8
bsw@725 9 -- TODO performance
bsw@725 10 local initiator
bsw@725 11 if app.session.member_id then
bsw@725 12 initiator = Initiator:by_pk(initiative.id, app.session.member.id)
bsw@725 13 end
bsw@725 14
bsw@725 15 if app.session.member_id then
bsw@725 16 issue:load_everything_for_member_id(app.session.member_id)
bsw@725 17 end
bsw@725 18
bsw@725 19 app.html_title.title = initiative.name
bsw@725 20 app.html_title.subtitle = _("Initiative ##{id}", { id = initiative.id })
bsw@725 21
bsw@725 22 slot.select("head", function()
bsw@725 23 execute.view{
bsw@725 24 module = "issue", view = "_head",
bsw@725 25 params = { issue = issue, initiative = initiative }
bsw@725 26 }
bsw@725 27 end)
bsw@725 28
bsw@725 29 local initiators_members_selector = initiative:get_reference_selector("initiating_members")
bsw@725 30 :add_field("initiator.accepted", "accepted")
bsw@725 31 :add_order_by("member.name")
bsw@725 32 if initiator and initiator.accepted then
bsw@725 33 initiators_members_selector:add_where("initiator.accepted ISNULL OR initiator.accepted")
bsw@725 34 else
bsw@725 35 initiators_members_selector:add_where("initiator.accepted")
bsw@725 36 end
bsw@725 37
bsw@725 38 local initiators = initiators_members_selector:exec()
bsw@725 39
bsw@725 40
bsw@725 41 local initiatives_selector = initiative.issue:get_reference_selector("initiatives")
bsw@725 42 slot.select("head", function()
bsw@725 43 execute.view{
bsw@725 44 module = "issue",
bsw@725 45 view = "_show",
bsw@725 46 params = {
bsw@725 47 issue = initiative.issue,
bsw@725 48 initiative_limit = 3,
bsw@725 49 for_initiative = initiative
bsw@725 50 }
bsw@725 51 }
bsw@725 52 end)
bsw@725 53
bsw@725 54 util.help("initiative.show")
bsw@725 55
bsw@725 56 ui.container{ attr = { class = "initiative_head" }, content = function()
bsw@725 57
bsw@725 58 local text = _("Initiative i#{id}: #{name}", { id = initiative.id, name = initiative.name })
bsw@725 59 if show_as_head then
bsw@725 60 ui.link{
bsw@725 61 attr = { class = "title" }, text = text,
bsw@725 62 module = "initiative", view = "show", id = initiative.id
bsw@725 63 }
bsw@725 64 else
bsw@725 65 ui.container{ attr = { class = "title" }, content = text }
bsw@725 66 end
bsw@725 67 ui.container{ attr = { class = "content" }, content = function()
bsw@725 68 if app.session.member_id or config.public_access == "pseudonym" or config.public_access == "full" then
bsw@725 69 ui.tag{
bsw@725 70 attr = { class = "initiator_names" },
bsw@725 71 content = function()
bsw@725 72 for i, initiator in ipairs(initiators) do
bsw@725 73 slot.put(" ")
bsw@725 74 if app.session.member_id or config.public_access == "full" then
bsw@725 75 ui.link{
bsw@725 76 content = function ()
bsw@725 77 execute.view{
bsw@725 78 module = "member_image",
bsw@725 79 view = "_show",
bsw@725 80 params = {
bsw@725 81 member = initiator,
bsw@725 82 image_type = "avatar",
bsw@725 83 show_dummy = true,
bsw@725 84 class = "micro_avatar",
bsw@725 85 popup_text = text
bsw@725 86 }
bsw@725 87 }
bsw@725 88 end,
bsw@725 89 module = "member", view = "show", id = initiator.id
bsw@725 90 }
bsw@725 91 slot.put(" ")
bsw@725 92 end
bsw@725 93 ui.link{
bsw@725 94 text = initiator.name,
bsw@725 95 module = "member", view = "show", id = initiator.id
bsw@725 96 }
bsw@725 97 if not initiator.accepted then
bsw@725 98 ui.tag{ attr = { title = _"Not accepted yet" }, content = "?" }
bsw@725 99 end
bsw@725 100 end
bsw@725 101 if initiator and initiator.accepted and not initiative.issue.fully_frozen and not initiative.issue.closed and not initiative.revoked then
bsw@725 102 slot.put(" · ")
bsw@725 103 ui.link{
bsw@725 104 attr = { class = "action" },
bsw@725 105 content = function()
bsw@725 106 slot.put(_"Invite initiator")
bsw@725 107 end,
bsw@725 108 module = "initiative",
bsw@725 109 view = "add_initiator",
bsw@725 110 params = { initiative_id = initiative.id }
bsw@725 111 }
bsw@725 112 if #initiators > 1 then
bsw@725 113 slot.put(" · ")
bsw@725 114 ui.link{
bsw@725 115 content = function()
bsw@725 116 slot.put(_"Remove initiator")
bsw@725 117 end,
bsw@725 118 module = "initiative",
bsw@725 119 view = "remove_initiator",
bsw@725 120 params = { initiative_id = initiative.id }
bsw@725 121 }
bsw@725 122 end
bsw@725 123 end
bsw@725 124 if initiator and initiator.accepted == false then
bsw@725 125 slot.put(" · ")
bsw@725 126 ui.link{
bsw@725 127 text = _"Cancel refuse of invitation",
bsw@725 128 module = "initiative",
bsw@725 129 action = "remove_initiator",
bsw@725 130 params = {
bsw@725 131 initiative_id = initiative.id,
bsw@725 132 member_id = app.session.member.id
bsw@725 133 },
bsw@725 134 routing = {
bsw@725 135 ok = {
bsw@725 136 mode = "redirect",
bsw@725 137 module = "initiative",
bsw@725 138 view = "show",
bsw@725 139 id = initiative.id
bsw@725 140 }
bsw@725 141 }
bsw@725 142 }
bsw@725 143 end
bsw@725 144 if (initiative.discussion_url and #initiative.discussion_url > 0) then
bsw@725 145 slot.put(" · ")
bsw@725 146 if initiative.discussion_url:find("^https?://") then
bsw@725 147 if initiative.discussion_url and #initiative.discussion_url > 0 then
bsw@725 148 ui.link{
bsw@725 149 attr = {
bsw@725 150 target = "_blank",
bsw@725 151 title = _"Discussion with initiators"
bsw@725 152 },
bsw@725 153 text = _"Discuss with initiators",
bsw@725 154 external = initiative.discussion_url
bsw@725 155 }
bsw@725 156 end
bsw@725 157 else
bsw@725 158 slot.put(encode.html(initiative.discussion_url))
bsw@725 159 end
bsw@725 160 end
bsw@725 161 if initiator and initiator.accepted and not initiative.issue.half_frozen and not initiative.issue.closed and not initiative.revoked then
bsw@725 162 slot.put(" · ")
bsw@725 163 ui.link{
bsw@725 164 text = _"change discussion URL",
bsw@725 165 module = "initiative",
bsw@725 166 view = "edit",
bsw@725 167 id = initiative.id
bsw@725 168 }
bsw@725 169 slot.put(" ")
bsw@725 170 end
bsw@725 171 end
bsw@725 172 }
bsw@725 173 end
bsw@725 174
bsw@725 175 end }
bsw@725 176 ui.container{ attr = { class = "content" }, content = function()
bsw@725 177 if app.session.member_id then
bsw@725 178 execute.view{
bsw@725 179 module = "supporter",
bsw@725 180 view = "_show_box",
bsw@725 181 params = {
bsw@725 182 initiative = initiative
bsw@725 183 }
bsw@725 184 }
bsw@725 185 end
bsw@725 186
bsw@725 187 end }
bsw@725 188
bsw@725 189
bsw@725 190 -- voting results
bsw@725 191 if initiative.issue.ranks_available and initiative.admitted then
bsw@725 192 local class = initiative.winner and "admitted_info" or "not_admitted_info"
bsw@725 193 ui.container{
bsw@725 194 attr = { class = class },
bsw@725 195 content = function()
bsw@725 196 local max_value = initiative.issue.voter_count
bsw@725 197 slot.put(" ")
bsw@725 198 local positive_votes = initiative.positive_votes
bsw@725 199 local negative_votes = initiative.negative_votes
bsw@725 200 local sum_votes = initiative.positive_votes + initiative.negative_votes
bsw@725 201 local function perc(votes, sum)
bsw@725 202 if sum > 0 and votes > 0 then return " (" .. string.format( "%.f", votes * 100 / sum ) .. "%)" end
bsw@725 203 return ""
bsw@725 204 end
bsw@725 205 slot.put(_"Yes" .. ": <b>" .. tostring(positive_votes) .. perc(positive_votes, sum_votes) .. "</b>")
bsw@725 206 slot.put(" &middot; ")
bsw@725 207 slot.put(_"Abstention" .. ": <b>" .. tostring(max_value - initiative.negative_votes - initiative.positive_votes) .. "</b>")
bsw@725 208 slot.put(" &middot; ")
bsw@725 209 slot.put(_"No" .. ": <b>" .. tostring(initiative.negative_votes) .. perc(negative_votes, sum_votes) .. "</b>")
bsw@725 210 slot.put(" &middot; ")
bsw@725 211 slot.put("<b>")
bsw@725 212 if initiative.winner then
bsw@725 213 slot.put(_"Approved")
bsw@725 214 elseif initiative.rank then
bsw@725 215 slot.put(_("Not approved (rank #{rank})", { rank = initiative.rank }))
bsw@725 216 else
bsw@725 217 slot.put(_"Not approved")
bsw@725 218 end
bsw@725 219 slot.put("</b>")
bsw@725 220 end
bsw@725 221 }
bsw@725 222 end
bsw@725 223
bsw@725 224 ui.container{ attr = { class = "content" }, content = function()
bsw@725 225 execute.view{
bsw@725 226 module = "initiative",
bsw@725 227 view = "_battles",
bsw@725 228 params = { initiative = initiative }
bsw@725 229 }
bsw@725 230 end }
bsw@725 231
bsw@725 232 -- initiative not admitted info
bsw@725 233 if initiative.admitted == false then
bsw@725 234 local policy = initiative.issue.policy
bsw@725 235 ui.container{
bsw@725 236 attr = { class = "not_admitted_info" },
bsw@725 237 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 238 }
bsw@725 239 end
bsw@725 240
bsw@725 241 -- initiative revoked info
bsw@725 242 if initiative.revoked then
bsw@725 243 ui.container{
bsw@725 244 attr = { class = "revoked_info" },
bsw@725 245 content = function()
bsw@725 246 slot.put(_("This initiative has been revoked at #{revoked}", { revoked = format.timestamp(initiative.revoked) }))
bsw@725 247 local suggested_initiative = initiative.suggested_initiative
bsw@725 248 if suggested_initiative then
bsw@725 249 slot.put("<br /><br />")
bsw@725 250 slot.put(_("The initiators suggest to support the following initiative:"))
bsw@725 251 slot.put(" ")
bsw@725 252 ui.link{
bsw@725 253 content = _("Issue ##{id}", { id = suggested_initiative.issue.id } ) .. ": " .. encode.html(suggested_initiative.name),
bsw@725 254 module = "initiative",
bsw@725 255 view = "show",
bsw@725 256 id = suggested_initiative.id
bsw@725 257 }
bsw@725 258 end
bsw@725 259 end
bsw@725 260 }
bsw@725 261 end
bsw@725 262
bsw@725 263
bsw@725 264 -- invited as initiator
bsw@725 265 if initiator and initiator.accepted == nil and not initiative.issue.half_frozen and not initiative.issue.closed then
bsw@725 266 ui.container{
bsw@725 267 attr = { class = "initiator_invite_info" },
bsw@725 268 content = function()
bsw@725 269 slot.put(_"You are invited to become initiator of this initiative.")
bsw@725 270 slot.put(" ")
bsw@725 271 ui.link{
bsw@725 272 image = { static = "icons/16/tick.png" },
bsw@725 273 text = _"Accept invitation",
bsw@725 274 module = "initiative",
bsw@725 275 action = "accept_invitation",
bsw@725 276 id = initiative.id,
bsw@725 277 routing = {
bsw@725 278 default = {
bsw@725 279 mode = "redirect",
bsw@725 280 module = request.get_module(),
bsw@725 281 view = request.get_view(),
bsw@725 282 id = param.get_id_cgi(),
bsw@725 283 params = param.get_all_cgi()
bsw@725 284 }
bsw@725 285 }
bsw@725 286 }
bsw@725 287 slot.put(" ")
bsw@725 288 ui.link{
bsw@725 289 image = { static = "icons/16/cross.png" },
bsw@725 290 text = _"Refuse invitation",
bsw@725 291 module = "initiative",
bsw@725 292 action = "reject_initiator_invitation",
bsw@725 293 params = {
bsw@725 294 initiative_id = initiative.id,
bsw@725 295 member_id = app.session.member.id
bsw@725 296 },
bsw@725 297 routing = {
bsw@725 298 default = {
bsw@725 299 mode = "redirect",
bsw@725 300 module = request.get_module(),
bsw@725 301 view = request.get_view(),
bsw@725 302 id = param.get_id_cgi(),
bsw@725 303 params = param.get_all_cgi()
bsw@725 304 }
bsw@725 305 }
bsw@725 306 }
bsw@725 307 end
bsw@725 308 }
bsw@725 309 end
bsw@725 310
bsw@725 311 -- draft updated
bsw@725 312 local supporter
bsw@725 313
bsw@725 314 if app.session.member_id then
bsw@725 315 supporter = app.session.member:get_reference_selector("supporters")
bsw@725 316 :add_where{ "initiative_id = ?", initiative.id }
bsw@725 317 :optional_object_mode()
bsw@725 318 :exec()
bsw@725 319 end
bsw@725 320
bsw@725 321 if supporter and not initiative.issue.closed then
bsw@725 322 local old_draft_id = supporter.draft_id
bsw@725 323 local new_draft_id = initiative.current_draft.id
bsw@725 324 if old_draft_id ~= new_draft_id then
bsw@725 325 ui.container{
bsw@725 326 attr = { class = "draft_updated_info" },
bsw@725 327 content = function()
bsw@725 328 slot.put(_"The draft of this initiative has been updated!")
bsw@725 329 slot.put(" ")
bsw@725 330 ui.link{
bsw@725 331 content = _"Show diff",
bsw@725 332 module = "draft",
bsw@725 333 view = "diff",
bsw@725 334 params = {
bsw@725 335 old_draft_id = old_draft_id,
bsw@725 336 new_draft_id = new_draft_id
bsw@725 337 }
bsw@725 338 }
bsw@725 339 if not initiative.revoked then
bsw@725 340 slot.put(" ")
bsw@725 341 ui.link{
bsw@725 342 text = _"Refresh support to current draft",
bsw@725 343 module = "initiative",
bsw@725 344 action = "add_support",
bsw@725 345 id = initiative.id,
bsw@725 346 routing = {
bsw@725 347 default = {
bsw@725 348 mode = "redirect",
bsw@725 349 module = "initiative",
bsw@725 350 view = "show",
bsw@725 351 id = initiative.id
bsw@725 352 }
bsw@725 353 }
bsw@725 354 }
bsw@725 355 end
bsw@725 356 end
bsw@725 357 }
bsw@725 358 end
bsw@725 359 end
bsw@725 360
bsw@725 361 if not show_as_head then
bsw@725 362 local drafts_count = initiative:get_reference_selector("drafts"):count()
bsw@725 363
bsw@725 364 ui.container{ attr = { class = "content" }, content = function()
bsw@725 365
bsw@725 366 if initiator and initiator.accepted and not initiative.issue.half_frozen and not initiative.issue.closed and not initiative.revoked then
bsw@725 367 ui.link{
bsw@725 368 content = function()
bsw@725 369 slot.put(_"Edit draft")
bsw@725 370 end,
bsw@725 371 module = "draft",
bsw@725 372 view = "new",
bsw@725 373 params = { initiative_id = initiative.id }
bsw@725 374 }
bsw@725 375 slot.put(" &middot; ")
bsw@725 376 ui.link{
bsw@725 377 content = function()
bsw@725 378 slot.put(_"Revoke initiative")
bsw@725 379 end,
bsw@725 380 module = "initiative",
bsw@725 381 view = "revoke",
bsw@725 382 id = initiative.id
bsw@725 383 }
bsw@725 384 slot.put(" &middot; ")
bsw@725 385 end
bsw@725 386
bsw@725 387 ui.tag{
bsw@725 388 attr = { class = "draft_version" },
bsw@725 389 content = _("Latest draft created at #{date} #{time}", {
bsw@725 390 date = format.date(initiative.current_draft.created),
bsw@725 391 time = format.time(initiative.current_draft.created)
bsw@725 392 })
bsw@725 393 }
bsw@725 394 if drafts_count > 1 then
bsw@725 395 slot.put(" &middot; ")
bsw@725 396 ui.link{
bsw@725 397 module = "draft", view = "list", params = { initiative_id = initiative.id },
bsw@725 398 text = _("List all revisions (#{count})", { count = drafts_count })
bsw@725 399 }
bsw@725 400 end
bsw@725 401 end }
bsw@725 402
bsw@725 403 execute.view{
bsw@725 404 module = "draft",
bsw@725 405 view = "_show",
bsw@725 406 params = {
bsw@725 407 draft = initiative.current_draft
bsw@725 408 }
bsw@725 409 }
bsw@725 410 end
bsw@725 411 end }
bsw@725 412
bsw@725 413 if not show_as_head then
bsw@725 414 execute.view{
bsw@725 415 module = "suggestion",
bsw@725 416 view = "_list",
bsw@725 417 params = {
bsw@725 418 initiative = initiative,
bsw@725 419 suggestions_selector = initiative:get_reference_selector("suggestions"),
bsw@725 420 tab_id = param.get("tab_id")
bsw@725 421 }
bsw@725 422 }
bsw@725 423
bsw@725 424
bsw@725 425 if config.public_access == "full" or app.session.member_id then
bsw@725 426 if initiative.issue.ranks_available then
bsw@725 427 local members_selector = initiative.issue:get_reference_selector("direct_voters")
bsw@725 428 :left_join("vote", nil, { "vote.initiative_id = ? AND vote.member_id = member.id", initiative.id })
bsw@725 429 :add_field("direct_voter.weight as voter_weight")
bsw@725 430 :add_field("coalesce(vote.grade, 0) as grade")
bsw@725 431 :left_join("initiative", nil, "initiative.id = vote.initiative_id")
bsw@725 432 :left_join("issue", nil, "issue.id = initiative.issue_id")
bsw@725 433
bsw@725 434 ui.anchor{ name = "voter", attr = { class = "heading" }, content = _"Member voter" }
bsw@725 435
bsw@725 436 execute.view{
bsw@725 437 module = "member",
bsw@725 438 view = "_list",
bsw@725 439 params = {
bsw@725 440 initiative = initiative,
bsw@725 441 for_votes = true,
bsw@725 442 members_selector = members_selector,
bsw@725 443 paginator_name = "voter"
bsw@725 444 }
bsw@725 445 }
bsw@725 446 end
bsw@725 447
bsw@725 448 local members_selector = initiative:get_reference_selector("supporting_members_snapshot")
bsw@725 449 :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id")
bsw@725 450 :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 451 :add_field("direct_interest_snapshot.weight")
bsw@725 452 :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event")
bsw@725 453 :add_where("direct_supporter_snapshot.satisfied")
bsw@725 454 :add_field("direct_supporter_snapshot.informed", "is_informed")
bsw@725 455
bsw@725 456 if members_selector:count() > 0 then
bsw@725 457 if issue.fully_frozen then
bsw@725 458 ui.anchor{ name = "supporters", attr = { class = "heading" }, content = _"Supporters (before begin of voting)" }
bsw@725 459 else
bsw@725 460 ui.anchor{ name = "supporters", attr = { class = "heading" }, content = _"Supporters" }
bsw@725 461 end
bsw@725 462
bsw@725 463 execute.view{
bsw@725 464 module = "member",
bsw@725 465 view = "_list",
bsw@725 466 params = {
bsw@725 467 initiative = initiative,
bsw@725 468 members_selector = members_selector,
bsw@725 469 paginator_name = "supporters"
bsw@725 470 }
bsw@725 471 }
bsw@725 472 else
bsw@725 473 if issue.fully_frozen then
bsw@725 474 ui.anchor{ name = "supporters", attr = { class = "heading" }, content = _"No supporters (before begin of voting)" }
bsw@725 475 else
bsw@725 476 ui.anchor{ name = "supporters", attr = { class = "heading" }, content = _"No supporters" }
bsw@725 477 end
bsw@725 478 slot.put("<br />")
bsw@725 479 end
bsw@725 480
bsw@725 481 local members_selector = initiative:get_reference_selector("supporting_members_snapshot")
bsw@725 482 :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id")
bsw@725 483 :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 484 :add_field("direct_interest_snapshot.weight")
bsw@725 485 :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event")
bsw@725 486 :add_where("NOT direct_supporter_snapshot.satisfied")
bsw@725 487 :add_field("direct_supporter_snapshot.informed", "is_informed")
bsw@725 488
bsw@725 489 if members_selector:count() > 0 then
bsw@725 490 if issue.fully_frozen then
bsw@725 491 ui.anchor{ name = "potential_supporters", attr = { class = "heading" }, content = _"Potential supporters (before begin of voting)" }
bsw@725 492 else
bsw@725 493 ui.anchor{ name = "potential_supporters", attr = { class = "heading" }, content = _"Potential supporters" }
bsw@725 494 end
bsw@725 495
bsw@725 496 execute.view{
bsw@725 497 module = "member",
bsw@725 498 view = "_list",
bsw@725 499 params = {
bsw@725 500 initiative = initiative,
bsw@725 501 members_selector = members_selector,
bsw@725 502 paginator_name = "potential_supporters"
bsw@725 503 }
bsw@725 504 }
bsw@725 505 else
bsw@725 506 if issue.fully_frozen then
bsw@725 507 ui.anchor{ name = "potential_supporters", attr = { class = "heading" }, content = _"No potential supporters (before begin of voting)" }
bsw@725 508 else
bsw@725 509 ui.anchor{ name = "potential_supporters", attr = { class = "heading" }, content = _"No potential supporters" }
bsw@725 510 end
bsw@725 511 slot.put("<br />")
bsw@725 512 end
bsw@725 513
bsw@725 514 ui.container{ attr = { class = "heading" }, content = _"Details" }
bsw@725 515 execute.view {
bsw@725 516 module = "initiative",
bsw@725 517 view = "_details",
bsw@725 518 params = {
bsw@725 519 initiative = initiative,
bsw@725 520 members_selector = members_selector
bsw@725 521 }
bsw@725 522 }
bsw@725 523
bsw@725 524 end
bsw@725 525 end

Impressum / About Us