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@1724:     ui.heading { 
bsw@1724:       level = 1, 
bsw@1724:       content = _("Suggestions for improvement (#{count})", { count = # ( initiative.suggestions ) } ) 
bsw@1724:     }
bsw@1724: 
bsw@1724:     ui.container { content = _"written and rated by the supportes of this initiative to improve the proposal and its reasons" }
bsw@1724: 
bsw@1729:     if app.session.member_id and initiative.member_info.supported and not active_trustee_id then
bsw@1724:       ui.link {
bsw@1724:         attr = {
bsw@1724:             style = "margin-top: 1ex;",
bsw@1724:             class = "mdl-button mdl-js-button mdl-button--raised mdl-button--colored",
bsw@1724:         },
bsw@1724:         module = "suggestion", view = "new", params = {
bsw@1724:           initiative_id = initiative.id
bsw@1724:         },
bsw@1724:         content = _"write a new suggestion" 
bsw/jbe@1309:       }
bsw@1724:     end
bsw@1724: 
bsw@1724:     slot.put("
")
bsw@1724: 
bsw@1724:     for i, suggestion in ipairs(initiative.suggestions) do
bsw@1724: 
bsw@1724:       local opinion = Opinion:by_pk(app.session.member_id, suggestion.id)
bsw/jbe@1309: 
bsw@1724:       local class = "mdl-card mdl-card__fullwidth mdl-shadow--2dp not-folded"
bsw@1724:       if suggestion.id == param.get("suggestion_id", atom.number) then
bsw@1724:         class = class .. " highlighted"
bsw@1724:       end
bsw@1724:       if member and not initiative.issue.fully_frozen and not initiative.issue.closed and initiative.member_info.supported then
bsw@1724:         class = class .. " rateable"
bsw@1724:       end
bsw@1724:     
bsw@1724:       ui.link { attr = { name = "s" .. suggestion.id }, text = "" }
bsw@1724:       ui.tag { tag = "div", attr = { class = class, id = "s" .. suggestion.id }, content = function ()
bsw@1724:         ui.tag{ attr = { class = "mdl-card__title mdl-card--border" }, content = function()
bsw@1724:           ui.heading { level = 2, 
bsw@1724:             attr = { class = "mdl-card__title-text" },
bsw@1724:             content = function()
bsw@1724:               ui.tag{ content = format.string(suggestion.name, {
bsw@1724:                 truncate_at = 160, truncate_suffix = true })
bsw@1724:               }
bsw@1724:             end
bsw@1724:           }
bsw@1724:         end }
bsw@1724: 
bsw@1724:           
bsw@1724:     
bsw@1724:         ui.container{ attr = { class = "suggestion-content" }, content = function()
bsw/jbe@1309:       
bsw@1724:           ui.container { 
bsw@1724:             attr = { class = "mdl-card__content mdl-card--border suggestionInfo" },
bsw@1724:             content = function ()
bsw@1724:             
bsw@1724:               if app.session:has_access("authors_pseudonymous") then
bsw@1724:                 ui.tag{ content = _"by" }
bsw@1724:                 slot.put(" ")
bsw@1724:                 ui.link{
bsw@1724:                   module = "member", view = "show", id = suggestion.author_id,
bsw@1724:                   content = suggestion.author.name
bsw/jbe@1309:                 }
bsw@1649:               end
bsw@1724:               
bsw@1724:               execute.view{
bsw@1724:                 module = "suggestion", view = "_collective_rating", params = {
bsw@1724:                   suggestion = suggestion
bsw@1724:                 }
bsw@1724:               }
bsw/jbe@1309: 
bsw@1724:             end 
bsw@1724:           }
bsw/jbe@1309:               
bsw@1724:           ui.container {
bsw@1724:             attr = { class = "mdl-card__content suggestion-text draft" },
bsw@1724:             content = function ()
bsw@1724:               slot.put ( suggestion:get_content( "html" ) )
bsw@1724: 
bsw@1724:               ui.container { attr = { class = "floatx-right" }, content = function()
bsw@1724:               
bsw@1724:                 ui.link { 
bsw@1724:                   attr = { 
bsw@1724:                     class = "mdl-button mdl-js-button mdl-button--icon suggestion-more",
bsw@1724:                     onclick = "document.querySelector('#s" .. suggestion.id .. "').classList.remove('folded');document.querySelector('#s" .. suggestion.id .. "').classList.add('unfolded'); return false;"
bsw@1724:                   },
bsw@1724:                   content = function()
bsw@1724:                     ui.tag{ tag = "i", attr = { class = "material-icons" }, content = "expand_more" }
bsw@1724:                   end
bsw@1649:                 }
bsw/jbe@1309:                 
bsw@1724:                 ui.link { 
bsw@1724:                   attr = { 
bsw@1724:                     class = "mdl-button mdl-js-button mdl-button--icon suggestion-less",
bsw@1724:                     onclick = "document.querySelector('#s" .. suggestion.id .. "').classList.add('folded');document.querySelector('#s" .. suggestion.id .. "').classList.remove('unfolded'); return false;"
bsw@1724:                   },
bsw@1724:                   content = function()
bsw@1724:                     ui.tag{ tag = "i", attr = { class = "material-icons" }, content = "expand_less" }
bsw@1724:                   end
bsw@1724:                 }
bsw@1724:                 --[[
bsw@1724:                 ui.link{
bsw@1724:                   attr = { class = "mdl-button" },
bsw@1724:                   content = _"Details",
bsw@1724:                   module = "suggestion", view = "show", id = suggestion.id
bsw@1724:                 }
bsw@1724:                 --]]
bsw@1724:               end }
bsw@1724:              
bsw@1724:             end
bsw@1724:           }
bsw@1724: 
bsw@1724:         end }
bsw@1724: 
bsw@1724:         ui.container { attr = { class = "mdl-card__actions mdl-card--border" }, content = function()
bsw@1649: 
bsw@1724:           if direct_supporter then
bsw@1724:             ui.container{ attr = { class = "suggestion_rating_info" }, content = function()
bsw@1724:               ui.tag{ attr = { id = "s" .. suggestion.id .. "_rating_text" }, content = function()
bsw@1724:                 local text = ""
bsw@1724:                 if opinion then
bsw@1724:                   if opinion.degree == 2 then
bsw@1724:                     text = _"must"
bsw@1724:                   elseif opinion.degree == 1 then
bsw@1724:                     text = _"should"
bsw@1724:                   elseif opinion.degree == 0 then
bsw@1724:                     text = _"neutral"
bsw@1724:                   elseif opinion.degree == -1 then
bsw@1724:                     text = _"should not"
bsw@1724:                   elseif opinion.degree == -2 then
bsw@1724:                     text = _"must not"
bsw@1724:                   end
bsw@1724:                   ui.tag { content = text }
bsw@1724:                   slot.put ( " " )
bsw@1724:                   if 
bsw@1724:                     (opinion.degree > 0 and not opinion.fulfilled)
bsw@1724:                     or (opinion.degree < 0 and opinion.fulfilled)
bsw@1724:                   then
bsw@1724:                     ui.tag{ content = _"but" }
bsw@1724:                   else
bsw@1724:                     ui.tag{ content = _"and" }
bsw@1724:                   end
bsw@1724:                   slot.put ( " " )
bsw@1724:                   local text = ""
bsw@1724:                   if opinion.fulfilled then
bsw@1724:                     text = _"is implemented"
bsw@1724:                   else
bsw@1724:                     text = _"is not implemented"
bsw@1724:                   end
bsw@1724:                   ui.tag { content = text }
bsw@1724:                 end
bsw@1724:               end }
bsw@1724:               local id = "s" .. suggestion.id .. "_rating_icon"
bsw@1724:               if opinion and (
bsw@1724:                   (opinion.degree > 0 and not opinion.fulfilled)
bsw@1724:                   or (opinion.degree < 0 and opinion.fulfilled)
bsw@1724:                 )
bsw@1724:               then
bsw@1724:                 slot.put(" ")
bsw@1724:                 if math.abs(opinion.degree) > 1 then
bsw@1724:                   ui.icon("warning", "red", id)
bsw@1724:                 else
bsw@1724:                   ui.icon("warning", nil, id)
bsw@1724:                 end
bsw@1724:               elseif opinion then
bsw@1724:                 slot.put(" ")
bsw@1724:                 ui.icon("done", nil, id)
bsw@1724:               else
bsw@1724:                 slot.put(" ")
bsw@1724:                 ui.icon("blank", nil, id)
bsw@1724:               end
bsw@1724:             end }
bsw@1724:             
bsw@1724:             ui.link{
bsw@1724:               attr = {
bsw@1724:                 id = "s" .. suggestion.id .. "_rate_button",
bsw@1724:                 class = "mdl-button",
bsw@1724:                 onclick = "rateSuggestion(" .. suggestion.id .. ", " .. (opinion and opinion.degree or 0) .. ", " .. (opinion and (opinion.fulfilled and "true" or "false") or "null") .. ");return false;"
bsw@1724:               },
bsw@1724:               content = function()
bsw@1724:                 if opinion then
bsw@1724:                   ui.tag { content = _"update rating" }
bsw@1724:                 else
bsw@1724:                   ui.tag { content = _"rate suggestion" }
bsw@1724:                 end
bsw/jbe@1309:               end
bsw/jbe@1309:             }
bsw@1724:           end
bsw@1724:                     
bsw@1724:           ui.link{
bsw@1724:             attr = { class = "mdl-button" },
bsw@1724:             content = _"Details",
bsw@1724:             module = "suggestion", view = "show", id = suggestion.id
bsw@1724:           }
bsw@1649: 
bsw@1724:         end }
bsw@1724:         ui.script{ script = [[
bsw@1724:           var rateSuggestionRateText = "]] .. _"rate suggestion" .. [[";
bsw@1724:           var rateSuggestionUpdateRatingText = "]] .. _"update rating" .. [[";
bsw@1724:           var rateSuggestionDegreeTexts = {
bsw@1724:             "-2": "]] .. _"must not" .. [[",
bsw@1724:             "-1": "]] .. _"should not" .. [[",
bsw@1724:             "1": "]] .. _"should" .. [[",
bsw@1724:             "2": "]] .. _"must" .. [["
bsw@1724:           }
bsw@1724:           var rateSuggestionAndText = "]] .. _"and" .. [[";
bsw@1724:           var rateSuggestionButText = "]] .. _"but" .. [[";
bsw@1724:           var rateSuggestionFulfilledText = "]] .. _"is implemented" .. [[";
bsw@1724:           var rateSuggestionNotFulfilledText = "]] .. _"is not implemented" .. [[";
bsw@1724:           window.addEventListener("load", function() {
bsw@1724:             var textEl = document.querySelector('#s]] .. suggestion.id .. [[ .suggestion-content');
bsw@1724:             var height = textEl.clientHeight;
bsw@1724:             if (height > 250) {
bsw@1724:               document.querySelector('#s]] .. suggestion.id .. [[').classList.add('folded');
bsw/jbe@1309:             }
bsw@1724:           });
bsw@1724:         ]] }
bsw@1724:         
bsw@1724:       end } 
bsw@1649: 
bsw@1724:     end -- for i, suggestion
bsw@1724:   
bsw/jbe@1309:   end
bsw/jbe@1309: }