post mode menu fixes

This commit is contained in:
albert
2011-10-22 01:56:36 -04:00
parent 8a5f26f3e5
commit 02c0a0f1c6
8 changed files with 47 additions and 18 deletions

View File

@@ -24,6 +24,10 @@
Danbooru.PostModeMenu.initialize_edit_form = function() {
$("#quick-edit-div").hide();
$("#quick-edit-form input[value=Cancel]").click(function(e) {
$("#quick-edit-div").hide();
e.preventDefault();
});
$("#quick-edit-form").submit(function(e) {
$.ajax({
@@ -56,13 +60,13 @@
script = prompt("Enter a tag script", script);
if (script) {
Cookie.put("tag-script", script);
Danbooru.Cookie.put("tag-script", script);
$("#mode-box select").val("apply-tag-script");
} else {
$("#mode-box select").val("view");
}
this.change();
Danbooru.PostModeMenu.change();
}
}

View File

@@ -168,7 +168,7 @@
Danbooru.Post.update_data(data);
},
error: function(data, status, xhr) {
Danbooru.j_alert("Error: " + data.reason);
Danbooru.notice("Error: " + data.reason);
}
});
}

View File

@@ -11,11 +11,11 @@
$.each(split_pred, function(i, x) {
if (x[0] === "-") {
if (tags.include(x.substr(1, 100))) {
if ($.inArray(x.substr(1, 100), tags)) {
is_true = false;
}
} else {
if (!tags.include(x)) {
if (!$.inArray(x, tags)) {
is_true = false;
}
}
@@ -27,8 +27,8 @@
Danbooru.TagScript.process = function(tags, command) {
if (command.match(/^\[if/)) {
var match = command.match(/\[if\s+(.+?)\s*,\s*(.+?)\]/)
if (this.test(tags, match[1])) {
return this.process(tags, match[2]);
if (Danbooru.TagScript.test(tags, match[1])) {
return Danbooru.TagScript.process(tags, match[2]);
} else {
return tags;
}
@@ -37,20 +37,21 @@
} else if (command[0] === "-") {
return Danbooru.reject(tags, function(x) {return x === command.substr(1, 100)});
} else {
tags.push(command)
tags.push(command);
return tags;
}
}
Danbooru.TagScript.run = function(post_id, tag_script) {
var commands = this.parse(tag_script);
var post = $("#p_" + post_id);
var old_tags = post.data("tags");
var commands = Danbooru.TagScript.parse(tag_script);
var $post = $("#post_" + post_id);
var old_tags = $post.data("tags");
$.each(commands, function(i, x) {
post.data("tags", Danbooru.TagScript.process(post.data("tags"), x));
})
var array = $post.data("tags").match(/\S+/g);
$post.data("tags", Danbooru.TagScript.process(array, x).join(" "));
});
Danbooru.Post.update(post_id, {"post[old_tags]": old_tags, "post[tags]": post.data("tags")});
Danbooru.Post.update(post_id, {"post[old_tag_string]": old_tags, "post[tag_string]": $post.data("tags")});
}
})();

View File

@@ -18,7 +18,7 @@ class PostsController < ApplicationController
def update
@post = Post.find(params[:id])
@post.update_attributes(params[:post])
@post.update_attributes(params[:post], :as => CurrentUser.role)
respond_with(@post) do |format|
format.json do
render :json => @post.to_json

View File

@@ -1,6 +1,6 @@
class ForumTopic < ActiveRecord::Base
attr_accessible :title, :original_post_attributes
attr_accessible :is_sticky, :is_locked, :as => :janitor
attr_accessible :title, :original_post_attributes, :is_sticky, :is_locked, :as => [:admin, :moderator, :janitor]
belongs_to :creator, :class_name => "User"
belongs_to :updater, :class_name => "User"
has_many :posts, :class_name => "ForumPost", :order => "forum_posts.id asc", :foreign_key => "topic_id", :dependent => :destroy

View File

@@ -31,6 +31,7 @@ class Post < ActiveRecord::Base
validates_presence_of :parent, :if => lambda {|rec| !rec.parent_id.nil?}
validate :validate_parent_does_not_have_a_parent
attr_accessible :source, :rating, :tag_string, :old_tag_string, :last_noted_at
attr_accessible :source, :rating, :tag_string, :old_tag_string, :last_noted_at, :is_rating_locked, :is_note_locked, :as => [:admin, :moderator, :janitor]
scope :pending, where(["is_pending = ?", true])
scope :pending_or_flagged, where(["(is_pending = ? OR is_flagged = ?)", true, true])
scope :undeleted, where(["is_deleted = ?", false])
@@ -973,6 +974,27 @@ class Post < ActiveRecord::Base
end
end
module ApiMethods
def hidden_attributes
super + [:tag_index]
end
def serializable_hash(options = {})
options ||= {}
options[:except] ||= []
options[:except] += hidden_attributes
super(options)
end
def to_xml(options = {}, &block)
# to_xml ignores the serializable_hash method
options ||= {}
options[:except] ||= []
options[:except] += hidden_attributes
super(options, &block)
end
end
include FileMethods
include ImageMethods
include ApprovalMethods
@@ -989,6 +1011,7 @@ class Post < ActiveRecord::Base
include DeletionMethods
include VersionMethods
include NoteMethods
include ApiMethods
def reload(options = nil)
super

View File

@@ -15,7 +15,7 @@ class User < ActiveRecord::Base
attr_accessor :password, :old_password
attr_accessible :password, :old_password, :password_confirmation, :password_hash, :email, :last_logged_in_at, :last_forum_read_at, :has_mail, :receive_email_notifications, :comment_threshold, :always_resize_images, :favorite_tags, :blacklisted_tags, :name, :ip_addr, :time_zone, :default_image_size
attr_accessible :level, :as => :admin
attr_accessible :password, :old_password, :password_confirmation, :password_hash, :email, :last_logged_in_at, :last_forum_read_at, :has_mail, :receive_email_notifications, :comment_threshold, :always_resize_images, :favorite_tags, :blacklisted_tags, :name, :ip_addr, :time_zone, :default_image_size, :level, :as => :admin
validates_length_of :name, :within => 2..100, :on => :create
validates_format_of :name, :with => /\A[^\s:]+\Z/, :on => :create, :message => "cannot have whitespace or colons"
validates_uniqueness_of :name, :case_sensitive => false, :on => :create

View File

@@ -4,5 +4,6 @@
<%= form_tag("/posts", :class => "simple_form", :method => :put, :id => "quick-edit-form") do %>
<%= text_area_tag "post[tag_string]", "" %>
<%= submit_tag "Submit" %>
<%= submit_tag "Cancel" %>
<% end %>
</div>