This commit is contained in:
Toks
2013-05-18 16:25:46 -04:00
parent f2c4312f9f
commit 17af05b2b1
6 changed files with 55 additions and 0 deletions

View File

@@ -133,6 +133,29 @@
$("#post_tag_string").trigger("focus");
e.preventDefault();
});
$("#copy-notes").click(function(e) {
var current_post_id = $("meta[name=post-id]").attr("content");
var other_post_id = prompt("Enter the ID of the post to copy all notes to:");
if (other_post_id !== null) {
$.ajax("/posts/" + current_post_id + "/copy_notes", {
type: "PUT",
data: {
other_post_id: other_post_id
},
complete: function(data) {
if (data.status === 200) {
Danbooru.notice("Successfully copied notes to <a href='" + other_post_id + "'>post #" + other_post_id + "</a>");
} else {
Danbooru.error("There was an error copying notes to <a href='" + other_post_id + "'>post #" + other_post_id + "</a>");
}
},
});
}
e.preventDefault();
});
}
Danbooru.Post.initialize_post_relationship_previews = function() {

View File

@@ -1,5 +1,6 @@
class PostsController < ApplicationController
before_filter :member_only, :except => [:show, :show_seq, :index]
before_filter :builder_only, :only => [:copy_notes]
after_filter :save_recent_tags, :only => [:update]
respond_to :html, :xml, :json
rescue_from PostSets::SearchError, :with => :rescue_exception
@@ -76,6 +77,13 @@ class PostsController < ApplicationController
end
end
def copy_notes
@post = Post.find(params[:id])
@other_post = Post.find(params[:other_post_id].to_i)
@post.copy_notes_to(@other_post)
render :nothing => true
end
private
def tag_query
params[:tags] || (params[:post] && params[:post][:tags])

View File

@@ -174,6 +174,20 @@ class Note < ActiveRecord::Base
save!
end
def copy_to(new_post)
new_note = dup
new_note.post_id = new_post.id
width_ratio = new_post.image_width.to_f / post.image_width
height_ratio = new_post.image_height.to_f / post.image_height
new_note.x = x * width_ratio
new_note.y = y * height_ratio
new_note.width = width * width_ratio
new_note.height = height * height_ratio
new_note.save
end
def self.undo_changes_by_user(user_id)
transaction do
notes = Note.joins(:versions).where(["note_versions.updater_id = ?", user_id]).select("DISTINCT notes.*").all

View File

@@ -900,6 +900,12 @@ class Post < ActiveRecord::Base
def last_noted_at_as_integer
last_noted_at.to_i
end
def copy_notes_to(other_post)
notes.each do |note|
note.copy_to(other_post)
end
end
end
module ApiMethods

View File

@@ -9,6 +9,9 @@
<% else %>
<li><%= link_to "Add note", "#", :id => "translate", :title => "Shortcut is N" %></li>
<% end %>
<% if CurrentUser.is_builder? %>
<li><%= link_to "Copy all notes", "#", :id => "copy-notes" %></li>
<% end %>
<li><%= link_to "Find similar", "http://danbooru.iqdb.org/db-search.php?url=http://#{Danbooru.config.hostname}#{post.preview_file_url}" %></li>
<% if post.is_status_locked? %>

View File

@@ -142,6 +142,7 @@ Danbooru::Application.routes.draw do
resources :votes, :controller => "post_votes", :only => [:create, :destroy]
member do
put :revert
put :copy_notes
get :show_seq
end
end