liquid_feedback_frontend
diff app/main/initiative/_suggestions.lua @ 1843:b01d9920371b
merge
author | jbe |
---|---|
date | Thu Feb 03 15:57:22 2022 +0100 (2022-02-03) |
parents | fe28be5403e2 |
children | 080f4112b8a9 |
line diff
1.1 --- a/app/main/initiative/_suggestions.lua Thu Feb 03 15:54:23 2022 +0100 1.2 +++ b/app/main/initiative/_suggestions.lua Thu Feb 03 15:57:22 2022 +0100 1.3 @@ -6,7 +6,7 @@ 1.4 1.5 1.6 if direct_supporter then 1.7 - ui.tag{ tag = "dialog", attr = { id = "rating_dialog" }, content = function () 1.8 + ui.tag{ tag = "div", attr = { id = "rating_dialog", class = "hidden" }, content = function () 1.9 1.10 local opinion = {} 1.11 ui.form { 1.12 @@ -112,7 +112,7 @@ 1.13 ui.tag{ 1.14 tag = "input", 1.15 attr = { 1.16 - onclick = "document.getElementById('rating_dialog').close(); return false;", 1.17 + onclick = "document.getElementById('rating_dialog').classList.add('hidden'); return false;", 1.18 type = "submit", 1.19 class = "mdl-button mdl-js-button", 1.20 value = _"cancel" 1.21 @@ -133,214 +133,228 @@ 1.22 attr = { class = "section suggestions" }, 1.23 content = function () 1.24 1.25 - if # ( initiative.suggestions ) > 0 then 1.26 - 1.27 - ui.heading { 1.28 - level = 1, 1.29 - content = _("Suggestions for improvement (#{count})", { count = # ( initiative.suggestions ) } ) 1.30 + ui.heading { 1.31 + level = 1, 1.32 + content = _("Suggestions for improvement (#{count})", { count = # ( initiative.suggestions ) } ) 1.33 + } 1.34 + 1.35 + ui.container { content = _"written and rated by the supportes of this initiative to improve the proposal and its reasons" } 1.36 + 1.37 + if app.session.member_id and initiative.member_info.supported and not active_trustee_id then 1.38 + ui.link { 1.39 + attr = { 1.40 + style = "margin-top: 1ex;", 1.41 + class = "mdl-button mdl-js-button mdl-button--raised mdl-button--colored", 1.42 + }, 1.43 + module = "suggestion", view = "new", params = { 1.44 + initiative_id = initiative.id 1.45 + }, 1.46 + content = _"write a new suggestion" 1.47 } 1.48 - ui.container { content = _"written and rated by the supportes of this initiative to improve the proposal and its reasons" } 1.49 - slot.put("<br />") 1.50 - 1.51 - for i, suggestion in ipairs(initiative.suggestions) do 1.52 - 1.53 - local opinion = Opinion:by_pk(app.session.member_id, suggestion.id) 1.54 + end 1.55 + 1.56 + slot.put("<br /><br />") 1.57 + 1.58 + for i, suggestion in ipairs(initiative.suggestions) do 1.59 + 1.60 + local opinion = Opinion:by_pk(app.session.member_id, suggestion.id) 1.61 1.62 - local class = "mdl-card mdl-card__fullwidth mdl-shadow--2dp not-folded" 1.63 - if suggestion.id == param.get("suggestion_id", atom.number) then 1.64 - class = class .. " highlighted" 1.65 - end 1.66 - if member and not initiative.issue.fully_frozen and not initiative.issue.closed and initiative.member_info.supported then 1.67 - class = class .. " rateable" 1.68 - end 1.69 + local class = "mdl-card mdl-card__fullwidth mdl-shadow--2dp not-folded" 1.70 + if suggestion.id == param.get("suggestion_id", atom.number) then 1.71 + class = class .. " highlighted" 1.72 + end 1.73 + if member and not initiative.issue.fully_frozen and not initiative.issue.closed and initiative.member_info.supported then 1.74 + class = class .. " rateable" 1.75 + end 1.76 + 1.77 + ui.link { attr = { name = "s" .. suggestion.id }, text = "" } 1.78 + ui.tag { tag = "div", attr = { class = class, id = "s" .. suggestion.id }, content = function () 1.79 + ui.tag{ attr = { class = "mdl-card__title mdl-card--border" }, content = function() 1.80 + ui.heading { level = 2, 1.81 + attr = { class = "mdl-card__title-text" }, 1.82 + content = function() 1.83 + ui.tag{ content = format.string(suggestion.name, { 1.84 + truncate_at = 160, truncate_suffix = true }) 1.85 + } 1.86 + end 1.87 + } 1.88 + end } 1.89 + 1.90 + 1.91 + 1.92 + ui.container{ attr = { class = "suggestion-content" }, content = function() 1.93 1.94 - ui.link { attr = { name = "s" .. suggestion.id }, text = "" } 1.95 - ui.tag { tag = "div", attr = { class = class, id = "s" .. suggestion.id }, content = function () 1.96 - ui.tag{ attr = { class = "mdl-card__title mdl-card--border" }, content = function() 1.97 - ui.heading { level = 2, 1.98 - attr = { class = "mdl-card__title-text" }, 1.99 - content = function() 1.100 - ui.tag{ content = format.string(suggestion.name, { 1.101 - truncate_at = 160, truncate_suffix = true }) 1.102 + ui.container { 1.103 + attr = { class = "mdl-card__content mdl-card--border suggestionInfo" }, 1.104 + content = function () 1.105 + 1.106 + if app.session:has_access("authors_pseudonymous") then 1.107 + ui.tag{ content = _"by" } 1.108 + slot.put(" ") 1.109 + ui.link{ 1.110 + module = "member", view = "show", id = suggestion.author_id, 1.111 + content = suggestion.author.name 1.112 } 1.113 end 1.114 - } 1.115 - end } 1.116 + 1.117 + execute.view{ 1.118 + module = "suggestion", view = "_collective_rating", params = { 1.119 + suggestion = suggestion 1.120 + } 1.121 + } 1.122 1.123 - 1.124 - 1.125 - ui.container{ attr = { class = "suggestion-content" }, content = function() 1.126 - 1.127 - ui.container { 1.128 - attr = { class = "mdl-card__content mdl-card--border suggestionInfo" }, 1.129 - content = function () 1.130 + end 1.131 + } 1.132 1.133 - if app.session:has_access("authors_pseudonymous") then 1.134 - ui.tag{ content = _"by" } 1.135 - slot.put(" ") 1.136 - ui.link{ 1.137 - module = "member", view = "show", id = suggestion.author_id, 1.138 - content = suggestion.author.name 1.139 - } 1.140 - end 1.141 - 1.142 - execute.view{ 1.143 - module = "suggestion", view = "_collective_rating", params = { 1.144 - suggestion = suggestion 1.145 - } 1.146 + ui.container { 1.147 + attr = { class = "mdl-card__content suggestion-text draft" }, 1.148 + content = function () 1.149 + slot.put ( suggestion:get_content( "html" ) ) 1.150 + 1.151 + ui.container { attr = { class = "floatx-right" }, content = function() 1.152 + 1.153 + ui.link { 1.154 + attr = { 1.155 + class = "mdl-button mdl-js-button mdl-button--icon suggestion-more", 1.156 + onclick = "document.querySelector('#s" .. suggestion.id .. "').classList.remove('folded');document.querySelector('#s" .. suggestion.id .. "').classList.add('unfolded'); return false;" 1.157 + }, 1.158 + content = function() 1.159 + ui.tag{ tag = "i", attr = { class = "material-icons" }, content = "expand_more" } 1.160 + end 1.161 } 1.162 - 1.163 - end 1.164 - } 1.165 1.166 - ui.container { 1.167 - attr = { class = "mdl-card__content suggestion-text draft" }, 1.168 - content = function () 1.169 - slot.put ( suggestion:get_content( "html" ) ) 1.170 + ui.link { 1.171 + attr = { 1.172 + class = "mdl-button mdl-js-button mdl-button--icon suggestion-less", 1.173 + onclick = "document.querySelector('#s" .. suggestion.id .. "').classList.add('folded');document.querySelector('#s" .. suggestion.id .. "').classList.remove('unfolded'); return false;" 1.174 + }, 1.175 + content = function() 1.176 + ui.tag{ tag = "i", attr = { class = "material-icons" }, content = "expand_less" } 1.177 + end 1.178 + } 1.179 + --[[ 1.180 + ui.link{ 1.181 + attr = { class = "mdl-button" }, 1.182 + content = _"Details", 1.183 + module = "suggestion", view = "show", id = suggestion.id 1.184 + } 1.185 + --]] 1.186 + end } 1.187 + 1.188 + end 1.189 + } 1.190 + 1.191 + end } 1.192 + 1.193 + ui.container { attr = { class = "mdl-card__actions mdl-card--border" }, content = function() 1.194 1.195 - ui.container { attr = { class = "floatx-right" }, content = function() 1.196 - 1.197 - ui.link { 1.198 - attr = { 1.199 - class = "mdl-button mdl-js-button mdl-button--icon suggestion-more", 1.200 - onclick = "document.querySelector('#s" .. suggestion.id .. "').classList.remove('folded');document.querySelector('#s" .. suggestion.id .. "').classList.add('unfolded'); return false;" 1.201 - }, 1.202 - content = function() 1.203 - ui.tag{ tag = "i", attr = { class = "material-icons" }, content = "expand_more" } 1.204 - end 1.205 - } 1.206 - 1.207 - ui.link { 1.208 - attr = { 1.209 - class = "mdl-button mdl-js-button mdl-button--icon suggestion-less", 1.210 - onclick = "document.querySelector('#s" .. suggestion.id .. "').classList.add('folded');document.querySelector('#s" .. suggestion.id .. "').classList.remove('unfolded'); return false;" 1.211 - }, 1.212 - content = function() 1.213 - ui.tag{ tag = "i", attr = { class = "material-icons" }, content = "expand_less" } 1.214 - end 1.215 - } 1.216 - --[[ 1.217 - ui.link{ 1.218 - attr = { class = "mdl-button" }, 1.219 - content = _"Details", 1.220 - module = "suggestion", view = "show", id = suggestion.id 1.221 - } 1.222 - --]] 1.223 - end } 1.224 - 1.225 + if direct_supporter then 1.226 + ui.container{ attr = { class = "suggestion_rating_info" }, content = function() 1.227 + ui.tag{ attr = { id = "s" .. suggestion.id .. "_rating_text" }, content = function() 1.228 + local text_opinion = "" 1.229 + if opinion then 1.230 + local text_template 1.231 + if 1.232 + (opinion.degree > 0 and not opinion.fulfilled) 1.233 + or (opinion.degree < 0 and opinion.fulfilled) 1.234 + then 1.235 + text_template = _"#{opinion} but #{implemented}" 1.236 + else 1.237 + text_template = _"#{opinion} and #{implemented}" 1.238 + end 1.239 + if opinion.degree == 2 then 1.240 + text_opinion = _"must" 1.241 + elseif opinion.degree == 1 then 1.242 + text_opinion = _"should" 1.243 + elseif opinion.degree == 0 then 1.244 + text_opinion = _"neutral" 1.245 + elseif opinion.degree == -1 then 1.246 + text_opinion = _"should not" 1.247 + elseif opinion.degree == -2 then 1.248 + text_opinion = _"must not" 1.249 + end 1.250 + local text_implemented = "" 1.251 + if opinion.fulfilled then 1.252 + text_implemented = _"is implemented" 1.253 + else 1.254 + text_implemented = _"is not implemented" 1.255 + end 1.256 + ui.tag { content = _(text_template, { 1.257 + opinion = text_opinion, 1.258 + implemented = text_implemented 1.259 + }) } 1.260 + end 1.261 + end } 1.262 + local id = "s" .. suggestion.id .. "_rating_icon" 1.263 + if opinion and ( 1.264 + (opinion.degree > 0 and not opinion.fulfilled) 1.265 + or (opinion.degree < 0 and opinion.fulfilled) 1.266 + ) 1.267 + then 1.268 + slot.put(" ") 1.269 + if math.abs(opinion.degree) > 1 then 1.270 + ui.icon("warning", "red", id) 1.271 + else 1.272 + ui.icon("warning", nil, id) 1.273 + end 1.274 + elseif opinion then 1.275 + slot.put(" ") 1.276 + ui.icon("done", nil, id) 1.277 + else 1.278 + slot.put(" ") 1.279 + ui.icon("blank", nil, id) 1.280 + end 1.281 + end } 1.282 + 1.283 + ui.tag{ 1.284 + tag = "a", 1.285 + attr = { 1.286 + id = "s" .. suggestion.id .. "_rate_button", 1.287 + class = "mdl-button", 1.288 + onclick = "rateSuggestion(" .. suggestion.id .. ", " .. (opinion and opinion.degree or 0) .. ", " .. (opinion and (opinion.fulfilled and "true" or "false") or "null") .. ");return false;" 1.289 + }, 1.290 + content = function() 1.291 + if opinion then 1.292 + ui.tag { content = _"update rating" } 1.293 + else 1.294 + ui.tag { content = _"rate suggestion" } 1.295 + end 1.296 end 1.297 } 1.298 - 1.299 - end } 1.300 - 1.301 - ui.container { attr = { class = "mdl-card__actions mdl-card--border" }, content = function() 1.302 + end 1.303 + 1.304 + ui.link{ 1.305 + attr = { class = "mdl-button" }, 1.306 + content = _"Details", 1.307 + module = "suggestion", view = "show", id = suggestion.id 1.308 + } 1.309 1.310 - if direct_supporter then 1.311 - ui.container{ attr = { class = "suggestion_rating_info" }, content = function() 1.312 - ui.tag{ attr = { id = "s" .. suggestion.id .. "_rating_text" }, content = function() 1.313 - local text = "" 1.314 - if opinion then 1.315 - if opinion.degree == 2 then 1.316 - text = _"must" 1.317 - elseif opinion.degree == 1 then 1.318 - text = _"should" 1.319 - elseif opinion.degree == 0 then 1.320 - text = _"neutral" 1.321 - elseif opinion.degree == -1 then 1.322 - text = _"should not" 1.323 - elseif opinion.degree == -2 then 1.324 - text = _"must not" 1.325 - end 1.326 - ui.tag { content = text } 1.327 - slot.put ( " " ) 1.328 - if 1.329 - (opinion.degree > 0 and not opinion.fulfilled) 1.330 - or (opinion.degree < 0 and opinion.fulfilled) 1.331 - then 1.332 - ui.tag{ content = _"but" } 1.333 - else 1.334 - ui.tag{ content = _"and" } 1.335 - end 1.336 - slot.put ( " " ) 1.337 - local text = "" 1.338 - if opinion.fulfilled then 1.339 - text = _"is implemented" 1.340 - else 1.341 - text = _"is not implemented" 1.342 - end 1.343 - ui.tag { content = text } 1.344 - end 1.345 - end } 1.346 - local id = "s" .. suggestion.id .. "_rating_icon" 1.347 - if opinion and ( 1.348 - (opinion.degree > 0 and not opinion.fulfilled) 1.349 - or (opinion.degree < 0 and opinion.fulfilled) 1.350 - ) 1.351 - then 1.352 - slot.put(" ") 1.353 - if math.abs(opinion.degree) > 1 then 1.354 - ui.icon("warning", "red", id) 1.355 - else 1.356 - ui.icon("warning", nil, id) 1.357 - end 1.358 - elseif opinion then 1.359 - slot.put(" ") 1.360 - ui.icon("done", nil, id) 1.361 - else 1.362 - slot.put(" ") 1.363 - ui.icon("blank", nil, id) 1.364 - end 1.365 - end } 1.366 - 1.367 - ui.link{ 1.368 - attr = { 1.369 - id = "s" .. suggestion.id .. "_rate_button", 1.370 - class = "mdl-button", 1.371 - onclick = "rateSuggestion(" .. suggestion.id .. ", " .. (opinion and opinion.degree or 0) .. ", " .. (opinion and (opinion.fulfilled and "true" or "false") or "null") .. ");return false;" 1.372 - }, 1.373 - content = function() 1.374 - if opinion then 1.375 - ui.tag { content = _"update rating" } 1.376 - else 1.377 - ui.tag { content = _"rate suggestion" } 1.378 - end 1.379 - end 1.380 - } 1.381 - end 1.382 - 1.383 - ui.link{ 1.384 - attr = { class = "mdl-button" }, 1.385 - content = _"Details", 1.386 - module = "suggestion", view = "show", id = suggestion.id 1.387 + end } 1.388 + ui.script{ script = [[ 1.389 + var rateSuggestionRateText = "]] .. _"rate suggestion" .. [["; 1.390 + var rateSuggestionUpdateRatingText = "]] .. _"update rating" .. [["; 1.391 + var rateSuggestionAndText = "]] .. _"#{opinion} and #{implemented}" .. [["; 1.392 + var rateSuggestionButText = "]] .. _"#{opinion} but #{implemented}" .. [["; 1.393 + var rateSuggestionDegreeTexts = { 1.394 + "-2": "]] .. _"must not" .. [[", 1.395 + "-1": "]] .. _"should not" .. [[", 1.396 + "1": "]] .. _"should" .. [[", 1.397 + "2": "]] .. _"must" .. [[" 1.398 + } 1.399 + var rateSuggestionFulfilledText = "]] .. _"is implemented" .. [["; 1.400 + var rateSuggestionNotFulfilledText = "]] .. _"is not implemented" .. [["; 1.401 + window.addEventListener("load", function() { 1.402 + var textEl = document.querySelector('#s]] .. suggestion.id .. [[ .suggestion-content'); 1.403 + var height = textEl.clientHeight; 1.404 + if (height > 250) { 1.405 + document.querySelector('#s]] .. suggestion.id .. [[').classList.add('folded'); 1.406 } 1.407 + }); 1.408 + ]] } 1.409 + 1.410 + end } 1.411 1.412 - end } 1.413 - ui.script{ script = [[ 1.414 - var rateSuggestionRateText = "]] .. _"rate suggestion" .. [["; 1.415 - var rateSuggestionUpdateRatingText = "]] .. _"update rating" .. [["; 1.416 - var rateSuggestionDegreeTexts = { 1.417 - "-2": "]] .. _"must not" .. [[", 1.418 - "-1": "]] .. _"should not" .. [[", 1.419 - "1": "]] .. _"should" .. [[", 1.420 - "2": "]] .. _"must" .. [[" 1.421 - } 1.422 - var rateSuggestionAndText = "]] .. _"and" .. [["; 1.423 - var rateSuggestionButText = "]] .. _"but" .. [["; 1.424 - var rateSuggestionFulfilledText = "]] .. _"is implemented" .. [["; 1.425 - var rateSuggestionNotFulfilledText = "]] .. _"is not implemented" .. [["; 1.426 - window.addEventListener("load", function() { 1.427 - var textEl = document.querySelector('#s]] .. suggestion.id .. [[ .suggestion-content'); 1.428 - var height = textEl.clientHeight; 1.429 - if (height > 250) { 1.430 - document.querySelector('#s]] .. suggestion.id .. [[').classList.add('folded'); 1.431 - } 1.432 - }); 1.433 - ]] } 1.434 - 1.435 - end } 1.436 - 1.437 - end -- for i, suggestion 1.438 - 1.439 - end -- if #initiative.suggestions > 0 1.440 + end -- for i, suggestion 1.441 + 1.442 end 1.443 }