From 35117e21e14abfd350171567f517837208ac6232 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Mon, 17 Sep 2012 11:58:03 +1200 Subject: [PATCH] Fire current search when switching between basic/advanced --- app/assets/javascripts/search.js.coffee | 10 +++++----- app/views/contacts/index.html.haml | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/search.js.coffee b/app/assets/javascripts/search.js.coffee index ea5b54510a..2c21aa14ff 100755 --- a/app/assets/javascripts/search.js.coffee +++ b/app/assets/javascripts/search.js.coffee @@ -1,5 +1,5 @@ (($) -> - class @Search + class @AdvancedSearch constructor: (@templates = {}) -> add_fields: (button, type, content) -> @@ -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", -> @@ -44,5 +44,5 @@ # Fire change event for existing search form. $("select.predicate").change() - + ) jQuery diff --git a/app/views/contacts/index.html.haml b/app/views/contacts/index.html.haml index 02a4fe28c4..8aec9f2a01 100644 --- a/app/views/contacts/index.html.haml +++ b/app/views/contacts/index.html.haml @@ -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')); });