liquid_feedback_frontend

view app/main/initiative/_list.lua @ 274:aec9df5b4cd3

More optical enhancements and repositioning of elements
author bsw
date Sun Feb 12 12:20:19 2012 +0100 (2012-02-12)
parents 65a1f7a01e7b
children fecd4c13054a
line source
1 ui.script{ script = "lf_initiative_expanded = {};" }
3 local issue = param.get("issue", "table")
5 local initiatives_selector = param.get("initiatives_selector", "table")
7 local highlight_initiative = param.get("highlight_initiative", "table")
9 initiatives_selector
10 :join("issue", nil, "issue.id = initiative.issue_id")
12 if app.session.member_id then
13 initiatives_selector
14 :left_join("initiator", "_initiator", { "_initiator.initiative_id = initiative.id AND _initiator.member_id = ? AND _initiator.accepted", app.session.member.id} )
15 :left_join("supporter", "_supporter", { "_supporter.initiative_id = initiative.id AND _supporter.member_id = ?", app.session.member.id} )
17 :add_field("(_initiator.member_id NOTNULL)", "is_initiator")
18 :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")
19 :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")
20 end
22 local initiatives_count = initiatives_selector:count()
24 local limit = param.get("limit", atom.number)
25 local no_sort = param.get("no_sort", atom.boolean)
27 local show_for_issue = param.get("show_for_issue", atom.boolean)
29 local show_for_initiative
31 local show_for_initiative_id = param.get("for_initiative_id", atom.number)
33 if show_for_initiative_id then
34 show_for_initiative = Initiative:by_id(show_for_initiative_id)
36 elseif not show_for_initiative_id and show_for_issue and issue and issue.ranks_available then
37 winning_initiative = Initiative:new_selector()
38 :add_where{ "issue_id = ?", issue.id }
39 :add_where("rank = 1")
40 :optional_object_mode()
41 :exec()
42 if winning_initiative then
43 show_for_initiative = winning_initiative
44 ui.container{
45 attr = { class = "admitted_info" },
46 content = _"This issue has been finished with the following winning initiative:"
47 }
48 else
49 ui.container{
50 attr = { class = "not_admitted_info" },
51 content = _"This issue has been finished without any winning initiative."
52 }
53 end
54 end
57 if show_for_initiative then
58 ui.script{ script = "lf_initiative_expanded['initiative_content_" .. tostring(show_for_initiative.id) .. "'] = true;" }
59 initiatives_selector:add_where{ "initiative.id != ?", show_for_initiative.id }
61 execute.view{
62 module = "initiative",
63 view = "_list_element",
64 params = {
65 initiative = show_for_initiative,
66 expanded = true,
67 expandable = true
68 }
69 }
70 if show_for_issue then
71 slot.put("<br />")
72 ui.container{
73 attr = { style = "font-weight: bold;" },
74 content = function()
75 slot.put(_"Alternative initiatives")
76 end
77 }
78 end
79 elseif show_for_issue then
80 ui.container{
81 attr = { style = "font-weight: bold;" },
82 content = function()
83 slot.put(_"Alternative initiatives")
84 end
85 }
86 end
88 if not show_for_initiative or initiatives_count > 1 then
91 local more_initiatives_count
92 if limit then
93 limit = limit - (show_for_initiative and 1 or 0)
94 if initiatives_count > limit then
95 more_initiatives_count = initiatives_count - limit
96 end
97 initiatives_selector:limit(limit)
98 end
100 local expandable = param.get("expandable", atom.boolean)
102 local issue = param.get("issue", "table")
104 local name = "initiative_list"
105 if issue then
106 name = "issue_" .. tostring(issue.id) .. "_initiative_list"
107 end
109 ui.add_partial_param_names{ name }
111 local order_filter = {
112 name = name,
113 label = _"Order by"
114 }
116 if issue and issue.ranks_available then
117 order_filter[#order_filter+1] = {
118 name = "rank",
119 label = _"Rank",
120 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
121 }
122 end
124 order_filter[#order_filter+1] = {
125 name = "potential_support",
126 label = _"Potential support",
127 selector_modifier = function(selector) selector:add_order_by("CASE WHEN issue.population = 0 THEN 0 ELSE initiative.supporter_count::float / issue.population::float END DESC, initiative.id") end
128 }
130 order_filter[#order_filter+1] = {
131 name = "support",
132 label = _"Support",
133 selector_modifier = function(selector) selector:add_order_by("initiative.satisfied_supporter_count::float / issue.population::float DESC, initiative.id") end
134 }
136 order_filter[#order_filter+1] = {
137 name = "newest",
138 label = _"Newest",
139 selector_modifier = function(selector) selector:add_order_by("initiative.created DESC, initiative.id") end
140 }
142 order_filter[#order_filter+1] = {
143 name = "oldest",
144 label = _"Oldest",
145 selector_modifier = function(selector) selector:add_order_by("initiative.created, initiative.id") end
146 }
148 ui_filters = ui.filters
150 if no_sort then
151 ui_filters = function(args) args.content() end
152 if issue.ranks_available then
153 initiatives_selector:add_order_by("initiative.rank, initiative.admitted DESC, vote_ratio(initiative.positive_votes, initiative.negative_votes) DESC, initiative.id")
154 else
155 initiatives_selector:add_order_by("CASE WHEN issue.population = 0 OR initiative.supporter_count = 0 OR initiative.supporter_count ISNULL THEN 0 ELSE initiative.supporter_count::float / issue.population::float END DESC, initiative.id")
156 end
157 end
159 ui_filters{
160 label = _"Change order",
161 order_filter,
162 selector = initiatives_selector,
163 content = function()
164 ui.paginate{
165 name = issue and "issue_" .. tostring(issue.id) .. "_page" or nil,
166 selector = initiatives_selector,
167 per_page = param.get("per_page", atom.number) or limit,
168 content = function()
169 local initiatives = initiatives_selector:exec()
170 if highlight_initiative then
171 local highlight_initiative_found
172 for i, initiative in ipairs(initiatives) do
173 if initiative.id == highlight_initiative.id then
174 highhighlight_initiative_found = true
175 end
176 end
177 if not highhighlight_initiative_found then
178 initiatives[#initiatives+1] = highlight_initiative
179 if more_initiatives_count then
180 more_initiatives_count = more_initiatives_count - 1
181 end
182 end
183 end
184 for i, initiative in ipairs(initiatives) do
185 local expanded = config.user_tab_mode == "accordeon_all_expanded" and expandable or
186 show_for_initiative and initiative.id == show_for_initiative.id
187 if expanded then
188 ui.script{ script = "lf_initiative_expanded['initiative_content_" .. tostring(initiative.id) .. "'] = true;" }
189 end
190 execute.view{
191 module = "initiative",
192 view = "_list_element",
193 params = {
194 initiative = initiative,
195 selected = highlight_initiative and highlight_initiative.id == initiative.id or nil,
196 expanded = expanded,
197 expandable = expandable
198 }
199 }
200 end
201 end
202 }
203 end
204 }
206 if more_initiatives_count then
207 local text
208 if more_initiatives_count == 1 then
209 text = _("and one more initiative")
210 else
211 text = _("and #{count} more initiatives", { count = more_initiatives_count })
212 end
213 ui.link{
214 attr = { class = "more_initiatives_link" },
215 content = text,
216 module = "issue",
217 view = "show",
218 id = issue.id,
219 }
220 end
222 end
224 if show_for_issue then
225 slot.put("<br />")
227 if issue and initiatives_count == 1 then
228 ui.container{
229 content = function()
230 if issue.fully_frozen or issue.closed then
231 slot.put(_"There were no more alternative initiatives.")
232 else
233 slot.put(_"There are no more alternative initiatives currently.")
234 end
235 end
236 }
237 end
239 end

Impressum / About Us