adding an ajax loader, and pull out the js from the middle of the view

This commit is contained in:
Maxwell Salzberg 2012-03-13 17:10:23 -07:00
parent 2a30e60fe0
commit b8b6557379
3 changed files with 18 additions and 9 deletions

View file

@ -34,9 +34,11 @@ class PeopleController < ApplicationController
#only do it if it is an email address #only do it if it is an email address
if diaspora_id?(search_query) if diaspora_id?(search_query)
@people = Person.where(:diaspora_handle => search_query.downcase) @people = Person.where(:diaspora_handle => search_query.downcase)
Webfinger.in_background(search_query) if @people.empty? if @people.empty?
Webfinger.in_background(search_query)
@background_query = search_query.downcase @background_query = search_query.downcase
end end
end
@people = @people.paginate(:page => params[:page], :per_page => 15) @people = @people.paginate(:page => params[:page], :per_page => 15)
@hashes = hashes_for_people(@people, @aspects) @hashes = hashes_for_people(@people, @aspects)
end end

View file

@ -8,6 +8,9 @@
- content_for :head do - content_for :head do
= include_javascripts :people = include_javascripts :people
= javascript_include_tag 'contact-list' = javascript_include_tag 'contact-list'
- if @background_query.present?
:javascript
$(document).ready(function() { List.startSearchDelay('#{@background_query}') } );
.span-24.last .span-24.last
= search_header = search_header
@ -20,12 +23,11 @@
- if @hashes.empty? - if @hashes.empty?
- if @background_query.present? - if @background_query.present?
%p %p
=t('.searching') = t('.searching')
:javascript = image_tag '/images/static-loader.png', :class => 'loader'
$(document).ready(function() { List.startSearchDelay('#{@background_query}') } );
- else - else
%p %p
=t('.no_one_found') = t('.no_one_found')
- else - else
- for hash in @hashes - for hash in @hashes
= render :partial => 'people/person', :locals => hash = render :partial => 'people/person', :locals => hash

View file

@ -53,9 +53,14 @@ describe PeopleController do
assigns[:people][0].id.should == @unsearchable_eugene.id assigns[:people][0].id.should == @unsearchable_eugene.id
end end
it 'sets the background query task' do it 'does not the background query task if the user is found' do
get :index, :q => "Eugene@Example.ORG" get :index, :q => "Eugene@Example.ORG"
assigns[:background_query].should == "eugene@example.org" assigns[:background_query].should == nil
end
it 'sets background query task if the user is not found' do
get :index, :q => "Eugene@Example1.ORG"
assigns[:background_query].should == "eugene@example1.org"
end end
end end