Add a "Hide" button to notes when viewed by moderators
authorTom Hughes <tom@compton.nu>
Mon, 8 Apr 2013 20:34:38 +0000 (21:34 +0100)
committerTom Hughes <tom@compton.nu>
Mon, 8 Apr 2013 21:32:20 +0000 (22:32 +0100)
app/assets/javascripts/index/notes.js.erb
app/assets/javascripts/templates/notes/show.jst.ejs
app/helpers/application_helper.rb
config/locales/en.yml

index 9fb03bb0dd62af9ad4ec7c5be0a75a70fd0b20b4..0728907758dab6e88007e03367b4bf87ca123243 100644 (file)
@@ -161,7 +161,8 @@ $(document).ready(function () {
 
     content.find("input[type=submit]").on("click", function (e) {
       e.preventDefault();
 
     content.find("input[type=submit]").on("click", function (e) {
       e.preventDefault();
-      updateNote(marker, e.target.form, $(e.target).data("url"));
+      var data = $(e.target).data();
+      updateNote(marker, e.target.form, data.method, data.url);
     });
 
     return content[0];
     });
 
     return content[0];
@@ -190,21 +191,27 @@ $(document).ready(function () {
     });
   }
 
     });
   }
 
-  function updateNote(marker, form, url) {
+  function updateNote(marker, form, method, url) {
     $(form).find("input[type=submit]").prop("disabled", true);
 
     $.ajax({
       url: url,
     $(form).find("input[type=submit]").prop("disabled", true);
 
     $.ajax({
       url: url,
-      type: "POST",
+      type: method,
       oauth: true,
       data: {
         text: $(form.text).val()
       },
       success: function (feature) {
       oauth: true,
       data: {
         text: $(form.text).val()
       },
       success: function (feature) {
-        var popupContent = createPopupContent(marker, feature.properties);
+        if (feature.properties.status == "hidden") {
+          noteLayer.removeLayer(marker);
+
+          delete notes[feature.properties.id];
+        } else {
+          var popupContent = createPopupContent(marker, feature.properties);
 
 
-        marker.setIcon(noteIcons[feature.properties.status]);
-        marker._popup.setContent(popupContent);
+          marker.setIcon(noteIcons[feature.properties.status]);
+          marker._popup.setContent(popupContent);
+        }
       }
     });
   }
       }
     });
   }
index 7063090dfe29fddf53f941c6e48cfaa491062a95..04cb6dfc13dcfb84683d8fa0239079921aed9247 100644 (file)
@@ -25,8 +25,9 @@
     <textarea class="comment" name="text" cols="40" rows="5"></textarea>
     <br/>
     <div class="buttons">
     <textarea class="comment" name="text" cols="40" rows="5"></textarea>
     <br/>
     <div class="buttons">
-      <input type="submit" name="close" value="<%- I18n.t('javascripts.notes.show.resolve') %>" class="hide_unless_logged_in" data-url="<%- note.close_url %>">
-      <input type="submit" name="comment" value="<%- I18n.t('javascripts.notes.show.comment') %>" data-url="<%- note.comment_url %>" disabled="1">
+      <input type="submit" name="hide" value="<%- I18n.t('javascripts.notes.show.hide') %>" class="hide_unless_moderator" data-method="DELETE" data-url="<%- note.url %>">
+      <input type="submit" name="close" value="<%- I18n.t('javascripts.notes.show.resolve') %>" class="hide_unless_logged_in" data-method="POST" data-url="<%- note.close_url %>">
+      <input type="submit" name="comment" value="<%- I18n.t('javascripts.notes.show.comment') %>" data-method="POST" data-url="<%- note.comment_url %>" disabled="1">
     </div>
   </form>
   <% } %>
     </div>
   </form>
   <% } %>
index 3771acf3726746cbc44f99a5cc91af5c43c2c14b..b91710b9c6f3dfa86df5cfc82532b00294adf1f7 100644 (file)
@@ -26,6 +26,7 @@ module ApplicationHelper
     css << ".hide_if_user_#{@user.id} { display: none !important }" if @user;
     css << ".show_if_user_#{@user.id} { display: inline !important }" if @user;
     css << ".hide_unless_administrator { display: none !important }" unless @user and @user.administrator?;
     css << ".hide_if_user_#{@user.id} { display: none !important }" if @user;
     css << ".show_if_user_#{@user.id} { display: inline !important }" if @user;
     css << ".hide_unless_administrator { display: none !important }" unless @user and @user.administrator?;
+    css << ".hide_unless_moderator { display: none !important }" unless @user and @user.moderator?;
 
     return content_tag(:style, css, :type => "text/css")
   end
 
     return content_tag(:style, css, :type => "text/css")
   end
index 5d3e6bbaeef5b980e7100b4745bdcaaba708084d..01e4abecbd943d15b156f59d141370275571684e 100644 (file)
@@ -2041,6 +2041,7 @@ en:
         closed_by_anonymous: "resolved by anonymous at %{time}"
         reopened_by: "reactivated by <a href='%{user_url}'>%{user}</a> at %{time}"
         reopened_by_anonymous: "reactivated by anonymous at %{time}"
         closed_by_anonymous: "resolved by anonymous at %{time}"
         reopened_by: "reactivated by <a href='%{user_url}'>%{user}</a> at %{time}"
         reopened_by_anonymous: "reactivated by anonymous at %{time}"
+        hide: Hide
         resolve: Resolve
         comment_and_resolve: Comment & Resolve
         comment: Comment
         resolve: Resolve
         comment_and_resolve: Comment & Resolve
         comment: Comment