Sha256: c5941aa1cdd00de7fc9537ce860f02fd415dafe27c3cab7107e5164b0593f617

Contents?: true

Size: 1.83 KB

Versions: 2

Compression:

Stored size: 1.83 KB

Contents

$(function() {
  
  // clear search fields and results
  function clearLdapPersonSearchForm() {
    $('#first_name').val('');
    $('#last_name').val('');
    $("#lps-results").empty();
  }
  
  function setHiddenField(link, dataAttribute) {
    var selector = '#' + dataAttribute;
    var value = link.data(dataAttribute);
    
    $(selector).val(value);
  }

  // add hidden fields to from coming from data attribute of link
  function setHiddenFields(link) {
    setHiddenField(link, 'search-field-name');
    setHiddenField(link, 'result-link-http-method');
    setHiddenField(link, 'result-link-text');
    setHiddenField(link, 'result-link-class');
    setHiddenField(link, 'result-link-url');
  }

  function setSearchUrl(link) {
    var url = link.data('search-url');
    var formAction = url == undefined ? '/ucb_rails/ldap_person_search' : url;
    $('form#lps-form').attr('action', formAction);
  }
  
  // open search dialog
  $('.ldap-person-search').click(function() {
    $('#lps-modal').modal('show');
    $('#first_name').focus();
    
    var link = $(this);
    setHiddenFields(link);
    setSearchUrl(link)
  });
    
  // Clear button
  $('#lps-clear').click(function() {
    clearLdapPersonSearchForm();
  }); 

  // modal shown
  $("#lps-modal").on('show', function() {
    //clearLdapPersonSearchForm();
    $("#first_name").focus();
  });
  
  // modal hidden
  $("#lps-modal").on('hide', function() {
    clearLdapPersonSearchForm();
  });
  
  // Default handler for search.  Implementers should specify a result-link-class
  // data attribute on the element that starts the search.
  $(document).on('click', 'a.result-link-default', function (e) {
    var link = $(this);
    alert('Default click handler: ' + link.data('uid'));
    e.preventDefault();
    hideLpsModal();
  });
  
});

function hideLpsModal() {
  $("#lps-modal").modal('hide');
}

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ucb_rails-0.0.3 lib/generators/ucb_rails/templates/app/assets/javascripts/ucb_rails/lps.js
ucb_rails-0.0.2 lib/generators/ucb_rails/templates/app/assets/javascripts/lps.js