diff --git a/app/views/people/index.html.haml b/app/views/people/index.html.haml index 456df1b54..1c98153c3 100644 --- a/app/views/people/index.html.haml +++ b/app/views/people/index.html.haml @@ -8,9 +8,6 @@ - content_for :head do = include_javascripts :people = javascript_include_tag 'contact-list' - - if @background_query.present? - :javascript - $(document).ready(function() { List.startSearchDelay('#{@background_query}') } ); .span-24.last = search_header @@ -22,7 +19,14 @@ #people_stream.stream - if @hashes.empty? - if @background_query.present? - %p + + / this is gross, and should be extracted! + :javascript + $(document).ready( function() { + List.startSearchDelay('#{@background_query}') + } ); + + %p = t('.searching') = image_tag '/images/static-loader.png', :class => 'loader' - else diff --git a/public/javascripts/contact-list.js b/public/javascripts/contact-list.js index 9321dc4b0..2a5e0d684 100644 --- a/public/javascripts/contact-list.js +++ b/public/javascripts/contact-list.js @@ -20,6 +20,7 @@ var List = { }); }); }, + disconnectUser: function(contact_id){ $.ajax({ url: "/contacts/" + contact_id, @@ -33,44 +34,48 @@ var List = { } }); }, + runDelayedSearch: function( searchTerm ) { - $.ajax({ - dataType: 'json', - url: '/people/refresh_search', - data: { q: searchTerm }, - success: List.handleSearchRefresh - }); + $.getJSON('/people/refresh_search', + { q: searchTerm }, + List.handleSearchRefresh + ); }, + handleSearchRefresh: function( data ) { - if ( data.search_count > 0 ) { - $("#people_stream.stream").html( data.search_html ); - } else { - $("#people_stream.stream").html( "

" + Diaspora.I18n.t("people.not_found") + "

" ); - } + var streamEl = $("#people_stream.stream"); + var string = data.search_html || $("

", { + text : Diaspora.I18n.t("people.not_found") + }); + + streamEl.html(string); }, - startSearchDelay: function ( theSearch ) { + + startSearchDelay: function (theSearch) { setTimeout( "List.runDelayedSearch('" + theSearch + "')", 10000); } }; $(document).ready(function() { - $('.added').live('ajax:loading', function() { - $(this).addClass('disabled'); - $(this).fadeTo(200,0.4); + $('.added').bind('ajax:loading', function() { + var $this = $(this); + + $this.addClass('disabled'); + $this.fadeTo(200,0.4); }); - $('.add').live('ajax:loading', function() { - $(this).addClass('disabled'); - $(this).fadeTo(200,0.4); - }); + $('.added').bind('hover', + function() { + var $this = $(this) + $this.addClass("remove"); + $this.children("img").attr("src","/images/icons/monotone_close_exit_delete.png"); + }, - $('.added').live('mouseover', function() { - $(this).addClass("remove"); - $(this).children("img").attr("src","/images/icons/monotone_close_exit_delete.png"); - }).live('mouseout', function() { - $(this).removeClass("remove"); - $(this).children("img").attr("src","/images/icons/monotone_check_yes.png"); + function() { + var $this = $(this) + $this.removeClass("remove"); + $this.children("img").attr("src","/images/icons/monotone_check_yes.png"); }); List.initialize(); diff --git a/spec/controllers/jasmine_fixtures/people_spec.rb b/spec/controllers/jasmine_fixtures/people_spec.rb index 8216656ff..25d227ac9 100644 --- a/spec/controllers/jasmine_fixtures/people_spec.rb +++ b/spec/controllers/jasmine_fixtures/people_spec.rb @@ -14,6 +14,7 @@ describe PeopleController do get :index save_fixture(html_for("body"), "empty_people_search") end + it "generates a jasmine fixture trying an external search", :fixture => true do get :index, :q => "sample@diaspor.us" save_fixture(html_for("body"), "pending_external_people_search") diff --git a/spec/javascripts/search-spec.js b/spec/javascripts/search-spec.js index 062d12814..7b30a320a 100644 --- a/spec/javascripts/search-spec.js +++ b/spec/javascripts/search-spec.js @@ -1,14 +1,12 @@ /* Copyright (c) 2010-2011, Diaspora Inc. This file is -* licensed under the Affero General Public License version 3 or later. See -* the COPYRIGHT file. -*/ + * licensed under the Affero General Public License version 3 or later. See + * the COPYRIGHT file. + */ describe("List", function() { - describe("runDelayedSearch", function() { - it('gets called on initialize', function(){ - spyOn( List, 'startSearchDelay'); + spyOn(List, 'startSearchDelay'); spec.loadFixture('pending_external_people_search'); expect(List.startSearchDelay).toHaveBeenCalled(); }); @@ -22,7 +20,7 @@ describe("List", function() { it('inserts contact html', function(){ List.handleSearchRefresh( { count:1, search_html: "

hello
" } ); - expect($(".testing_insert_div").text().toEqual( "hello" )); + expect($(".testing_insert_div").text()).toEqual("hello"); }); }); });