liquid_feedback_frontend

view app/main/initiative/_list.lua @ 23:e04122245a44

Bugfix in app/main/initiative/show_static.lua: Added neccessary "expanded" argument
author bsw
date Sun Feb 21 13:09:00 2010 +0100 (2010-02-21)
parents 00d1004545f1
children 81586ea68d57
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")
6 initiatives_selector
7 :join("issue", nil, "issue.id = initiative.issue_id")
8 :left_join("initiator", "_initiator", { "_initiator.initiative_id = initiative.id AND _initiator.member_id = ?", app.session.member.id} )
9 :left_join("supporter", "_supporter", { "_supporter.initiative_id = initiative.id AND _supporter.member_id = ?", app.session.member.id} )
11 :add_field("(_initiator.member_id NOTNULL)", "is_initiator")
12 :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")
13 :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")
15 local initiatives_count = initiatives_selector:count()
17 local limit = param.get("limit", atom.number)
18 local no_sort = param.get("no_sort", atom.boolean)
20 local show_for_issue = param.get("show_for_issue", atom.boolean)
22 local show_for_initiative
24 local show_for_initiative_id = param.get("for_initiative_id", atom.number)
26 if show_for_initiative_id then
27 show_for_initiative = Initiative:by_id(show_for_initiative_id)
29 elseif not show_for_initiative_id and show_for_issue and issue and issue.ranks_available then
30 winning_initiative = Initiative:new_selector()
31 :add_where{ "issue_id = ?", issue.id }
32 :add_where("rank = 1")
33 :single_object_mode()
34 :exec()
35 if winning_initiative then
36 show_for_initiative = winning_initiative
37 ui.container{
38 attr = { class = "admitted_info" },
39 content = _"This issue has been finished with the following winning initiative:"
40 }
41 else
42 ui.container{
43 attr = { class = "not_admitted_info" },
44 content = _"This issue has been finished without any winning initiative."
45 }
46 end
47 end
50 if show_for_initiative then
51 ui.script{ script = "lf_initiative_expanded['initiative_content_" .. tostring(show_for_initiative.id) .. "'] = true;" }
52 initiatives_selector:add_where{ "initiative.id != ?", show_for_initiative.id }
54 execute.view{
55 module = "initiative",
56 view = "_list_element",
57 params = {
58 initiative = show_for_initiative,
59 expanded = true,
60 expandable = true
61 }
62 }
63 if show_for_issue then
64 slot.put("<br />")
65 ui.container{
66 attr = { style = "font-weight: bold;" },
67 content = function()
68 slot.put(_"Alternative initiatives")
69 end
70 }
71 end
72 elseif show_for_issue then
73 ui.container{
74 attr = { style = "font-weight: bold;" },
75 content = function()
76 slot.put(_"Alternative initiatives")
77 end
78 }
79 end
81 if not show_for_initiative or initiatives_count > 1 then
84 local more_initiatives_count
85 if limit then
86 limit = limit - (show_for_initiative and 1 or 0)
87 if initiatives_count > limit then
88 more_initiatives_count = initiatives_count - limit
89 end
90 initiatives_selector:limit(limit)
91 end
93 local expandable = param.get("expandable", atom.boolean)
95 local issue = param.get("issue", "table")
97 local name = "initiative_list"
98 if issue then
99 name = "issue_" .. tostring(issue.id) .. "_initiative_list"
100 end
102 ui.add_partial_param_names{ name }
104 local order_filter = {
105 name = name,
106 label = _"Order by"
107 }
109 if issue and issue.ranks_available then
110 order_filter[#order_filter+1] = {
111 name = "rank",
112 label = _"Rank",
113 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
114 }
115 end
117 order_filter[#order_filter+1] = {
118 name = "potential_support",
119 label = _"Potential support",
120 selector_modifier = function(selector) selector:add_order_by("initiative.supporter_count::float / issue.population::float DESC, initiative.id") end
121 }
123 order_filter[#order_filter+1] = {
124 name = "support",
125 label = _"Support",
126 selector_modifier = function(selector) selector:add_order_by("initiative.satisfied_supporter_count::float / issue.population::float DESC, initiative.id") end
127 }
129 order_filter[#order_filter+1] = {
130 name = "newest",
131 label = _"Newest",
132 selector_modifier = function(selector) selector:add_order_by("initiative.created DESC, initiative.id") end
133 }
135 order_filter[#order_filter+1] = {
136 name = "oldest",
137 label = _"Oldest",
138 selector_modifier = function(selector) selector:add_order_by("initiative.created, initiative.id") end
139 }
141 ui_filters = ui.filters
143 if no_sort then
144 ui_filters = function(args) args.content() end
145 if issue.ranks_available then
146 initiatives_selector:add_order_by("initiative.rank, initiative.admitted DESC, vote_ratio(initiative.positive_votes, initiative.negative_votes) DESC, initiative.id")
147 else
148 initiatives_selector:add_order_by("initiative.supporter_count::float / issue.population::float DESC, initiative.id")
149 end
150 end
152 ui_filters{
153 label = _"Change order",
154 order_filter,
155 selector = initiatives_selector,
156 content = function()
157 ui.paginate{
158 name = issue and "issue_" .. tostring(issue.id) .. "_page" or nil,
159 selector = initiatives_selector,
160 per_page = param.get("per_page", atom.number),
161 content = function()
162 local initiatives = initiatives_selector:exec()
163 for i, initiative in ipairs(initiatives) do
164 local expanded = config.user_tab_mode == "accordeon_all_expanded" and expandable or
165 show_for_initiative and initiative.id == show_for_initiative.id
166 if expanded then
167 ui.script{ script = "lf_initiative_expanded['initiative_content_" .. tostring(initiative.id) .. "'] = true;" }
168 end
169 execute.view{
170 module = "initiative",
171 view = "_list_element",
172 params = {
173 initiative = initiative,
174 expanded = expanded,
175 expandable = expandable
176 }
177 }
178 end
179 end
180 }
181 end
182 }
184 if more_initiatives_count then
185 ui.link{
186 attr = { style = "font-size: 75%; font-style: italic;" },
187 content = _("and #{count} more initiatives", { count = more_initiatives_count }),
188 module = "issue",
189 view = "show",
190 id = issue.id,
191 }
192 end
194 end
196 if show_for_issue then
197 slot.put("<br />")
199 if issue and initiatives_count == 1 then
200 ui.container{
201 content = function()
202 if issue.fully_frozen or issue.closed then
203 slot.put(_"There were no more alternative initiatives.")
204 else
205 slot.put(_"There are no more alternative initiatives currently.")
206 end
207 end
208 }
209 end
211 if not (issue.fully_frozen or issue.closed) then
212 slot.put(" ")
213 ui.link{
214 content = function()
215 ui.image{ static = "icons/16/script_add.png" }
216 slot.put(" ")
217 slot.put(_"Create alternative initiative")
218 end,
219 module = "initiative",
220 view = "new",
221 params = { issue_id = issue.id }
222 }
223 end
224 end

Impressum / About Us