liquid_feedback_frontend

view app/main/initiative/_suggestions.lua @ 1855:080f4112b8a9

Show new suggestion button only during admission and discussion
author bsw
date Thu Mar 24 10:37:44 2022 +0100 (2022-03-24)
parents fe28be5403e2
children
line source
1 local initiative = param.get("initiative", "table")
2 local direct_supporter
3 if app.session.member_id then
4 direct_supporter = initiative.issue.member_info.own_participation and initiative.member_info.supported
5 end
8 if direct_supporter then
9 ui.tag{ tag = "div", attr = { id = "rating_dialog", class = "hidden" }, content = function ()
11 local opinion = {}
12 ui.form {
13 attr = { onsubmit = "updateOpinion(); return false;" },
14 module = "opinion", action = "update",
15 routing = { default = {
16 mode = "redirect",
17 module = "initiative", view = "show", id = initiative.id
18 } },
19 content = function ()
20 ui.field.hidden{ attr = { id = "rating_suggestion_id" }, name = "suggestion_id" }
21 ui.container{ attr = { class = "opinon-question" }, content = _"Should the initiator implement this suggestion?" }
22 ui.container { content = function ()
24 local options = {
25 { degree = 2, label = _"must" },
26 { degree = 1, label = _"should" },
27 { degree = 0, label = _"neutral" },
28 { degree = -1, label = _"should not" },
29 { degree = -2, label = _"must not" },
30 }
32 for i, option in ipairs(options) do
33 ui.tag{
34 tag = "label",
35 attr = {
36 id = "rating_degree" .. option.degree,
37 class = "mdl-radio mdl-js-radio mdl-js-ripple-effect"
38 },
39 ["for"] = "rating_degree" .. option.degree,
40 content = function()
41 ui.tag{
42 tag = "input",
43 attr = {
44 class = "mdl-radio__button",
45 type = "radio",
46 name = "degree",
47 value = option.degree
48 }
49 }
50 ui.tag{
51 attr = { class = "mdl-radio__label" },
52 content = option.label
53 }
54 end
55 }
56 slot.put("     ")
57 end
58 end }
60 slot.put("<br />")
62 ui.container{ attr = { class = "opinon-question" }, content = _"Did the initiator implement this suggestion?" }
63 ui.container { content = function ()
65 local options = {
66 { degree = "false", id = "notfulfilled", label = _"No (not yet)" },
67 { degree = "true", id = "fulfilled", label = _"Yes, it's implemented" },
68 }
70 for i, option in ipairs(options) do
71 ui.tag{
72 tag = "label",
73 attr = {
74 id = "rating_" .. option.id,
75 class = "mdl-radio mdl-js-radio mdl-js-ripple-effect"
76 },
77 ["for"] = "rating_" .. option.id,
78 content = function()
79 ui.tag{
80 tag = "input",
81 attr = {
82 class = "mdl-radio__button",
83 type = "radio",
84 name = "fulfilled",
85 value = option.degree,
86 }
87 }
88 ui.tag{
89 attr = { class = "mdl-radio__label" },
90 content = option.label
91 }
92 end
93 }
94 slot.put(" &nbsp;&nbsp;&nbsp; ")
95 end
96 end }
98 slot.put("<br />")
100 ui.tag{
101 tag = "input",
102 attr = {
103 type = "submit",
104 class = "mdl-button mdl-js-button mdl-button--raised mdl-button--colored",
105 value = _"publish my rating"
106 },
107 content = ""
108 }
110 slot.put(" &nbsp; ")
112 ui.tag{
113 tag = "input",
114 attr = {
115 onclick = "document.getElementById('rating_dialog').classList.add('hidden'); return false;",
116 type = "submit",
117 class = "mdl-button mdl-js-button",
118 value = _"cancel"
119 },
120 content = ""
121 }
123 end
124 }
126 end }
127 end
130 ui.link { attr = { name = "suggestions" }, text = "" }
132 ui.container {
133 attr = { class = "section suggestions" },
134 content = function ()
136 ui.heading {
137 level = 1,
138 content = _("Suggestions for improvement (#{count})", { count = # ( initiative.suggestions ) } )
139 }
141 ui.container { content = _"written and rated by the supportes of this initiative to improve the proposal and its reasons" }
143 if (initiative.issue.state == "admission" or initiative.issue.state == "discussion") and app.session.member_id and initiative.member_info.supported and not active_trustee_id then
144 ui.link {
145 attr = {
146 style = "margin-top: 1ex;",
147 class = "mdl-button mdl-js-button mdl-button--raised mdl-button--colored",
148 },
149 module = "suggestion", view = "new", params = {
150 initiative_id = initiative.id
151 },
152 content = _"write a new suggestion"
153 }
154 end
156 slot.put("<br /><br />")
158 for i, suggestion in ipairs(initiative.suggestions) do
160 local opinion = Opinion:by_pk(app.session.member_id, suggestion.id)
162 local class = "mdl-card mdl-card__fullwidth mdl-shadow--2dp not-folded"
163 if suggestion.id == param.get("suggestion_id", atom.number) then
164 class = class .. " highlighted"
165 end
166 if member and not initiative.issue.fully_frozen and not initiative.issue.closed and initiative.member_info.supported then
167 class = class .. " rateable"
168 end
170 ui.link { attr = { name = "s" .. suggestion.id }, text = "" }
171 ui.tag { tag = "div", attr = { class = class, id = "s" .. suggestion.id }, content = function ()
172 ui.tag{ attr = { class = "mdl-card__title mdl-card--border" }, content = function()
173 ui.heading { level = 2,
174 attr = { class = "mdl-card__title-text" },
175 content = function()
176 ui.tag{ content = format.string(suggestion.name, {
177 truncate_at = 160, truncate_suffix = true })
178 }
179 end
180 }
181 end }
185 ui.container{ attr = { class = "suggestion-content" }, content = function()
187 ui.container {
188 attr = { class = "mdl-card__content mdl-card--border suggestionInfo" },
189 content = function ()
191 if app.session:has_access("authors_pseudonymous") then
192 ui.tag{ content = _"by" }
193 slot.put(" ")
194 ui.link{
195 module = "member", view = "show", id = suggestion.author_id,
196 content = suggestion.author.name
197 }
198 end
200 execute.view{
201 module = "suggestion", view = "_collective_rating", params = {
202 suggestion = suggestion
203 }
204 }
206 end
207 }
209 ui.container {
210 attr = { class = "mdl-card__content suggestion-text draft" },
211 content = function ()
212 slot.put ( suggestion:get_content( "html" ) )
214 ui.container { attr = { class = "floatx-right" }, content = function()
216 ui.link {
217 attr = {
218 class = "mdl-button mdl-js-button mdl-button--icon suggestion-more",
219 onclick = "document.querySelector('#s" .. suggestion.id .. "').classList.remove('folded');document.querySelector('#s" .. suggestion.id .. "').classList.add('unfolded'); return false;"
220 },
221 content = function()
222 ui.tag{ tag = "i", attr = { class = "material-icons" }, content = "expand_more" }
223 end
224 }
226 ui.link {
227 attr = {
228 class = "mdl-button mdl-js-button mdl-button--icon suggestion-less",
229 onclick = "document.querySelector('#s" .. suggestion.id .. "').classList.add('folded');document.querySelector('#s" .. suggestion.id .. "').classList.remove('unfolded'); return false;"
230 },
231 content = function()
232 ui.tag{ tag = "i", attr = { class = "material-icons" }, content = "expand_less" }
233 end
234 }
235 --[[
236 ui.link{
237 attr = { class = "mdl-button" },
238 content = _"Details",
239 module = "suggestion", view = "show", id = suggestion.id
240 }
241 --]]
242 end }
244 end
245 }
247 end }
249 ui.container { attr = { class = "mdl-card__actions mdl-card--border" }, content = function()
251 if direct_supporter then
252 ui.container{ attr = { class = "suggestion_rating_info" }, content = function()
253 ui.tag{ attr = { id = "s" .. suggestion.id .. "_rating_text" }, content = function()
254 local text_opinion = ""
255 if opinion then
256 local text_template
257 if
258 (opinion.degree > 0 and not opinion.fulfilled)
259 or (opinion.degree < 0 and opinion.fulfilled)
260 then
261 text_template = _"#{opinion} but #{implemented}"
262 else
263 text_template = _"#{opinion} and #{implemented}"
264 end
265 if opinion.degree == 2 then
266 text_opinion = _"must"
267 elseif opinion.degree == 1 then
268 text_opinion = _"should"
269 elseif opinion.degree == 0 then
270 text_opinion = _"neutral"
271 elseif opinion.degree == -1 then
272 text_opinion = _"should not"
273 elseif opinion.degree == -2 then
274 text_opinion = _"must not"
275 end
276 local text_implemented = ""
277 if opinion.fulfilled then
278 text_implemented = _"is implemented"
279 else
280 text_implemented = _"is not implemented"
281 end
282 ui.tag { content = _(text_template, {
283 opinion = text_opinion,
284 implemented = text_implemented
285 }) }
286 end
287 end }
288 local id = "s" .. suggestion.id .. "_rating_icon"
289 if opinion and (
290 (opinion.degree > 0 and not opinion.fulfilled)
291 or (opinion.degree < 0 and opinion.fulfilled)
292 )
293 then
294 slot.put(" ")
295 if math.abs(opinion.degree) > 1 then
296 ui.icon("warning", "red", id)
297 else
298 ui.icon("warning", nil, id)
299 end
300 elseif opinion then
301 slot.put(" ")
302 ui.icon("done", nil, id)
303 else
304 slot.put(" ")
305 ui.icon("blank", nil, id)
306 end
307 end }
309 ui.tag{
310 tag = "a",
311 attr = {
312 id = "s" .. suggestion.id .. "_rate_button",
313 class = "mdl-button",
314 onclick = "rateSuggestion(" .. suggestion.id .. ", " .. (opinion and opinion.degree or 0) .. ", " .. (opinion and (opinion.fulfilled and "true" or "false") or "null") .. ");return false;"
315 },
316 content = function()
317 if opinion then
318 ui.tag { content = _"update rating" }
319 else
320 ui.tag { content = _"rate suggestion" }
321 end
322 end
323 }
324 end
326 ui.link{
327 attr = { class = "mdl-button" },
328 content = _"Details",
329 module = "suggestion", view = "show", id = suggestion.id
330 }
332 end }
333 ui.script{ script = [[
334 var rateSuggestionRateText = "]] .. _"rate suggestion" .. [[";
335 var rateSuggestionUpdateRatingText = "]] .. _"update rating" .. [[";
336 var rateSuggestionAndText = "]] .. _"#{opinion} and #{implemented}" .. [[";
337 var rateSuggestionButText = "]] .. _"#{opinion} but #{implemented}" .. [[";
338 var rateSuggestionDegreeTexts = {
339 "-2": "]] .. _"must not" .. [[",
340 "-1": "]] .. _"should not" .. [[",
341 "1": "]] .. _"should" .. [[",
342 "2": "]] .. _"must" .. [["
343 }
344 var rateSuggestionFulfilledText = "]] .. _"is implemented" .. [[";
345 var rateSuggestionNotFulfilledText = "]] .. _"is not implemented" .. [[";
346 window.addEventListener("load", function() {
347 var textEl = document.querySelector('#s]] .. suggestion.id .. [[ .suggestion-content');
348 var height = textEl.clientHeight;
349 if (height > 250) {
350 document.querySelector('#s]] .. suggestion.id .. [[').classList.add('folded');
351 }
352 });
353 ]] }
355 end }
357 end -- for i, suggestion
359 end
360 }

Impressum / About Us