From e85c6c3250ea902e139c3e38ad7c96efb298cc63 Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 15 Aug 2019 12:51:51 -0500 Subject: [PATCH] artists.js: replace 'check name' code with tag autocomplete. Instead of having custom code check whether the artist name is already in use, just enable autocomplete on the artist name field. This is an easier and more robust way to indicate tag name conflicts. --- app/javascript/src/javascripts/artists.js | 33 ----------------------- app/views/artists/_form.html.erb | 21 +++++---------- 2 files changed, 7 insertions(+), 47 deletions(-) delete mode 100644 app/javascript/src/javascripts/artists.js diff --git a/app/javascript/src/javascripts/artists.js b/app/javascript/src/javascripts/artists.js deleted file mode 100644 index fd5f41336..000000000 --- a/app/javascript/src/javascripts/artists.js +++ /dev/null @@ -1,33 +0,0 @@ -let Artist = {}; - -Artist.initialize_all = function() { - if ($("#c-artists").length) { - Artist.initialize_check_name(); - } -} - -Artist.initialize_check_name = function() { - $("#artist_name").on("keyup.danbooru", function(e) { - if ($("#artist_name").val().length > 0) { - $("#check-name-result").html(""); - - $.getJSON("/artists?search[name]=" + escape($("#artist_name").val()), function(artists) { - if (artists.length === 0) { - $.getJSON("/wiki_pages/" + escape($("#artist_name").val()), function(wiki_pages) { - if (wiki_pages !== null) { - $("#check-name-result").html("A wiki page with this name already exists. You must either move the wiki page or pick another artist name.") - } - }); - } else { - $("#check-name-result").html("An artist with this name already exists.") - } - }); - } - }); -} - -$(document).ready(function() { - Artist.initialize_all(); -}); - -export default Artist diff --git a/app/views/artists/_form.html.erb b/app/views/artists/_form.html.erb index 931ac2d19..c9d8c4376 100644 --- a/app/views/artists/_form.html.erb +++ b/app/views/artists/_form.html.erb @@ -1,19 +1,12 @@ <%= simple_form_for(@artist) do |f| %> -
- - <% if @artist.new_record? %> - <%= text_field "artist", "name" %> - + <% if @artist.new_record? %> + <%= f.input :name, input_html: { data: { autocomplete: "tag" } } %> + <% elsif CurrentUser.user.is_builder? %> + <%= f.input :name, input_html: { data: { autocomplete: "tag" } }, hint: "Change to rename this artist entry and its wiki page" %> + <% else %> +

<%= @artist.name %>

+ <% end %> - <% elsif CurrentUser.user.is_builder? %> - <%= text_field "artist", "name" %> - - Change to rename this artist entry and its wiki page - - <% else %> -

<%= @artist.name %>

- <% end %> -
<%= f.input :other_names_string, label: "Other names", as: :text, hint: 'NEW Separate names with spaces, not commas. Use underscores for spaces inside names.'.html_safe %> <%= f.input :group_name %> <%= f.input :url_string, :label => "URLs", :as => :text, :input_html => {:size => "50x5", :value => params.dig(:artist, :url_string) || @artist.urls.join("\n")}, :hint => "You can prefix a URL with - to mark it as dead." %>