liquid_feedback_frontend

annotate app/main/initiative/_suggestions.lua @ 1729:ae45894bbf08

Check for member before checking supporter status
author bsw
date Tue Sep 28 15:01:54 2021 +0200 (2021-09-28)
parents c33916811ca7
children 7df91db759ce
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(" &nbsp;&nbsp;&nbsp; ")
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(" &nbsp; ")
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@1724 136 ui.heading {
bsw@1724 137 level = 1,
bsw@1724 138 content = _("Suggestions for improvement (#{count})", { count = # ( initiative.suggestions ) } )
bsw@1724 139 }
bsw@1724 140
bsw@1724 141 ui.container { content = _"written and rated by the supportes of this initiative to improve the proposal and its reasons" }
bsw@1724 142
bsw@1729 143 if app.session.member_id and initiative.member_info.supported and not active_trustee_id then
bsw@1724 144 ui.link {
bsw@1724 145 attr = {
bsw@1724 146 style = "margin-top: 1ex;",
bsw@1724 147 class = "mdl-button mdl-js-button mdl-button--raised mdl-button--colored",
bsw@1724 148 },
bsw@1724 149 module = "suggestion", view = "new", params = {
bsw@1724 150 initiative_id = initiative.id
bsw@1724 151 },
bsw@1724 152 content = _"write a new suggestion"
bsw/jbe@1309 153 }
bsw@1724 154 end
bsw@1724 155
bsw@1724 156 slot.put("<br /><br />")
bsw@1724 157
bsw@1724 158 for i, suggestion in ipairs(initiative.suggestions) do
bsw@1724 159
bsw@1724 160 local opinion = Opinion:by_pk(app.session.member_id, suggestion.id)
bsw/jbe@1309 161
bsw@1724 162 local class = "mdl-card mdl-card__fullwidth mdl-shadow--2dp not-folded"
bsw@1724 163 if suggestion.id == param.get("suggestion_id", atom.number) then
bsw@1724 164 class = class .. " highlighted"
bsw@1724 165 end
bsw@1724 166 if member and not initiative.issue.fully_frozen and not initiative.issue.closed and initiative.member_info.supported then
bsw@1724 167 class = class .. " rateable"
bsw@1724 168 end
bsw@1724 169
bsw@1724 170 ui.link { attr = { name = "s" .. suggestion.id }, text = "" }
bsw@1724 171 ui.tag { tag = "div", attr = { class = class, id = "s" .. suggestion.id }, content = function ()
bsw@1724 172 ui.tag{ attr = { class = "mdl-card__title mdl-card--border" }, content = function()
bsw@1724 173 ui.heading { level = 2,
bsw@1724 174 attr = { class = "mdl-card__title-text" },
bsw@1724 175 content = function()
bsw@1724 176 ui.tag{ content = format.string(suggestion.name, {
bsw@1724 177 truncate_at = 160, truncate_suffix = true })
bsw@1724 178 }
bsw@1724 179 end
bsw@1724 180 }
bsw@1724 181 end }
bsw@1724 182
bsw@1724 183
bsw@1724 184
bsw@1724 185 ui.container{ attr = { class = "suggestion-content" }, content = function()
bsw/jbe@1309 186
bsw@1724 187 ui.container {
bsw@1724 188 attr = { class = "mdl-card__content mdl-card--border suggestionInfo" },
bsw@1724 189 content = function ()
bsw@1724 190
bsw@1724 191 if app.session:has_access("authors_pseudonymous") then
bsw@1724 192 ui.tag{ content = _"by" }
bsw@1724 193 slot.put(" ")
bsw@1724 194 ui.link{
bsw@1724 195 module = "member", view = "show", id = suggestion.author_id,
bsw@1724 196 content = suggestion.author.name
bsw/jbe@1309 197 }
bsw@1649 198 end
bsw@1724 199
bsw@1724 200 execute.view{
bsw@1724 201 module = "suggestion", view = "_collective_rating", params = {
bsw@1724 202 suggestion = suggestion
bsw@1724 203 }
bsw@1724 204 }
bsw/jbe@1309 205
bsw@1724 206 end
bsw@1724 207 }
bsw/jbe@1309 208
bsw@1724 209 ui.container {
bsw@1724 210 attr = { class = "mdl-card__content suggestion-text draft" },
bsw@1724 211 content = function ()
bsw@1724 212 slot.put ( suggestion:get_content( "html" ) )
bsw@1724 213
bsw@1724 214 ui.container { attr = { class = "floatx-right" }, content = function()
bsw@1724 215
bsw@1724 216 ui.link {
bsw@1724 217 attr = {
bsw@1724 218 class = "mdl-button mdl-js-button mdl-button--icon suggestion-more",
bsw@1724 219 onclick = "document.querySelector('#s" .. suggestion.id .. "').classList.remove('folded');document.querySelector('#s" .. suggestion.id .. "').classList.add('unfolded'); return false;"
bsw@1724 220 },
bsw@1724 221 content = function()
bsw@1724 222 ui.tag{ tag = "i", attr = { class = "material-icons" }, content = "expand_more" }
bsw@1724 223 end
bsw@1649 224 }
bsw/jbe@1309 225
bsw@1724 226 ui.link {
bsw@1724 227 attr = {
bsw@1724 228 class = "mdl-button mdl-js-button mdl-button--icon suggestion-less",
bsw@1724 229 onclick = "document.querySelector('#s" .. suggestion.id .. "').classList.add('folded');document.querySelector('#s" .. suggestion.id .. "').classList.remove('unfolded'); return false;"
bsw@1724 230 },
bsw@1724 231 content = function()
bsw@1724 232 ui.tag{ tag = "i", attr = { class = "material-icons" }, content = "expand_less" }
bsw@1724 233 end
bsw@1724 234 }
bsw@1724 235 --[[
bsw@1724 236 ui.link{
bsw@1724 237 attr = { class = "mdl-button" },
bsw@1724 238 content = _"Details",
bsw@1724 239 module = "suggestion", view = "show", id = suggestion.id
bsw@1724 240 }
bsw@1724 241 --]]
bsw@1724 242 end }
bsw@1724 243
bsw@1724 244 end
bsw@1724 245 }
bsw@1724 246
bsw@1724 247 end }
bsw@1724 248
bsw@1724 249 ui.container { attr = { class = "mdl-card__actions mdl-card--border" }, content = function()
bsw@1649 250
bsw@1724 251 if direct_supporter then
bsw@1724 252 ui.container{ attr = { class = "suggestion_rating_info" }, content = function()
bsw@1724 253 ui.tag{ attr = { id = "s" .. suggestion.id .. "_rating_text" }, content = function()
bsw@1724 254 local text = ""
bsw@1724 255 if opinion then
bsw@1724 256 if opinion.degree == 2 then
bsw@1724 257 text = _"must"
bsw@1724 258 elseif opinion.degree == 1 then
bsw@1724 259 text = _"should"
bsw@1724 260 elseif opinion.degree == 0 then
bsw@1724 261 text = _"neutral"
bsw@1724 262 elseif opinion.degree == -1 then
bsw@1724 263 text = _"should not"
bsw@1724 264 elseif opinion.degree == -2 then
bsw@1724 265 text = _"must not"
bsw@1724 266 end
bsw@1724 267 ui.tag { content = text }
bsw@1724 268 slot.put ( " " )
bsw@1724 269 if
bsw@1724 270 (opinion.degree > 0 and not opinion.fulfilled)
bsw@1724 271 or (opinion.degree < 0 and opinion.fulfilled)
bsw@1724 272 then
bsw@1724 273 ui.tag{ content = _"but" }
bsw@1724 274 else
bsw@1724 275 ui.tag{ content = _"and" }
bsw@1724 276 end
bsw@1724 277 slot.put ( " " )
bsw@1724 278 local text = ""
bsw@1724 279 if opinion.fulfilled then
bsw@1724 280 text = _"is implemented"
bsw@1724 281 else
bsw@1724 282 text = _"is not implemented"
bsw@1724 283 end
bsw@1724 284 ui.tag { content = text }
bsw@1724 285 end
bsw@1724 286 end }
bsw@1724 287 local id = "s" .. suggestion.id .. "_rating_icon"
bsw@1724 288 if opinion and (
bsw@1724 289 (opinion.degree > 0 and not opinion.fulfilled)
bsw@1724 290 or (opinion.degree < 0 and opinion.fulfilled)
bsw@1724 291 )
bsw@1724 292 then
bsw@1724 293 slot.put(" ")
bsw@1724 294 if math.abs(opinion.degree) > 1 then
bsw@1724 295 ui.icon("warning", "red", id)
bsw@1724 296 else
bsw@1724 297 ui.icon("warning", nil, id)
bsw@1724 298 end
bsw@1724 299 elseif opinion then
bsw@1724 300 slot.put(" ")
bsw@1724 301 ui.icon("done", nil, id)
bsw@1724 302 else
bsw@1724 303 slot.put(" ")
bsw@1724 304 ui.icon("blank", nil, id)
bsw@1724 305 end
bsw@1724 306 end }
bsw@1724 307
bsw@1724 308 ui.link{
bsw@1724 309 attr = {
bsw@1724 310 id = "s" .. suggestion.id .. "_rate_button",
bsw@1724 311 class = "mdl-button",
bsw@1724 312 onclick = "rateSuggestion(" .. suggestion.id .. ", " .. (opinion and opinion.degree or 0) .. ", " .. (opinion and (opinion.fulfilled and "true" or "false") or "null") .. ");return false;"
bsw@1724 313 },
bsw@1724 314 content = function()
bsw@1724 315 if opinion then
bsw@1724 316 ui.tag { content = _"update rating" }
bsw@1724 317 else
bsw@1724 318 ui.tag { content = _"rate suggestion" }
bsw@1724 319 end
bsw/jbe@1309 320 end
bsw/jbe@1309 321 }
bsw@1724 322 end
bsw@1724 323
bsw@1724 324 ui.link{
bsw@1724 325 attr = { class = "mdl-button" },
bsw@1724 326 content = _"Details",
bsw@1724 327 module = "suggestion", view = "show", id = suggestion.id
bsw@1724 328 }
bsw@1649 329
bsw@1724 330 end }
bsw@1724 331 ui.script{ script = [[
bsw@1724 332 var rateSuggestionRateText = "]] .. _"rate suggestion" .. [[";
bsw@1724 333 var rateSuggestionUpdateRatingText = "]] .. _"update rating" .. [[";
bsw@1724 334 var rateSuggestionDegreeTexts = {
bsw@1724 335 "-2": "]] .. _"must not" .. [[",
bsw@1724 336 "-1": "]] .. _"should not" .. [[",
bsw@1724 337 "1": "]] .. _"should" .. [[",
bsw@1724 338 "2": "]] .. _"must" .. [["
bsw@1724 339 }
bsw@1724 340 var rateSuggestionAndText = "]] .. _"and" .. [[";
bsw@1724 341 var rateSuggestionButText = "]] .. _"but" .. [[";
bsw@1724 342 var rateSuggestionFulfilledText = "]] .. _"is implemented" .. [[";
bsw@1724 343 var rateSuggestionNotFulfilledText = "]] .. _"is not implemented" .. [[";
bsw@1724 344 window.addEventListener("load", function() {
bsw@1724 345 var textEl = document.querySelector('#s]] .. suggestion.id .. [[ .suggestion-content');
bsw@1724 346 var height = textEl.clientHeight;
bsw@1724 347 if (height > 250) {
bsw@1724 348 document.querySelector('#s]] .. suggestion.id .. [[').classList.add('folded');
bsw/jbe@1309 349 }
bsw@1724 350 });
bsw@1724 351 ]] }
bsw@1724 352
bsw@1724 353 end }
bsw@1649 354
bsw@1724 355 end -- for i, suggestion
bsw@1724 356
bsw/jbe@1309 357 end
bsw/jbe@1309 358 }

Impressum / About Us