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