From 02c0a0f1c6978090ad7ea38bd50f1de68483a1d8 Mon Sep 17 00:00:00 2001 From: albert Date: Sat, 22 Oct 2011 01:56:36 -0400 Subject: [PATCH] post mode menu fixes --- app/assets/javascripts/post_mode_menu.js | 8 ++++-- app/assets/javascripts/posts.js | 2 +- app/assets/javascripts/tag_script.js | 25 ++++++++++--------- app/controllers/posts_controller.rb | 2 +- app/models/forum_topic.rb | 2 +- app/models/post.rb | 23 +++++++++++++++++ app/models/user.rb | 2 +- app/views/posts/partials/index/_edit.html.erb | 1 + 8 files changed, 47 insertions(+), 18 deletions(-) diff --git a/app/assets/javascripts/post_mode_menu.js b/app/assets/javascripts/post_mode_menu.js index 5467c0f73..7abc314df 100644 --- a/app/assets/javascripts/post_mode_menu.js +++ b/app/assets/javascripts/post_mode_menu.js @@ -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(); } } diff --git a/app/assets/javascripts/posts.js b/app/assets/javascripts/posts.js index 9d1d2731d..b5548888e 100644 --- a/app/assets/javascripts/posts.js +++ b/app/assets/javascripts/posts.js @@ -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); } }); } diff --git a/app/assets/javascripts/tag_script.js b/app/assets/javascripts/tag_script.js index 7efe2be24..c782d5349 100644 --- a/app/assets/javascripts/tag_script.js +++ b/app/assets/javascripts/tag_script.js @@ -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")}); } })(); diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 5a1738046..d77f77a67 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -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 diff --git a/app/models/forum_topic.rb b/app/models/forum_topic.rb index 9a181e72f..1767f0f35 100644 --- a/app/models/forum_topic.rb +++ b/app/models/forum_topic.rb @@ -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 diff --git a/app/models/post.rb b/app/models/post.rb index 41b446ce9..443859ea2 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index bfa7e2fdb..2b96a69d2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/views/posts/partials/index/_edit.html.erb b/app/views/posts/partials/index/_edit.html.erb index 9a5606aa2..b4ee8c051 100644 --- a/app/views/posts/partials/index/_edit.html.erb +++ b/app/views/posts/partials/index/_edit.html.erb @@ -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 %> \ No newline at end of file