Sha256: 5ac9afe7e4ce88d33b1b634bb07dea7063d807a8f7776b369e67c20da422b3e0

Contents?: true

Size: 1.66 KB

Versions: 13

Compression:

Stored size: 1.66 KB

Contents

$(function() {
  
  // prevent browser autocomplete from competing with Bootstrap typeahead
  $('.typeahead-lps-search').attr('autocomplete', 'off');
  
  // typing in search field clears uid field
  $('.typeahead-lps-search').keyup(function() {
    var uidSelector = '#' + $(this).data('uid-dom-id');
    $(uidSelector).val('');
  });
  
  // default handler for ldap search result link when used with typeahead
  $(document).on('click', 'a.lps-typeahead-item', function (e) {
    var link = $(this);
    var searchFieldSelector = '#' + link.parents('.modal').find('form input#search-field-name').val();
    var searchField = $(searchFieldSelector);
    var uidSelector = '#' + searchField.data('uid-dom-id');
    $(uidSelector).val(link.data('uid'));
    $(searchFieldSelector).val(link.data('first-name') + ' ' + link.data('last-name'));
    e.preventDefault();
    hideLpsModal();
  });
  
  // set up typeahead callbacks
  $('.typeahead-lps-search').typeahead({
    source: function(query, process) {
      return $.ajax({
        url: $(this)[0].$element[0].dataset.url,
        type: 'get',
        data: {query: query},
        dataType: 'json',

        success: function(uid_name_json) {
          names = [];
          map = {};

          $.each(uid_name_json, function (i, person) {
            map[person.first_last_name] = person;
            names.push(person.first_last_name);
          });

          process(names);
        }
      });
    },
    updater: function (item) {
      var uidSelector = '#' + $(this)[0].$element[0].dataset.uidDomId;
      $(uidSelector).val(map[item].uid);
      return item;
    },
    matcher: function (item) {
      return true;
    },
  });

})

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ucb_rails-0.0.14 lib/generators/ucb_rails/templates/app/assets/javascripts/ucb_rails/lps_typeahead.js
ucb_rails-0.0.13 lib/generators/ucb_rails/templates/app/assets/javascripts/ucb_rails/lps_typeahead.js
ucb_rails-0.0.12 lib/generators/ucb_rails/templates/app/assets/javascripts/ucb_rails/lps_typeahead.js
ucb_rails-0.0.11 lib/generators/ucb_rails/templates/app/assets/javascripts/ucb_rails/lps_typeahead.js
ucb_rails-0.0.10 lib/generators/ucb_rails/templates/app/assets/javascripts/ucb_rails/lps_typeahead.js
ucb_rails-0.0.9 lib/generators/ucb_rails/templates/app/assets/javascripts/ucb_rails/lps_typeahead.js
ucb_rails-0.0.8 lib/generators/ucb_rails/templates/app/assets/javascripts/ucb_rails/lps_typeahead.js
ucb_rails-0.0.7 lib/generators/ucb_rails/templates/app/assets/javascripts/ucb_rails/lps_typeahead.js
ucb_rails-0.0.6 lib/generators/ucb_rails/templates/app/assets/javascripts/ucb_rails/lps_typeahead.js
ucb_rails-0.0.5 lib/generators/ucb_rails/templates/app/assets/javascripts/ucb_rails/lps_typeahead.js
ucb_rails-0.0.4 lib/generators/ucb_rails/templates/app/assets/javascripts/ucb_rails/lps_typeahead.js
ucb_rails-0.0.3 lib/generators/ucb_rails/templates/app/assets/javascripts/ucb_rails/lps_typeahead.js
ucb_rails-0.0.2 lib/generators/ucb_rails/templates/app/assets/javascripts/lps_typeahead.js