implements edit mode for post mode menu

This commit is contained in:
albert
2011-10-21 18:56:27 -04:00
parent 88317bb4c9
commit 8a5f26f3e5
6 changed files with 62 additions and 5 deletions

View File

@@ -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') {

View File

@@ -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) {

View File

@@ -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 {

View File

@@ -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

View File

@@ -14,6 +14,7 @@
</aside>
<section id="content">
<%= render "posts/partials/index/edit" %>
<%= render "wiki_pages/excerpt", :post_set => @post_set %>
<%= render "posts/partials/index/posts", :post_set => @post_set %>
</section>

View File

@@ -0,0 +1,8 @@
<div id="quick-edit-div">
<h1>Edit</h1>
<%= form_tag("/posts", :class => "simple_form", :method => :put, :id => "quick-edit-form") do %>
<%= text_area_tag "post[tag_string]", "" %>
<%= submit_tag "Submit" %>
<% end %>
</div>