From c62b8ee46e75ca065b4c8993eb291ba6349df2c4 Mon Sep 17 00:00:00 2001 From: albert Date: Sat, 23 Feb 2013 12:36:45 -0500 Subject: [PATCH] fixes #547 --- app/assets/javascripts/artists.js | 30 +++++++++++++++++++++++++++ app/controllers/artists_controller.rb | 2 +- app/views/artists/_form.html.erb | 7 ++++++- 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 app/assets/javascripts/artists.js diff --git a/app/assets/javascripts/artists.js b/app/assets/javascripts/artists.js new file mode 100644 index 000000000..d6b1c4723 --- /dev/null +++ b/app/assets/javascripts/artists.js @@ -0,0 +1,30 @@ +(function() { + Danbooru.Artist = {}; + + Danbooru.Artist.initialize_all = function() { + if ($("#c-artists").length) { + Danbooru.Artist.initialize_check_name_link(); + } + } + + Danbooru.Artist.initialize_check_name_link = function() { + $("#check-name-link").click(function(e) { + var artist_name = $("#artist_name").val(); + $.get("/artists.json?name=" + artist_name, + function(data) { + if (data.length) { + $("#check-name-result").html("Taken") + } else { + $("#check-name-result").html("OK") + } + } + ); + e.preventDefault(); + }); + } +})(); + + +$(document).ready(function() { + Danbooru.Artist.initialize_all(); +}); diff --git a/app/controllers/artists_controller.rb b/app/controllers/artists_controller.rb index c66e3ea71..b485515d5 100644 --- a/app/controllers/artists_controller.rb +++ b/app/controllers/artists_controller.rb @@ -25,7 +25,7 @@ class ArtistsController < ApplicationController end def index - @artists = Artist.search(params[:search]).order("id desc").paginate(params[:page]) + @artists = Artist.search(params[:search] || params).order("id desc").paginate(params[:page]) respond_with(@artists) do |format| format.xml do render :xml => @artists.to_xml(:include => [:urls]) diff --git a/app/views/artists/_form.html.erb b/app/views/artists/_form.html.erb index f8c6a81c2..3e3ff1c7f 100644 --- a/app/views/artists/_form.html.erb +++ b/app/views/artists/_form.html.erb @@ -1,5 +1,10 @@ <%= simple_form_for(@artist) do |f| %> - <%= f.input :name %> +
+ + <%= text_field "artist", "name" %> + [<%= link_to "check", "#", :id => "check-name-link" %>] + +
<%= f.input :other_names_comma, :hint => "Separate with commas", :as => :text, :label => "Other names" %> <%= f.input :group_name %> <%= f.input :url_string, :label => "URLs", :as => :text, :input_html => {:size => "50x5"} %>