diff --git a/app/assets/javascripts/datarepo/submission_form.js b/app/assets/javascripts/datarepo/submission_form.js index ad015e6b9da67dae7e7fbffa4f4438a344fb41bd..de8f0bb30682ac4ff2000406211284e7d597298e 100644 --- a/app/assets/javascripts/datarepo/submission_form.js +++ b/app/assets/javascripts/datarepo/submission_form.js @@ -67,32 +67,51 @@ Blacklight.onLoad(function () { }); - $('#ldap_button_creator').on('click', function () { - $( ".ldap_results_creator" ).load( 'ldap_search?name=' + $( '#ldap_text_creator' ).val() ); - $('.ldap_results_creator').show(); - $('#add_ldap_creator').show(); + function getLdapResults(tag) { + var searchText = $(".ldap-txt." + tag); + var searchButton = $(".ldap-search." + tag); + var resultDiv = $(".ldap-results." + tag); + var addButton = $(".ldap-add." + tag); + var loadingDiv = $(".ldap-loading." + tag); + $(searchButton).hide(); + $(resultDiv).hide(); + $(addButton).hide(); + $(loadingDiv).show(); + var urlName = encodeURI($(searchText).val()); + var ldapURL = 'ldap_search?label='+ tag +'&name=' + urlName; + $(resultDiv).load(ldapURL, function() { + $(loadingDiv).hide(); + $(searchButton).show(); + $(resultDiv).slideDown("fast"); + if ($(resultDiv).find("[type='radio']").length) { + $(addButton).show(); + } + } ); + } + + function addLdapResult(tag) { + var the_value = $(".ldap-results." + tag).find("input[type='radio'][name='" + tag + "_result']:checked").val(); + var count = $(".collection_" + tag + " ul li").length; + $(".collection_" + tag + " ul li:nth-child(" + count + ") input").val(the_value); + $(".ldap-results." + tag).hide(); + $(".ldap-add." + tag).hide(); + } + + $('#ldap-search-creator').on('click', function () { + getLdapResults('creator'); }); - $('#add_ldap_creator').on('click', function() { - var the_value = $('.ldap_results_creator').find("input[type='radio'][name='result']:checked").val(); - var count = $(".collection_creator ul li").length; - $(".collection_creator ul li:nth-child(" + count + ") input").val(the_value) - $('.ldap_results_creator').hide(); - $('#add_ldap_creator').hide(); + $('#ldap-add-creator').on('click', function() { + addLdapResult('creator'); }); - $('#ldap_button_contributor').on('click', function () { - $( ".ldap_results_contributor" ).load( 'ldap_search?name=' + $( '#ldap_text_contributor' ).val() ); - $('.ldap_results_contributor').show(); - $('#add_ldap_contributor').show(); + + $('#ldap-search-contributor').on('click', function () { + getLdapResults('contributor'); }); - $('#add_ldap_contributor').on('click', function() { - var the_value = $('.ldap_results_contributor').find("input[type='radio'][name='result']:checked").val(); - var count = $(".collection_contributor ul li").length; - $(".collection_contributor ul li:nth-child(" + count + ") input").val(the_value) - $('.ldap_results_contributor').hide(); - $('#add_ldap_contributor').hide(); + $('#ldap-add-contributor').on('click', function() { + addLdapResult('contributor'); }); }); diff --git a/app/controllers/collections_controller.rb b/app/controllers/collections_controller.rb index 14cf7593afeba67b9bbbc1b3c11f78aa7cb19edb..d1856e71db23f02f83a61ad277a1b665c25f829e 100644 --- a/app/controllers/collections_controller.rb +++ b/app/controllers/collections_controller.rb @@ -111,6 +111,7 @@ class CollectionsController < ApplicationController name = params[:name].gsub(/\s/,'*') filter = Net::LDAP::Filter.eq("cn", "*#{name}*") @results = ldap.search(base: treebase, filter: filter) + @radio_name = params[:label] render :layout => false end diff --git a/app/views/collections/ldap_search.html.erb b/app/views/collections/ldap_search.html.erb index 5089589bf0580fc2d75721f8fda6d3f9e954632e..1a74c32933049d9b5716039ef0cfd2609e47380f 100644 --- a/app/views/collections/ldap_search.html.erb +++ b/app/views/collections/ldap_search.html.erb @@ -17,9 +17,9 @@ <% @results[0...5].each_with_index do |result, idx| %> <tr> <% if idx == 0 %> - <td><%= radio_button_tag 'result', "#{result[:displayname][0]}", true %></td> + <td><%= radio_button_tag @radio_name+'_result', "#{result[:displayname][0]}", true %></td> <% else %> - <td><%= radio_button_tag 'result', "#{result[:displayname][0]}" %></td> + <td><%= radio_button_tag @radio_name+'_result', "#{result[:displayname][0]}" %></td> <% end %> <td><%= result[:displayname].join(" or ") %></td> <td><%= result[:department].join(" or ") %> </td> diff --git a/app/views/records/edit_fields/_contributor.html.erb b/app/views/records/edit_fields/_contributor.html.erb index 9783e076949240a67e72cf89b6bdd5c74c7446ab..bd90f6bd5135f05375d0e937d469097c6389de64 100644 --- a/app/views/records/edit_fields/_contributor.html.erb +++ b/app/views/records/edit_fields/_contributor.html.erb @@ -1,6 +1,7 @@ <%= f.input key, as: :multi_value, input_html: { class: 'form-control datarepo-autocomplete' }, required: f.object.required?(key) %> -<input id="ldap_text_contributor"> -<input type="button" id="ldap_button_contributor" value="search people"> -<div class="ldap_results_contributor"></div> -<input id="add_ldap_contributor" type="button" value="Add Creator" style="display:none"> +<input class="ldap-txt contributor" id="ldap-txt-contributor"> +<input class="ldap-search contributor" type="button" id="ldap-search-contributor" value="search people"> +<div class="ldap-results contributor"></div> +<input class="ldap-add contributor" type="button" id="ldap-add-contributor" value="Add Contributor" style="display:none"> +<div class="ldap-loading contributor" style="display:none">Loading</div> diff --git a/app/views/records/edit_fields/_creator.html.erb b/app/views/records/edit_fields/_creator.html.erb index 6913e25686814393841b2cb1cd976f5f122809b1..16598f852f7c3f363104f4f0832539e40d744f02 100644 --- a/app/views/records/edit_fields/_creator.html.erb +++ b/app/views/records/edit_fields/_creator.html.erb @@ -1,6 +1,7 @@ <%= f.input key, as: :multi_value, input_html: { class: 'form-control datarepo-autocomplete' }, required: f.object.required?(key) %> -<input id="ldap_text_creator"> -<input type="button" id="ldap_button_creator" value="search people"> -<div class="ldap_results_creator"></div> -<input id="add_ldap_creator" type="button" value="Add Creator" style="display:none"> +<input class="ldap-txt creator" id="ldap-txt-creator"> +<input class="ldap-search creator" type="button" id="ldap-search-creator" value="search people"> +<div class="ldap-results creator"></div> +<input class="ldap-add creator" type="button" id="ldap-add-creator" value="Add creator" style="display:none"> +<div class="ldap-loading creator" style="display:none">Loading</div>