add more intelligent js for artist forms
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
Danbooru.Artist.initialize_all = function() {
|
Danbooru.Artist.initialize_all = function() {
|
||||||
if ($("#c-artists").length) {
|
if ($("#c-artists").length) {
|
||||||
Danbooru.Artist.initialize_check_name_link();
|
Danbooru.Artist.initialize_check_name();
|
||||||
|
|
||||||
if (Danbooru.meta("enable-auto-complete") === "true") {
|
if (Danbooru.meta("enable-auto-complete") === "true") {
|
||||||
Danbooru.Artist.initialize_autocomplete();
|
Danbooru.Artist.initialize_autocomplete();
|
||||||
@@ -11,6 +11,26 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Danbooru.Artist.initialize_check_name = function() {
|
||||||
|
$("#artist_name").keyup(function(e) {
|
||||||
|
if ($("#artist_name").val().length > 0) {
|
||||||
|
$("#check-name-result").html("");
|
||||||
|
|
||||||
|
$.getJSON("/artists?search[name]=" + escape($("#artist_name").val()), function(data) {
|
||||||
|
if (data.length === 0) {
|
||||||
|
$.getJSON("/wiki_pages/" + escape($("#artist_name").val()), function(data) {
|
||||||
|
if (data !== null) {
|
||||||
|
$("#check-name-result").html("<a href='/wiki_pages/" + escape($("#artist_name").val()) + "'>A wiki page with this name already exists</a>. You must either move the wiki page or pick another artist name.")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$("#check-name-result").html("An artist with this name already exists.")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Danbooru.Artist.initialize_autocomplete = function() {
|
Danbooru.Artist.initialize_autocomplete = function() {
|
||||||
var $fields = $("#search_name,#quick_search_name");
|
var $fields = $("#search_name,#quick_search_name");
|
||||||
|
|
||||||
@@ -45,34 +65,6 @@
|
|||||||
$(field).data("uiAutocomplete")._renderItem = render_artist;
|
$(field).data("uiAutocomplete")._renderItem = render_artist;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Danbooru.Artist.initialize_check_name_link = function() {
|
|
||||||
$("#check-name-link").click(function(e) {
|
|
||||||
var artist_name = $("#artist_name").val();
|
|
||||||
|
|
||||||
if (artist_name.length === 0) {
|
|
||||||
$("#check-name-result").html("OK");
|
|
||||||
}
|
|
||||||
|
|
||||||
$.get("/artists.json?name=" + artist_name,
|
|
||||||
function(artists) {
|
|
||||||
$("check-name-result").empty();
|
|
||||||
|
|
||||||
if (artists.length) {
|
|
||||||
$("#check-name-result").text("Taken: ");
|
|
||||||
|
|
||||||
$.map(artists.slice(0, 5), function (artist) {
|
|
||||||
var link = $("<a>").attr("href", "/artists/" + artist.id).text(artist.name);
|
|
||||||
$("#check-name-result").append(link);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
$("#check-name-result").text("OK");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -93,7 +93,7 @@
|
|||||||
);
|
);
|
||||||
var $fields_single = $(
|
var $fields_single = $(
|
||||||
"#c-tags #search_name_matches,#c-tag-aliases #query,#c-tag-implications #query," +
|
"#c-tags #search_name_matches,#c-tag-aliases #query,#c-tag-implications #query," +
|
||||||
"#wiki_page_title,#artist_name," +
|
"#wiki_page_title," +
|
||||||
"#tag_alias_request_antecedent_name,#tag_alias_request_consequent_name," +
|
"#tag_alias_request_antecedent_name,#tag_alias_request_consequent_name," +
|
||||||
"#tag_implication_request_antecedent_name,#tag_implication_request_consequent_name," +
|
"#tag_implication_request_antecedent_name,#tag_implication_request_consequent_name," +
|
||||||
"#tag_alias_antecedent_name,#tag_alias_consequent_name," +
|
"#tag_alias_antecedent_name,#tag_alias_consequent_name," +
|
||||||
|
|||||||
@@ -29,10 +29,6 @@ div#c-artists, div#excerpt {
|
|||||||
.hint {
|
.hint {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
#check-name-result a {
|
|
||||||
margin-right: 1em;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
div.recent-posts {
|
div.recent-posts {
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class WikiPagesController < ApplicationController
|
|||||||
@wiki_page = WikiPage.find(params[:id])
|
@wiki_page = WikiPage.find(params[:id])
|
||||||
else
|
else
|
||||||
@wiki_page = WikiPage.find_by_title(params[:id])
|
@wiki_page = WikiPage.find_by_title(params[:id])
|
||||||
if @wiki_page.nil?
|
if @wiki_page.nil? && request.format.symbol == :html
|
||||||
redirect_to show_or_new_wiki_pages_path(:title => params[:id])
|
redirect_to show_or_new_wiki_pages_path(:title => params[:id])
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ class Artist < ActiveRecord::Base
|
|||||||
after_save :categorize_tag
|
after_save :categorize_tag
|
||||||
validates_uniqueness_of :name
|
validates_uniqueness_of :name
|
||||||
validate :name_is_valid
|
validate :name_is_valid
|
||||||
|
validate :wiki_is_empty, :on => :create
|
||||||
belongs_to :creator, :class_name => "User"
|
belongs_to :creator, :class_name => "User"
|
||||||
has_many :members, :class_name => "Artist", :foreign_key => "group_name", :primary_key => "name"
|
has_many :members, :class_name => "Artist", :foreign_key => "group_name", :primary_key => "name"
|
||||||
has_many :urls, :dependent => :destroy, :class_name => "ArtistUrl"
|
has_many :urls, :dependent => :destroy, :class_name => "ArtistUrl"
|
||||||
@@ -252,6 +253,13 @@ class Artist < ActiveRecord::Base
|
|||||||
def notes_changed?
|
def notes_changed?
|
||||||
!!@notes_changed
|
!!@notes_changed
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def wiki_is_empty
|
||||||
|
if WikiPage.titled(name).exists?
|
||||||
|
errors.add(:name, "conflicts with a wiki page")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module TagMethods
|
module TagMethods
|
||||||
|
|||||||
@@ -3,13 +3,13 @@
|
|||||||
<label for="artist_name">Name</label>
|
<label for="artist_name">Name</label>
|
||||||
<% if @artist.new_record? %>
|
<% if @artist.new_record? %>
|
||||||
<%= text_field "artist", "name" %>
|
<%= text_field "artist", "name" %>
|
||||||
[<%= link_to "check", "#", :id => "check-name-link" %>]
|
|
||||||
<span id="check-name-result"></span>
|
<span id="check-name-result"></span>
|
||||||
|
|
||||||
<% elsif CurrentUser.user.is_builder? %>
|
<% elsif CurrentUser.user.is_builder? %>
|
||||||
<%= text_field "artist", "name" %>
|
<%= text_field "artist", "name" %>
|
||||||
[<%= link_to "check", "#", :id => "check-name-link" %>]
|
|
||||||
<span id="check-name-result"></span>
|
<span id="check-name-result"></span>
|
||||||
<span class="hint">Change to rename this artist entry and its wiki page</span>
|
<span class="hint">Change to rename this artist entry and its wiki page</span>
|
||||||
|
|
||||||
<% else %>
|
<% else %>
|
||||||
<p><%= @artist.name %></p>
|
<p><%= @artist.name %></p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -101,6 +101,18 @@ class ArtistTest < ActiveSupport::TestCase
|
|||||||
assert_equal(artist.name, artist.wiki_page.title)
|
assert_equal(artist.name, artist.wiki_page.title)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when a wiki page with the same name already exists" do
|
||||||
|
setup do
|
||||||
|
@wiki_page = FactoryGirl.create(:wiki_page, :title => "aaa")
|
||||||
|
@artist = FactoryGirl.build(:artist, :name => "aaa")
|
||||||
|
end
|
||||||
|
|
||||||
|
should "not validate" do
|
||||||
|
@artist.save
|
||||||
|
assert_equal(["Name conflicts with a wiki page"], @artist.errors.full_messages)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
should "update the wiki page when notes are assigned" do
|
should "update the wiki page when notes are assigned" do
|
||||||
artist = FactoryGirl.create(:artist, :name => "aaa", :notes => "testing")
|
artist = FactoryGirl.create(:artist, :name => "aaa", :notes => "testing")
|
||||||
artist.update_attribute(:notes, "kokoko")
|
artist.update_attribute(:notes, "kokoko")
|
||||||
|
|||||||
Reference in New Issue
Block a user