From 8a5f26f3e5b9917cb079cddc3ef6254330973707 Mon Sep 17 00:00:00 2001 From: albert Date: Fri, 21 Oct 2011 18:56:27 -0400 Subject: [PATCH] implements edit mode for post mode menu --- app/assets/javascripts/post_mode_menu.js | 32 ++++++++++++++++++- app/assets/javascripts/posts.js | 12 +++++-- .../stylesheets/specific/posts.css.scss | 8 +++++ app/controllers/posts_controller.rb | 6 +++- app/views/posts/index.html.erb | 1 + app/views/posts/partials/index/_edit.html.erb | 8 +++++ 6 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 app/views/posts/partials/index/_edit.html.erb diff --git a/app/assets/javascripts/post_mode_menu.js b/app/assets/javascripts/post_mode_menu.js index e10b9037f..5467c0f73 100644 --- a/app/assets/javascripts/post_mode_menu.js +++ b/app/assets/javascripts/post_mode_menu.js @@ -4,6 +4,7 @@ Danbooru.PostModeMenu.initialize = function() { this.initialize_selector(); this.initialize_preview_link(); + this.initialize_edit_form(); } Danbooru.PostModeMenu.initialize_selector = function() { @@ -21,7 +22,29 @@ $(".post-preview a").click(Danbooru.PostModeMenu.click); } + Danbooru.PostModeMenu.initialize_edit_form = function() { + $("#quick-edit-div").hide(); + + $("#quick-edit-form").submit(function(e) { + $.ajax({ + type: "put", + url: $("#quick-edit-form").attr("action"), + data: { + post: { + tag_string: $("#post_tag_string").val() + } + }, + success: function(data) { + Danbooru.Post.update_data(data); + } + }); + + e.preventDefault(); + }); + } + Danbooru.PostModeMenu.change = function() { + $("#quick-edit-div").hide(); var s = $("#mode-box select").val(); var $body = $(document.body); $body.removeClass(); @@ -43,6 +66,13 @@ } } + Danbooru.PostModeMenu.open_edit = function(post_id) { + var $post = $("#post_" + post_id); + $("#quick-edit-div").show(); + $("#quick-edit-form").attr("action", "/posts/" + post_id + ".json"); + $("#post_tag_string").val($post.data("tags")); + } + Danbooru.PostModeMenu.click = function(e) { var s = $("#mode-box select").val(); var post_id = $(e.target).closest("article").data("id"); @@ -52,7 +82,7 @@ } else if (s === "remove-fav") { Danbooru.Favorite.destroy(post_id); } else if (s === "edit") { - // TODO + Danbooru.PostModeMenu.open_edit(post_id); } else if (s === 'vote-down') { Danbooru.Post.vote("down", post_id); } else if (s === 'vote-up') { diff --git a/app/assets/javascripts/posts.js b/app/assets/javascripts/posts.js index c5281c58d..9d1d2731d 100644 --- a/app/assets/javascripts/posts.js +++ b/app/assets/javascripts/posts.js @@ -22,11 +22,15 @@ Danbooru.Post.initialize_titles = function() { $("article.post-preview").each(function(i, v) { - var $v = $(v); - $v.attr("title", $v.data("tags") + " uploader:" + $v.data("uploader") + " rating:" + $v.data("rating")); + Danbooru.Post.initialize_title_for(v); }); } + Danbooru.Post.initialize_title_for = function(post) { + var $post = $(post); + $post.attr("title", $post.data("tags") + " uploader:" + $post.data("uploader") + " rating:" + $post.data("rating")); + } + Danbooru.Post.initialize_image_resize = function() { if ($("#c-posts #a-show").size() > 0) { var default_image_size = Danbooru.meta("default-image-size"); @@ -124,7 +128,9 @@ Danbooru.Post.update_data = function(data) { var $post = $("#post_" + data.id); - $post.data("tags", data.tags); + $post.data("tags", data.tag_string); + $post.data("rating", data.rating); + Danbooru.Post.initialize_title_for($post); } Danbooru.Post.vote = function(score, id) { diff --git a/app/assets/stylesheets/specific/posts.css.scss b/app/assets/stylesheets/specific/posts.css.scss index 485dc0dab..fac1f1273 100644 --- a/app/assets/stylesheets/specific/posts.css.scss +++ b/app/assets/stylesheets/specific/posts.css.scss @@ -135,6 +135,14 @@ div#c-posts { margin-top: 1em; } } + + div#quick-edit-div { + textarea { + width: 30em; + height: 4em; + display: block; + } + } } div#c-explore-posts { diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index e47e16fab..5a1738046 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -19,7 +19,11 @@ class PostsController < ApplicationController def update @post = Post.find(params[:id]) @post.update_attributes(params[:post]) - respond_with(@post) + respond_with(@post) do |format| + format.json do + render :json => @post.to_json + end + end end def revert diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index 1fd067734..40e831cbb 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -14,6 +14,7 @@
+ <%= render "posts/partials/index/edit" %> <%= render "wiki_pages/excerpt", :post_set => @post_set %> <%= render "posts/partials/index/posts", :post_set => @post_set %>
diff --git a/app/views/posts/partials/index/_edit.html.erb b/app/views/posts/partials/index/_edit.html.erb new file mode 100644 index 000000000..9a5606aa2 --- /dev/null +++ b/app/views/posts/partials/index/_edit.html.erb @@ -0,0 +1,8 @@ +
+

Edit

+ + <%= form_tag("/posts", :class => "simple_form", :method => :put, :id => "quick-edit-form") do %> + <%= text_area_tag "post[tag_string]", "" %> + <%= submit_tag "Submit" %> + <% end %> +
\ No newline at end of file