liquid_feedback_frontend

annotate app/main/initiative/_list.lua @ 118:93f4e465b50d

add initiator support in delegation

if a delegation is issued from the initiative view, the initiators
from that one are added to the delegation target list. this makes it easier to delegate to the author without the need to add him to the contact list.
author Daniel Poelzleithner <poelzi@poelzi.org>
date Mon Sep 20 20:32:04 2010 +0200 (2010-09-20)
parents 4f39f0a0d5b5
children bed32bf10a0b
rev   line source
bsw/jbe@19 1 ui.script{ script = "lf_initiative_expanded = {};" }
bsw@11 2
bsw/jbe@0 3 local issue = param.get("issue", "table")
bsw/jbe@0 4
bsw/jbe@19 5 local initiatives_selector = param.get("initiatives_selector", "table")
bsw@51 6
bsw@11 7 initiatives_selector
bsw/jbe@19 8 :join("issue", nil, "issue.id = initiative.issue_id")
bsw@11 9
bsw@51 10 if app.session.member_id then
bsw@51 11 initiatives_selector
bsw@57 12 :left_join("initiator", "_initiator", { "_initiator.initiative_id = initiative.id AND _initiator.member_id = ? AND _initiator.accepted", app.session.member.id} )
bsw@51 13 :left_join("supporter", "_supporter", { "_supporter.initiative_id = initiative.id AND _supporter.member_id = ?", app.session.member.id} )
bsw@51 14
bsw@51 15 :add_field("(_initiator.member_id NOTNULL)", "is_initiator")
bsw@51 16 :add_field({"(_supporter.member_id NOTNULL) AND NOT EXISTS(SELECT 1 FROM opinion WHERE opinion.initiative_id = initiative.id AND opinion.member_id = ? AND ((opinion.degree = 2 AND NOT fulfilled) OR (opinion.degree = -2 AND fulfilled)))", app.session.member.id }, "is_supporter")
bsw@51 17 :add_field({"EXISTS(SELECT 1 FROM opinion WHERE opinion.initiative_id = initiative.id AND opinion.member_id = ? AND ((opinion.degree = 2 AND NOT fulfilled) OR (opinion.degree = -2 AND fulfilled)))", app.session.member.id }, "is_potential_supporter")
bsw@51 18 end
bsw@11 19
bsw/jbe@19 20 local initiatives_count = initiatives_selector:count()
bsw@11 21
bsw/jbe@19 22 local limit = param.get("limit", atom.number)
bsw/jbe@19 23 local no_sort = param.get("no_sort", atom.boolean)
bsw/jbe@19 24
bsw/jbe@19 25 local show_for_issue = param.get("show_for_issue", atom.boolean)
bsw/jbe@19 26
bsw/jbe@19 27 local show_for_initiative
bsw/jbe@19 28
bsw/jbe@19 29 local show_for_initiative_id = param.get("for_initiative_id", atom.number)
bsw/jbe@19 30
bsw/jbe@19 31 if show_for_initiative_id then
bsw/jbe@19 32 show_for_initiative = Initiative:by_id(show_for_initiative_id)
bsw/jbe@19 33
bsw/jbe@19 34 elseif not show_for_initiative_id and show_for_issue and issue and issue.ranks_available then
bsw/jbe@19 35 winning_initiative = Initiative:new_selector()
bsw/jbe@19 36 :add_where{ "issue_id = ?", issue.id }
bsw/jbe@19 37 :add_where("rank = 1")
bsw@24 38 :optional_object_mode()
bsw/jbe@19 39 :exec()
bsw/jbe@19 40 if winning_initiative then
bsw/jbe@19 41 show_for_initiative = winning_initiative
bsw/jbe@19 42 ui.container{
bsw/jbe@19 43 attr = { class = "admitted_info" },
bsw/jbe@19 44 content = _"This issue has been finished with the following winning initiative:"
bsw/jbe@19 45 }
bsw/jbe@19 46 else
bsw/jbe@19 47 ui.container{
bsw/jbe@19 48 attr = { class = "not_admitted_info" },
bsw/jbe@19 49 content = _"This issue has been finished without any winning initiative."
bsw/jbe@19 50 }
bsw/jbe@19 51 end
bsw/jbe@19 52 end
bsw/jbe@19 53
bsw/jbe@19 54
bsw/jbe@19 55 if show_for_initiative then
bsw/jbe@19 56 ui.script{ script = "lf_initiative_expanded['initiative_content_" .. tostring(show_for_initiative.id) .. "'] = true;" }
bsw/jbe@19 57 initiatives_selector:add_where{ "initiative.id != ?", show_for_initiative.id }
bsw/jbe@19 58
bsw/jbe@19 59 execute.view{
bsw/jbe@19 60 module = "initiative",
bsw/jbe@19 61 view = "_list_element",
bsw/jbe@19 62 params = {
bsw/jbe@19 63 initiative = show_for_initiative,
bsw/jbe@19 64 expanded = true,
bsw/jbe@19 65 expandable = true
bsw/jbe@19 66 }
bsw/jbe@19 67 }
bsw/jbe@19 68 if show_for_issue then
bsw/jbe@19 69 slot.put("<br />")
bsw/jbe@19 70 ui.container{
bsw/jbe@19 71 attr = { style = "font-weight: bold;" },
bsw/jbe@0 72 content = function()
bsw/jbe@19 73 slot.put(_"Alternative initiatives")
bsw/jbe@0 74 end
bsw/jbe@0 75 }
bsw/jbe@0 76 end
bsw/jbe@19 77 elseif show_for_issue then
bsw/jbe@19 78 ui.container{
bsw/jbe@19 79 attr = { style = "font-weight: bold;" },
bsw/jbe@19 80 content = function()
bsw/jbe@19 81 slot.put(_"Alternative initiatives")
bsw/jbe@19 82 end
bsw@11 83 }
bsw@11 84 end
bsw/jbe@19 85
bsw/jbe@19 86 if not show_for_initiative or initiatives_count > 1 then
bsw/jbe@19 87
bsw/jbe@19 88
bsw/jbe@19 89 local more_initiatives_count
bsw/jbe@19 90 if limit then
bsw/jbe@19 91 limit = limit - (show_for_initiative and 1 or 0)
bsw/jbe@19 92 if initiatives_count > limit then
bsw/jbe@19 93 more_initiatives_count = initiatives_count - limit
bsw/jbe@19 94 end
bsw/jbe@19 95 initiatives_selector:limit(limit)
bsw/jbe@19 96 end
bsw/jbe@19 97
bsw/jbe@19 98 local expandable = param.get("expandable", atom.boolean)
bsw/jbe@19 99
bsw/jbe@19 100 local issue = param.get("issue", "table")
bsw/jbe@19 101
bsw/jbe@19 102 local name = "initiative_list"
bsw/jbe@19 103 if issue then
bsw/jbe@19 104 name = "issue_" .. tostring(issue.id) .. "_initiative_list"
bsw/jbe@19 105 end
bsw/jbe@19 106
bsw/jbe@19 107 ui.add_partial_param_names{ name }
bsw/jbe@19 108
bsw/jbe@19 109 local order_filter = {
bsw/jbe@19 110 name = name,
bsw/jbe@19 111 label = _"Order by"
bsw/jbe@19 112 }
bsw/jbe@19 113
bsw/jbe@19 114 if issue and issue.ranks_available then
bsw/jbe@19 115 order_filter[#order_filter+1] = {
bsw/jbe@19 116 name = "rank",
bsw/jbe@19 117 label = _"Rank",
bsw/jbe@19 118 selector_modifier = function(selector) selector:add_order_by("initiative.rank, initiative.admitted DESC, vote_ratio(initiative.positive_votes, initiative.negative_votes) DESC, initiative.id") end
bsw/jbe@19 119 }
bsw/jbe@19 120 end
bsw/jbe@19 121
bsw/jbe@19 122 order_filter[#order_filter+1] = {
bsw/jbe@19 123 name = "potential_support",
bsw/jbe@19 124 label = _"Potential support",
bsw/jbe@19 125 selector_modifier = function(selector) selector:add_order_by("initiative.supporter_count::float / issue.population::float DESC, initiative.id") end
bsw/jbe@19 126 }
bsw/jbe@19 127
bsw/jbe@19 128 order_filter[#order_filter+1] = {
bsw/jbe@19 129 name = "support",
bsw/jbe@19 130 label = _"Support",
bsw/jbe@19 131 selector_modifier = function(selector) selector:add_order_by("initiative.satisfied_supporter_count::float / issue.population::float DESC, initiative.id") end
bsw/jbe@19 132 }
bsw/jbe@19 133
bsw/jbe@19 134 order_filter[#order_filter+1] = {
bsw/jbe@19 135 name = "newest",
bsw/jbe@19 136 label = _"Newest",
bsw/jbe@19 137 selector_modifier = function(selector) selector:add_order_by("initiative.created DESC, initiative.id") end
bsw/jbe@19 138 }
bsw/jbe@19 139
bsw/jbe@19 140 order_filter[#order_filter+1] = {
bsw/jbe@19 141 name = "oldest",
bsw/jbe@19 142 label = _"Oldest",
bsw/jbe@19 143 selector_modifier = function(selector) selector:add_order_by("initiative.created, initiative.id") end
bsw/jbe@19 144 }
bsw/jbe@19 145
bsw/jbe@19 146 ui_filters = ui.filters
bsw/jbe@19 147
bsw/jbe@19 148 if no_sort then
bsw/jbe@19 149 ui_filters = function(args) args.content() end
bsw/jbe@19 150 if issue.ranks_available then
bsw/jbe@19 151 initiatives_selector:add_order_by("initiative.rank, initiative.admitted DESC, vote_ratio(initiative.positive_votes, initiative.negative_votes) DESC, initiative.id")
bsw/jbe@19 152 else
bsw/jbe@19 153 initiatives_selector:add_order_by("initiative.supporter_count::float / issue.population::float DESC, initiative.id")
bsw/jbe@19 154 end
bsw/jbe@19 155 end
bsw/jbe@19 156
bsw/jbe@19 157 ui_filters{
bsw/jbe@19 158 label = _"Change order",
bsw/jbe@19 159 order_filter,
bsw/jbe@19 160 selector = initiatives_selector,
bsw/jbe@19 161 content = function()
bsw/jbe@19 162 ui.paginate{
bsw/jbe@19 163 name = issue and "issue_" .. tostring(issue.id) .. "_page" or nil,
bsw/jbe@19 164 selector = initiatives_selector,
bsw/jbe@19 165 per_page = param.get("per_page", atom.number),
bsw/jbe@19 166 content = function()
bsw/jbe@19 167 local initiatives = initiatives_selector:exec()
bsw/jbe@19 168 for i, initiative in ipairs(initiatives) do
bsw/jbe@19 169 local expanded = config.user_tab_mode == "accordeon_all_expanded" and expandable or
bsw/jbe@19 170 show_for_initiative and initiative.id == show_for_initiative.id
bsw/jbe@19 171 if expanded then
bsw/jbe@19 172 ui.script{ script = "lf_initiative_expanded['initiative_content_" .. tostring(initiative.id) .. "'] = true;" }
bsw/jbe@19 173 end
bsw/jbe@19 174 execute.view{
bsw/jbe@19 175 module = "initiative",
bsw/jbe@19 176 view = "_list_element",
bsw/jbe@19 177 params = {
bsw/jbe@19 178 initiative = initiative,
bsw/jbe@19 179 expanded = expanded,
bsw/jbe@19 180 expandable = expandable
bsw/jbe@19 181 }
bsw/jbe@19 182 }
bsw/jbe@19 183 end
bsw/jbe@19 184 end
bsw/jbe@19 185 }
bsw/jbe@19 186 end
bsw/jbe@19 187 }
bsw/jbe@19 188
bsw/jbe@19 189 if more_initiatives_count then
bsw/jbe@19 190 ui.link{
bsw/jbe@19 191 attr = { style = "font-size: 75%; font-style: italic;" },
bsw/jbe@19 192 content = _("and #{count} more initiatives", { count = more_initiatives_count }),
bsw/jbe@19 193 module = "issue",
bsw/jbe@19 194 view = "show",
bsw/jbe@19 195 id = issue.id,
bsw/jbe@19 196 }
bsw/jbe@19 197 end
bsw/jbe@19 198
bsw/jbe@19 199 end
bsw/jbe@19 200
bsw/jbe@19 201 if show_for_issue then
bsw/jbe@19 202 slot.put("<br />")
bsw/jbe@19 203
bsw/jbe@19 204 if issue and initiatives_count == 1 then
bsw/jbe@19 205 ui.container{
bsw/jbe@19 206 content = function()
bsw/jbe@19 207 if issue.fully_frozen or issue.closed then
bsw/jbe@19 208 slot.put(_"There were no more alternative initiatives.")
bsw/jbe@19 209 else
bsw/jbe@19 210 slot.put(_"There are no more alternative initiatives currently.")
bsw/jbe@19 211 end
bsw/jbe@19 212 end
bsw/jbe@19 213 }
bsw/jbe@19 214 end
bsw/jbe@19 215
bsw@51 216 if app.session.member_id and not (issue.fully_frozen or issue.closed) then
bsw/jbe@19 217 slot.put(" ")
bsw/jbe@19 218 ui.link{
bsw/jbe@19 219 content = function()
bsw/jbe@19 220 ui.image{ static = "icons/16/script_add.png" }
bsw/jbe@19 221 slot.put(" ")
bsw/jbe@19 222 slot.put(_"Create alternative initiative")
bsw/jbe@19 223 end,
bsw/jbe@19 224 module = "initiative",
bsw/jbe@19 225 view = "new",
bsw/jbe@19 226 params = { issue_id = issue.id }
bsw/jbe@19 227 }
bsw/jbe@19 228 end
bsw/jbe@19 229 end

Impressum / About Us