liquid_feedback_frontend

diff 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 cdd0bcbbef8b
children 701a5cf6b067
line diff
     1.1 --- a/app/main/initiative/show.lua	Thu Jun 28 01:02:03 2012 +0200
     1.2 +++ b/app/main/initiative/show.lua	Thu Jun 28 13:52:42 2012 +0200
     1.3 @@ -1,442 +1,7 @@
     1.4  local initiative = Initiative:by_id(param.get_id())
     1.5 -initiative:load_everything_for_member_id(app.session.member_id)
     1.6 -
     1.7 -local issue = initiative.issue
     1.8 -
     1.9 -if app.session.member_id then
    1.10 -  issue:load_everything_for_member_id(app.session.member_id)
    1.11 -end
    1.12 -
    1.13 -app.html_title.title = initiative.name
    1.14 -app.html_title.subtitle = _("Initiative ##{id}", { id = initiative.id })
    1.15 -
    1.16 -slot.select("head", function()
    1.17 -  execute.view{
    1.18 -    module = "issue", view = "_head",
    1.19 -    params = { issue = issue, initiative = initiative }
    1.20 -  }
    1.21 -end)
    1.22 -  
    1.23 -local initiators_members_selector = initiative:get_reference_selector("initiating_members")
    1.24 -  :add_field("initiator.accepted", "accepted")
    1.25 -  :add_order_by("member.name")
    1.26 -if initiator and initiator.accepted then
    1.27 -  initiators_members_selector:add_where("initiator.accepted ISNULL OR initiator.accepted")
    1.28 -else
    1.29 -  initiators_members_selector:add_where("initiator.accepted")
    1.30 -end
    1.31 -
    1.32 -local initiators = initiators_members_selector:exec()
    1.33 -
    1.34 -
    1.35 -local initiatives_selector = initiative.issue:get_reference_selector("initiatives")
    1.36 -slot.select("head", function()
    1.37 -  execute.view{
    1.38 -    module = "issue",
    1.39 -    view = "_show",
    1.40 -    params = {
    1.41 -      issue = initiative.issue,
    1.42 -      initiative_limit = 3,
    1.43 -      for_initiative = initiative
    1.44 -    }
    1.45 -  }
    1.46 -end)
    1.47 -
    1.48 -util.help("initiative.show")
    1.49 -
    1.50 -ui.container{ attr = { class = "initiative_head" }, content = function()
    1.51 -
    1.52 -  ui.container{
    1.53 -    attr = { class = "title" },
    1.54 -    content = _("Initiative i#{id}: #{name}", { id = initiative.id, name = initiative.name })
    1.55 -  }
    1.56 -
    1.57 -  ui.container{ attr = { class = "content" }, content = function()
    1.58 -    if app.session.member_id or config.public_access == "pseudonym" or config.public_access == "full" then
    1.59 -      ui.tag{
    1.60 -        attr = { class = "initiator_names" },
    1.61 -        content = function()
    1.62 -          for i, initiator in ipairs(initiators) do
    1.63 -            slot.put(" ")
    1.64 -            if app.session.member_id or config.public_access == "full" then
    1.65 -              ui.link{
    1.66 -                content = function ()
    1.67 -                  execute.view{
    1.68 -                    module = "member_image",
    1.69 -                    view = "_show",
    1.70 -                    params = {
    1.71 -                      member = initiator,
    1.72 -                      image_type = "avatar",
    1.73 -                      show_dummy = true,
    1.74 -                      class = "micro_avatar",
    1.75 -                      popup_text = text
    1.76 -                    }
    1.77 -                  }
    1.78 -                end,
    1.79 -                module = "member", view = "show", id = initiator.id
    1.80 -              }
    1.81 -              slot.put(" ")
    1.82 -            end
    1.83 -            ui.link{
    1.84 -              text = initiator.name,
    1.85 -              module = "member", view = "show", id = initiator.id
    1.86 -            }
    1.87 -            if not initiator.accepted then
    1.88 -              ui.tag{ attr = { title = _"Not accepted yet" }, content = "?" }
    1.89 -            end
    1.90 -          end
    1.91 -        end
    1.92 -      }
    1.93 -    end
    1.94 -
    1.95 -    if initiator and initiator.accepted and not initiative.issue.fully_frozen and not initiative.issue.closed and not initiative.revoked then
    1.96 -      slot.put(" · ")
    1.97 -      ui.link{
    1.98 -        attr = { class = "action" },
    1.99 -        content = function()
   1.100 -          slot.put(_"Invite initiator")
   1.101 -        end,
   1.102 -        module = "initiative",
   1.103 -        view = "add_initiator",
   1.104 -        params = { initiative_id = initiative.id }
   1.105 -      }
   1.106 -      if #initiators > 1 then
   1.107 -        slot.put(" · ")
   1.108 -        ui.link{
   1.109 -          content = function()
   1.110 -            slot.put(_"Remove initiator")
   1.111 -          end,
   1.112 -          module = "initiative",
   1.113 -          view = "remove_initiator",
   1.114 -          params = { initiative_id = initiative.id }
   1.115 -        }
   1.116 -      end
   1.117 -    end
   1.118 -    if initiator and initiator.accepted == false then
   1.119 -        slot.put(" · ")
   1.120 -        ui.link{
   1.121 -          text   = _"Cancel refuse of invitation",
   1.122 -          module = "initiative",
   1.123 -          action = "remove_initiator",
   1.124 -          params = {
   1.125 -            initiative_id = initiative.id,
   1.126 -            member_id = app.session.member.id
   1.127 -          },
   1.128 -          routing = {
   1.129 -            ok = {
   1.130 -              mode = "redirect",
   1.131 -              module = "initiative",
   1.132 -              view = "show",
   1.133 -              id = initiative.id
   1.134 -            }
   1.135 -          }
   1.136 -        }
   1.137 -    end
   1.138 -  end }
   1.139 -  ui.container{ attr = { class = "content" }, content = function()
   1.140 -    if app.session.member_id then
   1.141 -      execute.view{
   1.142 -        module = "supporter",
   1.143 -        view = "_show_box",
   1.144 -        params = {
   1.145 -          initiative = initiative
   1.146 -        }
   1.147 -      }
   1.148 -    end
   1.149 -
   1.150 -  end }
   1.151 -
   1.152 -  
   1.153 -  -- voting results
   1.154 -  if initiative.issue.ranks_available and initiative.admitted then
   1.155 -    local class = initiative.winner and "admitted_info" or "not_admitted_info"
   1.156 -    ui.container{
   1.157 -      attr = { class = class },
   1.158 -      content = function()
   1.159 -        local max_value = initiative.issue.voter_count
   1.160 -        slot.put(" ")
   1.161 -        local positive_votes = initiative.positive_votes
   1.162 -        local negative_votes = initiative.negative_votes
   1.163 -        local sum_votes = initiative.positive_votes + initiative.negative_votes
   1.164 -        local function perc(votes, sum)
   1.165 -          if sum > 0 and votes > 0 then return " (" .. string.format( "%.f", votes * 100 / sum ) .. "%)" end
   1.166 -          return ""
   1.167 -        end
   1.168 -        slot.put(_"Yes" .. ": <b>" .. tostring(positive_votes) .. perc(positive_votes, sum_votes) .. "</b>")
   1.169 -        slot.put(" &middot; ")
   1.170 -        slot.put(_"Abstention" .. ": <b>" .. tostring(max_value - initiative.negative_votes - initiative.positive_votes)  .. "</b>")
   1.171 -        slot.put(" &middot; ")
   1.172 -        slot.put(_"No" .. ": <b>" .. tostring(initiative.negative_votes) .. perc(negative_votes, sum_votes) .. "</b>")
   1.173 -        slot.put(" &middot; ")
   1.174 -        slot.put("<b>")
   1.175 -        if initiative.winner then
   1.176 -          slot.put(_"Approved")
   1.177 -        elseif initiative.rank then
   1.178 -          slot.put(_("Not approved (rank #{rank})", { rank = initiative.rank }))
   1.179 -        else
   1.180 -          slot.put(_"Not approved")
   1.181 -        end
   1.182 -        slot.put("</b>")
   1.183 -      end
   1.184 -    }
   1.185 -  end
   1.186 -
   1.187 -  ui.container{ attr = { class = "content" }, content = function()
   1.188 -    execute.view{
   1.189 -      module = "initiative",
   1.190 -      view = "_battles",
   1.191 -      params = { initiative = initiative }
   1.192 -    }
   1.193 -  end }
   1.194 -    
   1.195 -  -- initiative not admitted info
   1.196 -  if initiative.admitted == false then
   1.197 -    local policy = initiative.issue.policy
   1.198 -    ui.container{
   1.199 -      attr = { class = "not_admitted_info" },
   1.200 -      content = _("This initiative has not been admitted! It failed the quorum of #{quorum}.", { quorum = format.percentage(policy.initiative_quorum_num / policy.initiative_quorum_den) })
   1.201 -    }
   1.202 -  end
   1.203 -
   1.204 -  -- initiative revoked info
   1.205 -  if initiative.revoked then
   1.206 -    ui.container{
   1.207 -      attr = { class = "revoked_info" },
   1.208 -      content = function()
   1.209 -        slot.put(_("This initiative has been revoked at #{revoked}", { revoked = format.timestamp(initiative.revoked) }))
   1.210 -        local suggested_initiative = initiative.suggested_initiative
   1.211 -        if suggested_initiative then
   1.212 -          slot.put("<br /><br />")
   1.213 -          slot.put(_("The initiators suggest to support the following initiative:"))
   1.214 -          slot.put(" ")
   1.215 -          ui.link{
   1.216 -            content = _("Issue ##{id}", { id = suggested_initiative.issue.id } ) .. ": " .. encode.html(suggested_initiative.name),
   1.217 -            module = "initiative",
   1.218 -            view = "show",
   1.219 -            id = suggested_initiative.id
   1.220 -          }
   1.221 -        end
   1.222 -      end
   1.223 -    }
   1.224 -  end
   1.225 -
   1.226 -
   1.227 -  -- invited as initiator
   1.228 -  if initiator and initiator.accepted == nil and not initiative.issue.half_frozen and not initiative.issue.closed then
   1.229 -    ui.container{
   1.230 -      attr = { class = "initiator_invite_info" },
   1.231 -      content = function()
   1.232 -        slot.put(_"You are invited to become initiator of this initiative.")
   1.233 -        slot.put(" ")
   1.234 -        ui.link{
   1.235 -          image  = { static = "icons/16/tick.png" },
   1.236 -          text   = _"Accept invitation",
   1.237 -          module = "initiative",
   1.238 -          action = "accept_invitation",
   1.239 -          id     = initiative.id,
   1.240 -          routing = {
   1.241 -            default = {
   1.242 -              mode = "redirect",
   1.243 -              module = request.get_module(),
   1.244 -              view = request.get_view(),
   1.245 -              id = param.get_id_cgi(),
   1.246 -              params = param.get_all_cgi()
   1.247 -            }
   1.248 -          }
   1.249 -        }
   1.250 -        slot.put(" ")
   1.251 -        ui.link{
   1.252 -          image  = { static = "icons/16/cross.png" },
   1.253 -          text   = _"Refuse invitation",
   1.254 -          module = "initiative",
   1.255 -          action = "reject_initiator_invitation",
   1.256 -          params = {
   1.257 -            initiative_id = initiative.id,
   1.258 -            member_id = app.session.member.id
   1.259 -          },
   1.260 -          routing = {
   1.261 -            default = {
   1.262 -              mode = "redirect",
   1.263 -              module = request.get_module(),
   1.264 -              view = request.get_view(),
   1.265 -              id = param.get_id_cgi(),
   1.266 -              params = param.get_all_cgi()
   1.267 -            }
   1.268 -          }
   1.269 -        }
   1.270 -      end
   1.271 -    }
   1.272 -  end
   1.273 -
   1.274 -  -- draft updated
   1.275 -  local supporter
   1.276 -
   1.277 -  if app.session.member_id then
   1.278 -    supporter = app.session.member:get_reference_selector("supporters")
   1.279 -      :add_where{ "initiative_id = ?", initiative.id }
   1.280 -      :optional_object_mode()
   1.281 -      :exec()
   1.282 -  end
   1.283 -
   1.284 -  if supporter and not initiative.issue.closed then
   1.285 -    local old_draft_id = supporter.draft_id
   1.286 -    local new_draft_id = initiative.current_draft.id
   1.287 -    if old_draft_id ~= new_draft_id then
   1.288 -      ui.container{
   1.289 -        attr = { class = "draft_updated_info" },
   1.290 -        content = function()
   1.291 -          slot.put(_"The draft of this initiative has been updated!")
   1.292 -          slot.put(" ")
   1.293 -          ui.link{
   1.294 -            content = _"Show diff",
   1.295 -            module = "draft",
   1.296 -            view = "diff",
   1.297 -            params = {
   1.298 -              old_draft_id = old_draft_id,
   1.299 -              new_draft_id = new_draft_id
   1.300 -            }
   1.301 -          }
   1.302 -          if not initiative.revoked then
   1.303 -            slot.put(" ")
   1.304 -            ui.link{
   1.305 -              text   = _"Refresh support to current draft",
   1.306 -              module = "initiative",
   1.307 -              action = "add_support",
   1.308 -              id     = initiative.id,
   1.309 -              routing = {
   1.310 -                default = {
   1.311 -                  mode = "redirect",
   1.312 -                  module = "initiative",
   1.313 -                  view = "show",
   1.314 -                  id = initiative.id
   1.315 -                }
   1.316 -              }
   1.317 -            }
   1.318 -          end
   1.319 -        end
   1.320 -      }
   1.321 -    end
   1.322 -  end
   1.323 -
   1.324 -
   1.325 -  execute.view{
   1.326 -    module = "draft",
   1.327 -    view = "_show",
   1.328 -    params = {
   1.329 -      draft = initiative.current_draft
   1.330 -    }
   1.331 -  }
   1.332 -  
   1.333 -end }
   1.334  
   1.335  execute.view{
   1.336 -  module = "suggestion",
   1.337 -  view = "_list",
   1.338 -  params = {
   1.339 -    initiative = initiative,
   1.340 -    suggestions_selector = initiative:get_reference_selector("suggestions"),
   1.341 -    tab_id = param.get("tab_id")
   1.342 +  module = "initiative", view = "_show", params = {
   1.343 +    initiative = initiative
   1.344    }
   1.345  }
   1.346 -
   1.347 -
   1.348 -if config.public_access == "full" or app.session.member_id then
   1.349 -  if initiative.issue.ranks_available then
   1.350 -    local members_selector = initiative.issue:get_reference_selector("direct_voters")
   1.351 -          :left_join("vote", nil, { "vote.initiative_id = ? AND vote.member_id = member.id", initiative.id })
   1.352 -          :add_field("direct_voter.weight as voter_weight")
   1.353 -          :add_field("coalesce(vote.grade, 0) as grade")
   1.354 -          :left_join("initiative", nil, "initiative.id = vote.initiative_id")
   1.355 -          :left_join("issue", nil, "issue.id = initiative.issue_id")
   1.356 -    
   1.357 -    ui.anchor{ name = "voter", attr = { class = "heading" }, content = _"Member voter" }
   1.358 -    
   1.359 -    execute.view{
   1.360 -      module = "member",
   1.361 -      view = "_list",
   1.362 -      params = {
   1.363 -        initiative = initiative,
   1.364 -        for_votes = true,
   1.365 -        members_selector = members_selector,
   1.366 -        paginator_name = "voter"
   1.367 -      }
   1.368 -    }
   1.369 -  end
   1.370 -  
   1.371 -  local members_selector = initiative:get_reference_selector("supporting_members_snapshot")
   1.372 -            :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id")
   1.373 -            :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")
   1.374 -            :add_field("direct_interest_snapshot.weight")
   1.375 -            :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event")
   1.376 -            :add_where("direct_supporter_snapshot.satisfied")
   1.377 -            :add_field("direct_supporter_snapshot.informed", "is_informed")
   1.378 -
   1.379 -  if members_selector:count() > 0 then
   1.380 -    if issue.fully_frozen then
   1.381 -      ui.anchor{ name = "supporters", attr = { class = "heading" }, content = _"Supporters (before begin of voting)" }
   1.382 -    else
   1.383 -      ui.anchor{ name = "supporters", attr = { class = "heading" }, content = _"Supporters" }
   1.384 -    end      
   1.385 -    
   1.386 -    execute.view{
   1.387 -      module = "member",
   1.388 -      view = "_list",
   1.389 -      params = {
   1.390 -        initiative = initiative,
   1.391 -        members_selector = members_selector,
   1.392 -        paginator_name = "supporters"
   1.393 -      }
   1.394 -  }
   1.395 -  else
   1.396 -    if issue.fully_frozen then
   1.397 -      ui.anchor{ name = "supporters", attr = { class = "heading" }, content = _"No supporters (before begin of voting)" }
   1.398 -    else
   1.399 -      ui.anchor{ name = "supporters", attr = { class = "heading" }, content = _"No supporters" }
   1.400 -    end
   1.401 -    slot.put("<br />")
   1.402 -  end
   1.403 -
   1.404 -  local members_selector = initiative:get_reference_selector("supporting_members_snapshot")
   1.405 -            :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id")
   1.406 -            :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")
   1.407 -            :add_field("direct_interest_snapshot.weight")
   1.408 -            :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event")
   1.409 -            :add_where("NOT direct_supporter_snapshot.satisfied")
   1.410 -            :add_field("direct_supporter_snapshot.informed", "is_informed")
   1.411 -
   1.412 -  if members_selector:count() > 0 then
   1.413 -    if issue.fully_frozen then
   1.414 -      ui.anchor{ name = "potential_supporters", attr = { class = "heading" }, content = _"Potential supporters (before begin of voting)" }
   1.415 -    else
   1.416 -      ui.anchor{ name = "potential_supporters", attr = { class = "heading" }, content = _"Potential supporters" }
   1.417 -    end
   1.418 -              
   1.419 -    execute.view{
   1.420 -      module = "member",
   1.421 -      view = "_list",
   1.422 -      params = {
   1.423 -        initiative = initiative,
   1.424 -        members_selector = members_selector,
   1.425 -        paginator_name = "potential_supporters"
   1.426 -      }
   1.427 -    }
   1.428 -  else
   1.429 -    if issue.fully_frozen then
   1.430 -      ui.anchor{ name = "potential_supporters", attr = { class = "heading" }, content = _"No potential supporters (before begin of voting)" }
   1.431 -    else
   1.432 -      ui.anchor{ name = "potential_supporters", attr = { class = "heading" }, content = _"No potential supporters" }
   1.433 -    end
   1.434 -    slot.put("<br />")
   1.435 -  end
   1.436 -  
   1.437 -  ui.container{ attr = { class = "heading" }, content = _"Details" }
   1.438 -  execute.view {
   1.439 -    module = "initiative",
   1.440 -    view = "_details",
   1.441 -    params = {
   1.442 -      initiative = initiative,
   1.443 -      members_selector = members_selector
   1.444 -    }
   1.445 -  }
   1.446 -
   1.447 -end

Impressum / About Us