fatfreecrm/fat_free_crm

View on GitHub
app/views/shared/_search.html.haml

Summary

Maintainability
Test Coverage
- path = controller.controller_name
- path = "admin/#{path}" if controller.class.to_s.starts_with?("Admin::")

%h4 #{t(:search_assets, t(controller.controller_name + "_small"))}
%div{ style: "margin: 0px 0px 6px 0px" }
  = text_field_tag('query', @current_query, size: 23)

:javascript
  var searchTimeout;

  $('#query').on('keydown', function(event) {
    $el = $(event.target)
    if (searchTimeout) clearTimeout(searchTimeout);
    searchTimeout = setTimeout(function () { crm.search($el.val(), '#{path}'); }, 500);
  });