liquid_feedback_frontend

annotate app/main/initiative/_show.lua @ 281:b77e6a17ca77

Check unit voting right where neccessary, hide action buttons for units without voting right
author bsw
date Thu Feb 16 15:01:49 2012 +0100 (2012-02-16)
parents 808269b7f41c
children c587d8762e62
rev   line source
bsw/jbe@19 1 local initiative = param.get("initiative", "table")
bsw/jbe@19 2 local initiator = param.get("initiator", "table")
bsw/jbe@19 3
bsw@272 4 local initiators_members_selector = initiative:get_reference_selector("initiating_members")
bsw@272 5 :add_field("initiator.accepted", "accepted")
bsw@280 6 :add_order_by("member.name")
bsw@280 7 if initiator and initiator.accepted then
bsw@280 8 initiators_members_selector:add_where("initiator.accepted ISNULL OR initiator.accepted")
bsw@280 9 else
bsw@272 10 initiators_members_selector:add_where("initiator.accepted")
bsw@272 11 end
bsw@272 12
bsw@272 13 local initiators = initiators_members_selector:exec()
bsw@272 14
bsw@274 15
bsw@274 16 local initiatives_selector = initiative.issue:get_reference_selector("initiatives")
bsw@274 17 slot.select("initiatives_list", function()
bsw@274 18 execute.view{
bsw@274 19 module = "initiative",
bsw@274 20 view = "_list",
bsw@274 21 params = {
bsw@274 22 issue = initiative.issue,
bsw@274 23 initiatives_selector = initiatives_selector,
bsw@274 24 no_sort = true, highlight_initiative = initiative, limit = 3
bsw@274 25 }
bsw@274 26 }
bsw@274 27 end)
bsw@274 28
bsw@272 29 slot.select("initiative_head", function()
bsw@272 30
bsw@272 31 ui.container{
bsw@272 32 attr = { class = "initiative_name" },
bsw@272 33 content = _("Initiative i#{id}: #{name}", { id = initiative.id, name = initiative.name })
bsw@272 34 }
bsw@276 35 if app.session.member_id or config.public_access == "pseudonym" or config.public_access == "full" then
bsw@276 36 ui.tag{
bsw@276 37 attr = { class = "initiator_names" },
bsw@276 38 content = function()
bsw@276 39 for i, initiator in ipairs(initiators) do
bsw@280 40 slot.put(" ")
bsw@280 41 ui.link{
bsw@280 42 content = function ()
bsw@280 43 execute.view{
bsw@280 44 module = "member_image",
bsw@280 45 view = "_show",
bsw@280 46 params = {
bsw@280 47 member = initiator,
bsw@280 48 image_type = "avatar",
bsw@280 49 show_dummy = true,
bsw@280 50 class = "micro_avatar",
bsw@280 51 popup_text = text
bsw@280 52 }
bsw@280 53 }
bsw@280 54 end,
bsw@280 55 module = "member", view = "show", id = initiator.id
bsw@280 56 }
bsw@280 57 slot.put(" ")
bsw@276 58 ui.link{
bsw@276 59 text = initiator.name,
bsw@276 60 module = "member", view = "show", id = initiator.id
bsw@276 61 }
bsw@280 62 if not initiator.accepted then
bsw@280 63 ui.tag{ attr = { title = _"Not accepted yet" }, content = "?" }
bsw@280 64 end
bsw@272 65 end
bsw@272 66 end
bsw@276 67 }
bsw@276 68 end
bsw@272 69
bsw@272 70 if initiator and initiator.accepted and not initiative.issue.fully_frozen and not initiative.issue.closed and not initiative.revoked then
bsw@272 71 slot.put(" · ")
bsw@272 72 ui.link{
bsw@272 73 attr = { class = "action" },
bsw@272 74 content = function()
bsw@272 75 slot.put(_"Invite initiator")
bsw@272 76 end,
bsw@272 77 module = "initiative",
bsw@272 78 view = "add_initiator",
bsw@272 79 params = { initiative_id = initiative.id }
bsw@272 80 }
bsw@272 81 if #initiators > 1 then
bsw@272 82 slot.put(" · ")
bsw@272 83 ui.link{
bsw@272 84 content = function()
bsw@272 85 slot.put(_"Remove initiator")
bsw@272 86 end,
bsw@272 87 module = "initiative",
bsw@272 88 view = "remove_initiator",
bsw@272 89 params = { initiative_id = initiative.id }
bsw@272 90 }
bsw@272 91 end
bsw@272 92 end
bsw@272 93 if initiator and initiator.accepted == false then
bsw@272 94 slot.put(" · ")
bsw@272 95 ui.link{
bsw@272 96 text = _"Cancel refuse of invitation",
bsw@272 97 module = "initiative",
bsw@272 98 action = "remove_initiator",
bsw@272 99 params = {
bsw@272 100 initiative_id = initiative.id,
bsw@272 101 member_id = app.session.member.id
bsw@272 102 },
bsw@272 103 routing = {
bsw@272 104 ok = {
bsw@272 105 mode = "redirect",
bsw@272 106 module = "initiative",
bsw@272 107 view = "show",
bsw@272 108 id = initiative.id
bsw@272 109 }
bsw@272 110 }
bsw@272 111 }
bsw@272 112 end
bsw@272 113
bsw@272 114
bsw@272 115 end )
bsw@272 116
bsw/jbe@19 117 util.help("initiative.show")
bsw/jbe@19 118
bsw@272 119
bsw/jbe@19 120 if initiative.issue.ranks_available and initiative.admitted then
bsw/jbe@19 121 local class = initiative.rank == 1 and "admitted_info" or "not_admitted_info"
bsw/jbe@19 122 ui.container{
bsw/jbe@19 123 attr = { class = class },
bsw/jbe@19 124 content = function()
bsw/jbe@19 125 local max_value = initiative.issue.voter_count
bsw/jbe@19 126 slot.put(" ")
bsw/jbe@19 127 local positive_votes = initiative.positive_votes
bsw/jbe@19 128 local negative_votes = initiative.negative_votes
jorges@104 129 local sum_votes = initiative.positive_votes + initiative.negative_votes
poelzi@167 130 local function perc(votes, sum)
poelzi@167 131 if sum > 0 and votes > 0 then return " (" .. string.format( "%.f", votes * 100 / sum ) .. "%)" end
poelzi@167 132 return ""
poelzi@167 133 end
poelzi@167 134 slot.put(_"Yes" .. ": <b>" .. tostring(positive_votes) .. perc(positive_votes, sum_votes) .. "</b>")
bsw/jbe@19 135 slot.put(" &middot; ")
bsw/jbe@19 136 slot.put(_"Abstention" .. ": <b>" .. tostring(max_value - initiative.negative_votes - initiative.positive_votes) .. "</b>")
bsw/jbe@19 137 slot.put(" &middot; ")
poelzi@167 138 slot.put(_"No" .. ": <b>" .. tostring(initiative.negative_votes) .. perc(negative_votes, sum_votes) .. "</b>")
bsw/jbe@19 139 slot.put(" &middot; ")
bsw/jbe@19 140 slot.put("<b>")
bsw/jbe@19 141 if initiative.rank == 1 then
bsw/jbe@19 142 slot.put(_"Approved")
bsw/jbe@19 143 elseif initiative.rank then
bsw/jbe@19 144 slot.put(_("Not approved (rank #{rank})", { rank = initiative.rank }))
bsw@24 145 else
bsw@24 146 slot.put(_"Not approved")
bsw/jbe@19 147 end
bsw/jbe@19 148 slot.put("</b>")
bsw/jbe@19 149 end
bsw/jbe@19 150 }
bsw/jbe@19 151 end
bsw/jbe@19 152
bsw/jbe@19 153 if initiative.admitted == false then
bsw/jbe@19 154 local policy = initiative.issue.policy
bsw/jbe@19 155 ui.container{
bsw/jbe@19 156 attr = { class = "not_admitted_info" },
bsw/jbe@19 157 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/jbe@19 158 }
bsw/jbe@19 159 end
bsw/jbe@19 160
bsw@278 161 if initiative.issue.state == "cancelled" then
bsw/jbe@19 162 local policy = initiative.issue.policy
bsw/jbe@19 163 ui.container{
bsw/jbe@19 164 attr = { class = "not_admitted_info" },
bsw/jbe@19 165 content = _("This issue has been cancelled. It failed the quorum of #{quorum}.", { quorum = format.percentage(policy.issue_quorum_num / policy.issue_quorum_den) })
bsw/jbe@19 166 }
bsw/jbe@19 167 end
bsw/jbe@19 168
bsw/jbe@19 169 if initiative.revoked then
bsw/jbe@19 170 ui.container{
bsw/jbe@19 171 attr = { class = "revoked_info" },
bsw/jbe@19 172 content = function()
bsw/jbe@19 173 slot.put(_("This initiative has been revoked at #{revoked}", { revoked = format.timestamp(initiative.revoked) }))
bsw/jbe@19 174 local suggested_initiative = initiative.suggested_initiative
bsw/jbe@19 175 if suggested_initiative then
bsw/jbe@19 176 slot.put("<br /><br />")
bsw/jbe@19 177 slot.put(_("The initiators suggest to support the following initiative:"))
bsw/jbe@19 178 slot.put(" ")
bsw/jbe@19 179 ui.link{
bsw/jbe@19 180 content = _("Issue ##{id}", { id = suggested_initiative.issue.id } ) .. ": " .. encode.html(suggested_initiative.name),
bsw/jbe@19 181 module = "initiative",
bsw/jbe@19 182 view = "show",
bsw/jbe@19 183 id = suggested_initiative.id
bsw/jbe@19 184 }
bsw/jbe@19 185 end
bsw/jbe@19 186 end
bsw/jbe@19 187 }
bsw/jbe@19 188 end
bsw/jbe@19 189
bsw@41 190 if initiator and initiator.accepted == nil and not initiative.issue.half_frozen and not initiative.issue.closed then
bsw/jbe@19 191 ui.container{
bsw/jbe@19 192 attr = { class = "initiator_invite_info" },
bsw/jbe@19 193 content = function()
bsw/jbe@19 194 slot.put(_"You are invited to become initiator of this initiative.")
bsw/jbe@19 195 slot.put(" ")
bsw/jbe@19 196 ui.link{
bsw/jbe@19 197 image = { static = "icons/16/tick.png" },
bsw/jbe@19 198 text = _"Accept invitation",
bsw/jbe@19 199 module = "initiative",
bsw/jbe@19 200 action = "accept_invitation",
bsw/jbe@19 201 id = initiative.id,
bsw/jbe@19 202 routing = {
bsw/jbe@19 203 default = {
bsw/jbe@19 204 mode = "redirect",
bsw/jbe@19 205 module = request.get_module(),
bsw/jbe@19 206 view = request.get_view(),
bsw/jbe@19 207 id = param.get_id_cgi(),
bsw/jbe@19 208 params = param.get_all_cgi()
bsw/jbe@19 209 }
bsw/jbe@19 210 }
bsw/jbe@19 211 }
bsw/jbe@19 212 slot.put(" ")
bsw/jbe@19 213 ui.link{
bsw/jbe@19 214 image = { static = "icons/16/cross.png" },
bsw/jbe@19 215 text = _"Refuse invitation",
bsw/jbe@19 216 module = "initiative",
bsw/jbe@19 217 action = "reject_initiator_invitation",
bsw/jbe@19 218 params = {
bsw/jbe@19 219 initiative_id = initiative.id,
bsw/jbe@19 220 member_id = app.session.member.id
bsw/jbe@19 221 },
bsw/jbe@19 222 routing = {
bsw/jbe@19 223 default = {
bsw/jbe@19 224 mode = "redirect",
bsw/jbe@19 225 module = request.get_module(),
bsw/jbe@19 226 view = request.get_view(),
bsw/jbe@19 227 id = param.get_id_cgi(),
bsw/jbe@19 228 params = param.get_all_cgi()
bsw/jbe@19 229 }
bsw/jbe@19 230 }
bsw/jbe@19 231 }
bsw/jbe@19 232 end
bsw/jbe@19 233 }
bsw/jbe@19 234 slot.put("<br />")
bsw/jbe@19 235 end
bsw/jbe@19 236
bsw/jbe@19 237
bsw@280 238 if app.session.member_id then
bsw@280 239 execute.view{
bsw@280 240 module = "supporter",
bsw@280 241 view = "_show_box",
bsw@280 242 params = {
bsw@280 243 initiative = initiative
bsw@280 244 }
bsw@280 245 }
bsw@280 246 end
bsw@280 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@280 307 ui.field.timestamp{ label = _"Last snapshot:", value = initiative.issue.snapshot }
bsw@280 308 end
bsw@280 309
bsw@280 310

Impressum / About Us