add more intelligent js for artist forms

This commit is contained in:
Albert Yi
2016-10-18 14:53:44 -07:00
parent 2424f24fcd
commit 2a5343b8cf
7 changed files with 45 additions and 37 deletions

View File

@@ -3,7 +3,7 @@
Danbooru.Artist.initialize_all = function() {
if ($("#c-artists").length) {
Danbooru.Artist.initialize_check_name_link();
Danbooru.Artist.initialize_check_name();
if (Danbooru.meta("enable-auto-complete") === "true") {
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() {
var $fields = $("#search_name,#quick_search_name");
@@ -45,34 +65,6 @@
$(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();
});
}
})();

View File

@@ -93,7 +93,7 @@
);
var $fields_single = $(
"#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_implication_request_antecedent_name,#tag_implication_request_consequent_name," +
"#tag_alias_antecedent_name,#tag_alias_consequent_name," +