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