@@ -324,13 +324,18 @@
|
|||||||
data: {
|
data: {
|
||||||
other_post_id: other_post_id
|
other_post_id: other_post_id
|
||||||
},
|
},
|
||||||
complete: function(data) {
|
success: function(data) {
|
||||||
if (data.status === 200) {
|
Danbooru.notice("Successfully copied notes to <a href='" + other_post_id + "'>post #" + other_post_id + "</a>");
|
||||||
Danbooru.notice("Successfully copied notes to <a href='" + other_post_id + "'>post #" + other_post_id + "</a>");
|
},
|
||||||
|
error: function(data) {
|
||||||
|
if (data.status === 404) {
|
||||||
|
Danbooru.error("Error: Invalid destination post");
|
||||||
|
} else if (data.responseJSON && data.responseJSON.reason) {
|
||||||
|
Danbooru.error("Error: " + data.responseJSON.reason);
|
||||||
} else {
|
} else {
|
||||||
Danbooru.error("There was an error copying notes to <a href='" + other_post_id + "'>post #" + other_post_id + "</a>");
|
Danbooru.error("There was an error copying notes to <a href='" + other_post_id + "'>post #" + other_post_id + "</a>");
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -88,7 +88,13 @@ class PostsController < ApplicationController
|
|||||||
@post = Post.find(params[:id])
|
@post = Post.find(params[:id])
|
||||||
@other_post = Post.find(params[:other_post_id].to_i)
|
@other_post = Post.find(params[:other_post_id].to_i)
|
||||||
@post.copy_notes_to(@other_post)
|
@post.copy_notes_to(@other_post)
|
||||||
render :nothing => true
|
|
||||||
|
if @post.errors.any?
|
||||||
|
@error_message = @post.errors.full_messages.join("; ")
|
||||||
|
render :json => {:success => false, :reason => @error_message}.to_json, :status => 400
|
||||||
|
else
|
||||||
|
head :no_content
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def unvote
|
def unvote
|
||||||
|
|||||||
@@ -977,7 +977,14 @@ class Post < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def copy_notes_to(other_post)
|
def copy_notes_to(other_post)
|
||||||
return if notes.active.length == 0
|
if id == other_post.id
|
||||||
|
errors.add :base, "Source and destination posts are the same"
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
unless has_notes?
|
||||||
|
errors.add :post, "has no notes"
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
notes.active.each do |note|
|
notes.active.each do |note|
|
||||||
note.copy_to(other_post)
|
note.copy_to(other_post)
|
||||||
|
|||||||
Reference in New Issue
Block a user