bsw/jbe@1309: local initiative = param.get("initiative", "table") bsw/jbe@1309: local direct_supporter bsw/jbe@1309: if app.session.member_id then bsw/jbe@1309: direct_supporter = initiative.issue.member_info.own_participation and initiative.member_info.supported bsw/jbe@1309: end bsw/jbe@1309: bsw/jbe@1309: bsw@1649: if direct_supporter then bsw@1649: ui.tag{ tag = "dialog", attr = { id = "rating_dialog" }, content = function () bsw@1649: bsw@1649: local opinion = {} bsw@1649: ui.form { bsw@1649: attr = { onsubmit = "updateOpinion(); return false;" }, bsw@1649: module = "opinion", action = "update", bsw@1649: routing = { default = { bsw@1649: mode = "redirect", bsw@1649: module = "initiative", view = "show", id = initiative.id bsw@1649: } }, bsw@1649: content = function () bsw@1649: ui.field.hidden{ attr = { id = "rating_suggestion_id" }, name = "suggestion_id" } bsw@1649: ui.container{ attr = { class = "opinon-question" }, content = _"Should the initiator implement this suggestion?" } bsw@1649: ui.container { content = function () bsw@1649: bsw@1649: local options = { bsw@1649: { degree = 2, label = _"must" }, bsw@1649: { degree = 1, label = _"should" }, bsw@1649: { degree = 0, label = _"neutral" }, bsw@1649: { degree = -1, label = _"should not" }, bsw@1649: { degree = -2, label = _"must not" }, bsw@1649: } bsw@1649: bsw@1649: for i, option in ipairs(options) do bsw@1649: ui.tag{ bsw@1649: tag = "label", bsw@1649: attr = { bsw@1649: id = "rating_degree" .. option.degree, bsw@1649: class = "mdl-radio mdl-js-radio mdl-js-ripple-effect" bsw@1649: }, bsw@1649: ["for"] = "rating_degree" .. option.degree, bsw@1649: content = function() bsw@1649: ui.tag{ bsw@1649: tag = "input", bsw@1649: attr = { bsw@1649: class = "mdl-radio__button", bsw@1649: type = "radio", bsw@1649: name = "degree", bsw@1649: value = option.degree bsw@1649: } bsw@1649: } bsw@1649: ui.tag{ bsw@1649: attr = { class = "mdl-radio__label" }, bsw@1649: content = option.label bsw@1649: } bsw@1649: end bsw@1649: } bsw@1649: slot.put("     ") bsw@1649: end bsw@1649: end } bsw@1649: bsw@1649: slot.put("
") bsw@1649: bsw@1649: ui.container{ attr = { class = "opinon-question" }, content = _"Did the initiator implement this suggestion?" } bsw@1649: ui.container { content = function () bsw@1649: bsw@1649: local options = { bsw@1649: { degree = "false", id = "notfulfilled", label = _"No (not yet)" }, bsw@1649: { degree = "true", id = "fulfilled", label = _"Yes, it's implemented" }, bsw@1649: } bsw@1649: bsw@1649: for i, option in ipairs(options) do bsw@1649: ui.tag{ bsw@1649: tag = "label", bsw@1649: attr = { bsw@1649: id = "rating_" .. option.id, bsw@1649: class = "mdl-radio mdl-js-radio mdl-js-ripple-effect" bsw@1649: }, bsw@1649: ["for"] = "rating_" .. option.id, bsw@1649: content = function() bsw@1649: ui.tag{ bsw@1649: tag = "input", bsw@1649: attr = { bsw@1649: class = "mdl-radio__button", bsw@1649: type = "radio", bsw@1649: name = "fulfilled", bsw@1649: value = option.degree, bsw@1649: } bsw@1649: } bsw@1649: ui.tag{ bsw@1649: attr = { class = "mdl-radio__label" }, bsw@1649: content = option.label bsw@1649: } bsw@1649: end bsw@1649: } bsw@1649: slot.put("     ") bsw@1649: end bsw@1649: end } bsw@1649: bsw@1649: slot.put("
") bsw@1649: bsw@1649: ui.tag{ bsw@1649: tag = "input", bsw@1649: attr = { bsw@1649: type = "submit", bsw@1649: class = "mdl-button mdl-js-button mdl-button--raised mdl-button--colored", bsw@1649: value = _"publish my rating" bsw@1649: }, bsw@1649: content = "" bsw@1649: } bsw@1649: bsw@1649: slot.put("   ") bsw@1649: bsw@1649: ui.tag{ bsw@1649: tag = "input", bsw@1649: attr = { bsw@1649: onclick = "document.getElementById('rating_dialog').close(); return false;", bsw@1649: type = "submit", bsw@1649: class = "mdl-button mdl-js-button", bsw@1649: value = _"cancel" bsw@1649: }, bsw@1649: content = "" bsw@1649: } bsw@1649: bsw@1649: end bsw@1649: } bsw@1649: bsw@1649: end } bsw@1649: end bsw@1649: bsw@1649: bsw/jbe@1309: ui.link { attr = { name = "suggestions" }, text = "" } bsw/jbe@1309: bsw/jbe@1309: ui.container { bsw/jbe@1309: attr = { class = "section suggestions" }, bsw/jbe@1309: content = function () bsw/jbe@1309: bsw/jbe@1309: if # ( initiative.suggestions ) > 0 then bsw/jbe@1309: bsw/jbe@1309: ui.heading { bsw/jbe@1309: level = 1, bsw/jbe@1309: content = _("Suggestions for improvement (#{count})", { count = # ( initiative.suggestions ) } ) bsw/jbe@1309: } bsw/jbe@1309: ui.container { content = _"written and rated by the supportes of this initiative to improve the proposal and its reasons" } bsw/jbe@1309: slot.put("
") bsw/jbe@1309: bsw/jbe@1309: for i, suggestion in ipairs(initiative.suggestions) do bsw/jbe@1309: bsw/jbe@1309: local opinion = Opinion:by_pk(app.session.member_id, suggestion.id) bsw/jbe@1309: bsw/jbe@1309: local class = "mdl-card mdl-card__fullwidth mdl-shadow--2dp not-folded" bsw/jbe@1309: if suggestion.id == param.get("suggestion_id", atom.number) then bsw/jbe@1309: class = class .. " highlighted" bsw/jbe@1309: end bsw/jbe@1309: if member and not initiative.issue.fully_frozen and not initiative.issue.closed and initiative.member_info.supported then bsw/jbe@1309: class = class .. " rateable" bsw/jbe@1309: end bsw/jbe@1309: bsw/jbe@1309: ui.link { attr = { name = "s" .. suggestion.id }, text = "" } bsw/jbe@1309: ui.tag { tag = "div", attr = { class = class, id = "s" .. suggestion.id }, content = function () bsw/jbe@1309: ui.tag{ attr = { class = "mdl-card__title mdl-card--border" }, content = function() bsw/jbe@1309: ui.heading { level = 2, bsw/jbe@1309: attr = { class = "mdl-card__title-text" }, bsw@1649: content = function() bsw@1649: ui.tag{ content = format.string(suggestion.name, { bsw@1649: truncate_at = 160, truncate_suffix = true }) bsw/jbe@1309: } bsw@1649: end bsw@1649: } bsw@1649: end } bsw/jbe@1309: bsw@1649: bsw/jbe@1309: bsw/jbe@1309: ui.container{ attr = { class = "suggestion-content" }, content = function() bsw/jbe@1309: bsw/jbe@1309: ui.container { bsw/jbe@1309: attr = { class = "mdl-card__content mdl-card--border suggestionInfo" }, bsw/jbe@1309: content = function () bsw/jbe@1309: bsw/jbe@1309: if app.session:has_access("authors_pseudonymous") then bsw@1658: ui.tag{ content = _"by" } bsw@1658: slot.put(" ") bsw@1658: ui.link{ bsw@1658: module = "member", view = "show", id = suggestion.author_id, bsw@1658: content = suggestion.author.name bsw@1658: } bsw/jbe@1309: end bsw/jbe@1309: bsw@1649: execute.view{ bsw@1649: module = "suggestion", view = "_collective_rating", params = { bsw@1649: suggestion = suggestion bsw@1649: } bsw@1649: } bsw/jbe@1309: bsw/jbe@1309: end bsw/jbe@1309: } bsw/jbe@1309: bsw/jbe@1309: ui.container { bsw@1649: attr = { class = "mdl-card__content suggestion-text draft" }, bsw/jbe@1309: content = function () bsw/jbe@1309: slot.put ( suggestion:get_content( "html" ) ) bsw@1649: bsw@1649: ui.container { attr = { class = "floatx-right" }, content = function() bsw@1649: bsw@1649: ui.link { bsw@1649: attr = { bsw@1649: class = "mdl-button mdl-js-button mdl-button--icon suggestion-more", bsw@1649: onclick = "document.querySelector('#s" .. suggestion.id .. "').classList.remove('folded');document.querySelector('#s" .. suggestion.id .. "').classList.add('unfolded'); return false;" bsw@1649: }, bsw@1649: content = function() bsw@1649: ui.tag{ tag = "i", attr = { class = "material-icons" }, content = "expand_more" } bsw@1649: end bsw@1649: } bsw@1649: bsw@1649: ui.link { bsw@1649: attr = { bsw@1649: class = "mdl-button mdl-js-button mdl-button--icon suggestion-less", bsw@1649: onclick = "document.querySelector('#s" .. suggestion.id .. "').classList.add('folded');document.querySelector('#s" .. suggestion.id .. "').classList.remove('unfolded'); return false;" bsw@1649: }, bsw@1649: content = function() bsw@1649: ui.tag{ tag = "i", attr = { class = "material-icons" }, content = "expand_less" } bsw@1649: end bsw@1649: } bsw@1649: --[[ bsw@1649: ui.link{ bsw@1649: attr = { class = "mdl-button" }, bsw@1649: content = _"Details", bsw@1649: module = "suggestion", view = "show", id = suggestion.id bsw@1649: } bsw@1649: --]] bsw@1649: end } bsw/jbe@1309: bsw/jbe@1309: end bsw/jbe@1309: } bsw/jbe@1309: bsw/jbe@1309: end } bsw/jbe@1309: bsw@1649: ui.container { attr = { class = "mdl-card__actions mdl-card--border" }, content = function() bsw@1649: bsw@1658: if direct_supporter then bsw@1658: ui.container{ attr = { class = "suggestion_rating_info" }, content = function() bsw@1658: ui.tag{ attr = { id = "s" .. suggestion.id .. "_rating_text" }, content = function() bsw@1658: local text = "" bsw@1658: if opinion then bsw@1658: if opinion.degree == 2 then bsw@1658: text = _"must" bsw@1658: elseif opinion.degree == 1 then bsw@1658: text = _"should" bsw@1658: elseif opinion.degree == 0 then bsw@1658: text = _"neutral" bsw@1658: elseif opinion.degree == -1 then bsw@1658: text = _"should not" bsw@1658: elseif opinion.degree == -2 then bsw@1658: text = _"must not" bsw@1658: end bsw@1658: ui.tag { content = text } bsw@1658: slot.put ( " " ) bsw@1658: if bsw@1658: (opinion.degree > 0 and not opinion.fulfilled) bsw@1658: or (opinion.degree < 0 and opinion.fulfilled) bsw@1658: then bsw@1658: ui.tag{ content = _"but" } bsw@1658: else bsw@1658: ui.tag{ content = _"and" } bsw@1658: end bsw@1658: slot.put ( " " ) bsw@1658: local text = "" bsw@1658: if opinion.fulfilled then bsw@1658: text = _"is implemented" bsw@1658: else bsw@1658: text = _"is not implemented" bsw@1658: end bsw@1658: ui.tag { content = text } bsw@1649: end bsw@1658: end } bsw@1658: local id = "s" .. suggestion.id .. "_rating_icon" bsw@1658: if opinion and ( bsw@1649: (opinion.degree > 0 and not opinion.fulfilled) bsw@1649: or (opinion.degree < 0 and opinion.fulfilled) bsw@1658: ) bsw@1658: then bsw@1658: slot.put(" ") bsw@1658: if math.abs(opinion.degree) > 1 then bsw@1658: ui.icon("warning", "red", id) bsw@1649: else bsw@1658: ui.icon("warning", nil, id) bsw@1649: end bsw@1658: elseif opinion then bsw@1658: slot.put(" ") bsw@1658: ui.icon("done", nil, id) bsw@1658: else bsw@1658: slot.put(" ") bsw@1658: ui.icon("blank", nil, id) bsw@1649: end bsw@1649: end } bsw@1658: bsw@1658: ui.link{ bsw@1658: attr = { bsw@1658: id = "s" .. suggestion.id .. "_rate_button", bsw@1658: class = "mdl-button", bsw@1658: onclick = "rateSuggestion(" .. suggestion.id .. ", " .. (opinion and opinion.degree or 0) .. ", " .. (opinion and (opinion.fulfilled and "true" or "false") or "null") .. ");return false;" bsw@1658: }, bsw@1658: content = function() bsw@1658: if opinion then bsw@1658: ui.tag { content = _"update rating" } bsw@1658: else bsw@1658: ui.tag { content = _"rate suggestion" } bsw@1658: end bsw@1649: end bsw@1658: } bsw@1658: end bsw@1658: bsw/jbe@1309: ui.link{ bsw/jbe@1309: attr = { class = "mdl-button" }, bsw/jbe@1309: content = _"Details", bsw/jbe@1309: module = "suggestion", view = "show", id = suggestion.id bsw/jbe@1309: } bsw@1649: bsw/jbe@1309: end } bsw/jbe@1309: ui.script{ script = [[ bsw@1649: var rateSuggestionRateText = "]] .. _"rate suggestion" .. [["; bsw@1649: var rateSuggestionUpdateRatingText = "]] .. _"update rating" .. [["; bsw@1649: var rateSuggestionDegreeTexts = { bsw@1649: "-2": "]] .. _"must not" .. [[", bsw@1649: "-1": "]] .. _"should not" .. [[", bsw@1649: "1": "]] .. _"should" .. [[", bsw@1649: "2": "]] .. _"must" .. [[" bsw@1649: } bsw@1649: var rateSuggestionAndText = "]] .. _"and" .. [["; bsw@1649: var rateSuggestionButText = "]] .. _"but" .. [["; bsw@1649: var rateSuggestionFulfilledText = "]] .. _"is implemented" .. [["; bsw@1649: var rateSuggestionNotFulfilledText = "]] .. _"is not implemented" .. [["; bsw/jbe@1309: window.addEventListener("load", function() { bsw/jbe@1309: var textEl = document.querySelector('#s]] .. suggestion.id .. [[ .suggestion-content'); bsw/jbe@1309: var height = textEl.clientHeight; bsw@1649: if (height > 250) { bsw/jbe@1309: document.querySelector('#s]] .. suggestion.id .. [[').classList.add('folded'); bsw/jbe@1309: } bsw/jbe@1309: }); bsw/jbe@1309: ]] } bsw/jbe@1309: bsw/jbe@1309: end } bsw/jbe@1309: bsw/jbe@1309: end -- for i, suggestion bsw/jbe@1309: bsw/jbe@1309: end -- if #initiative.suggestions > 0 bsw/jbe@1309: end bsw/jbe@1309: }