Skip to content

Commit

Permalink
Fire current search when switching between basic/advanced
Browse files Browse the repository at this point in the history
  • Loading branch information
ndbroadbent committed Sep 16, 2012
1 parent 48dd529 commit 35117e2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
10 changes: 5 additions & 5 deletions app/assets/javascripts/search.js.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(($) ->
class @Search
class @AdvancedSearch
constructor: (@templates = {}) ->

add_fields: (button, type, content) ->
Expand All @@ -15,14 +15,14 @@
container.parent().closest('.fields').remove()

$(document).ready ->
search = new Search()
advanced_search = new AdvancedSearch()

$(".add_fields").live "click", ->
search.add_fields this, $(this).data("fieldType"), $(this).data("content")
advanced_search.add_fields this, $(this).data("fieldType"), $(this).data("content")
false

$(".remove_fields").live "click", ->
search.remove_fields this
advanced_search.remove_fields this
false

$("select.predicate").live "change", ->
Expand All @@ -44,5 +44,5 @@

# Fire change event for existing search form.
$("select.predicate").change()

) jQuery
17 changes: 16 additions & 1 deletion app/views/contacts/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,25 @@
var activate_search_form = function(search_form){
// Hide all
jQuery('#search .search_form').hide();
jQuery('#search .tabs li a').removeClass('active');
jQuery('#search .tabs li a').removeClass('active');
// Show selected
jQuery('#' + search_form).show();
jQuery('a[data-search-form=' + search_form + ']').addClass('active');
// Run search for current query
switch(search_form) {
case 'basic_search':
var query_input = jQuery('#basic_search input#query');
if (!query_input.is('.defaultTextActive')) {
var value = query_input.val();
} else {
var value = "";
}
crm.search(value, '#{controller.controller_name}');
break;
case 'advanced_search':
jQuery("#advanced_search form input:submit").click();
break;
}
}

jQuery("#search .tabs a").click(function(){ activate_search_form(jQuery(this).data('search-form')); });

0 comments on commit 35117e2

Please sign in to comment.