From 9e07acac39f6f9d66fd19368c4eb5d025e53974f Mon Sep 17 00:00:00 2001 From: Xavier Shay Date: Sat, 25 Feb 2012 11:27:48 -0800 Subject: [PATCH 1/2] Fix AJAX deletion and undo. This JS was not written to be bundled together, but with the new Rails asset pipeline that is exactly what happens. As a result, multiple conflicting behaviours were being added to each form. This commit ensures that only the desired behaviour is applied to each page. Fixes #50. --- app/assets/javascripts/admin/comments.js | 3 -- app/assets/javascripts/admin/common.js | 7 ++++ app/assets/javascripts/admin/dashboard.js | 40 ++++++++++++----------- app/assets/javascripts/admin/pages.js | 1 - app/assets/javascripts/admin/posts.js | 1 - app/views/admin/comments/index.html.erb | 3 +- app/views/admin/pages/index.html.erb | 2 +- app/views/admin/posts/index.html.erb | 3 +- 8 files changed, 33 insertions(+), 27 deletions(-) delete mode 100644 app/assets/javascripts/admin/comments.js delete mode 100644 app/assets/javascripts/admin/pages.js delete mode 100644 app/assets/javascripts/admin/posts.js diff --git a/app/assets/javascripts/admin/comments.js b/app/assets/javascripts/admin/comments.js deleted file mode 100644 index 742e58a13..000000000 --- a/app/assets/javascripts/admin/comments.js +++ /dev/null @@ -1,3 +0,0 @@ -$(document).ready(function() { - destroyAndUndoBehaviour('comments') -}); // Defined in admin/common.js diff --git a/app/assets/javascripts/admin/common.js b/app/assets/javascripts/admin/common.js index 1c0fd665f..43a2b215c 100644 --- a/app/assets/javascripts/admin/common.js +++ b/app/assets/javascripts/admin/common.js @@ -107,3 +107,10 @@ function destroyAndUndoBehaviour(type) { } } +$(document).ready(function() { + $(['posts', 'comments', 'pages']).each(function() { + if ($('#' + this).length > 0) { + destroyAndUndoBehaviour(this)(); + } + }); +}); diff --git a/app/assets/javascripts/admin/dashboard.js b/app/assets/javascripts/admin/dashboard.js index 2b0330fe0..41b1d0ffe 100644 --- a/app/assets/javascripts/admin/dashboard.js +++ b/app/assets/javascripts/admin/dashboard.js @@ -4,30 +4,32 @@ function extractId(obj) { } $(document).ready(function (){ - $('.comment-body').hide(); + if ($('#recent-comments').length) { + $('.comment-body').hide(); - $('.comment-link').click (function() { - comment_body_id = '#comment-body-' + extractId($(this)); + $('.comment-link').click (function() { + comment_body_id = '#comment-body-' + extractId($(this)); - $('.comment-body').not(comment_body_id).hide(); - $(comment_body_id).toggle(); + $('.comment-body').not(comment_body_id).hide(); + $(comment_body_id).toggle(); - return false; - }) + return false; + }) - $(document).click(function() { - $('.comment-body').hide(); - }); + $(document).click(function() { + $('.comment-body').hide(); + }); - asyncUndoBehaviour(); + asyncUndoBehaviour(); - $('form.delete-item').submit(function () { - asyncDeleteForm($(this)); + $('form.delete-item').submit(function () { + asyncDeleteForm($(this)); - // Assume success and remove comment - comment_link_id = '#comment-link-' + extractId($(this)); - $(comment_link_id).remove(); - $(this).parent('div').parent('div').remove(); - return false; - }); + // Assume success and remove comment + comment_link_id = '#comment-link-' + extractId($(this)); + $(comment_link_id).remove(); + $(this).parent('div').parent('div').remove(); + return false; + }); + } }) diff --git a/app/assets/javascripts/admin/pages.js b/app/assets/javascripts/admin/pages.js deleted file mode 100644 index 38f290a86..000000000 --- a/app/assets/javascripts/admin/pages.js +++ /dev/null @@ -1 +0,0 @@ -$(document).ready(destroyAndUndoBehaviour('pages')); // Defined in admin/common.js diff --git a/app/assets/javascripts/admin/posts.js b/app/assets/javascripts/admin/posts.js deleted file mode 100644 index bd962b8fb..000000000 --- a/app/assets/javascripts/admin/posts.js +++ /dev/null @@ -1 +0,0 @@ -$(document).ready(destroyAndUndoBehaviour('posts')); // Defined in admin/common.js diff --git a/app/views/admin/comments/index.html.erb b/app/views/admin/comments/index.html.erb index 8aeb18a67..98a5212ed 100644 --- a/app/views/admin/comments/index.html.erb +++ b/app/views/admin/comments/index.html.erb @@ -1,5 +1,6 @@

Comments

- + +
diff --git a/app/views/admin/pages/index.html.erb b/app/views/admin/pages/index.html.erb index de5237994..825417aaa 100644 --- a/app/views/admin/pages/index.html.erb +++ b/app/views/admin/pages/index.html.erb @@ -1,6 +1,6 @@

Your pages

-
Created At
+
diff --git a/app/views/admin/posts/index.html.erb b/app/views/admin/posts/index.html.erb index 3e1b982e4..411c5d702 100644 --- a/app/views/admin/posts/index.html.erb +++ b/app/views/admin/posts/index.html.erb @@ -1,5 +1,6 @@

Your posts

-
Created At
+ +
From 83caf02a0837336b15a90b5779137a6b6ceedd97 Mon Sep 17 00:00:00 2001 From: Xavier Shay Date: Sat, 25 Feb 2012 11:29:19 -0800 Subject: [PATCH 2/2] Fix incorrect alt text on delete post. --- app/views/admin/posts/_post.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/posts/_post.html.erb b/app/views/admin/posts/_post.html.erb index 9b5b29aa7..1410c7def 100644 --- a/app/views/admin/posts/_post.html.erb +++ b/app/views/admin/posts/_post.html.erb @@ -6,7 +6,7 @@
Published At <%= link_to(image_tag('silk/pencil.png', :alt => 'edit'), admin_post_path(post)) %> <%= form_for(post, :as => :post, :url => admin_post_path(post), :html => {:class => 'delete-item', :method => :delete}) do |form| -%> - <%= image_submit_tag("silk/delete.png", :alt => 'Delete Comment') %> + <%= image_submit_tag("silk/delete.png", :alt => 'Delete Post') %> <% end -%>