Finish autocomplete

This commit is contained in:
Raphael 2011-02-01 11:54:55 -08:00
parent 518642d0d7
commit 7d18e2bcd8
10 changed files with 113 additions and 149 deletions

View file

@ -160,7 +160,7 @@ class Person < ActiveRecord::Base
end end
def as_json(opts={}) def as_json(opts={})
{:id => self.guid, :label => 'giraffes', :name => self.name, :avatar => self.profile.image_url(:thumb_small)} {:id => self.guid, :name => self.name, :avatar => self.profile.image_url(:thumb_small), :url => "/people/#{self.id}"}
end end
protected protected

View file

@ -1,50 +0,0 @@
#content
%h1= @person.name
#content_inner
#i.entity_profile.vcard.author
%h2 User profile
%dl.entity_nickname
%dt Nickname
%dd
%a.nickname.url.uid{:href=>@person.url, :rel=>'me'}= @person.name
%dl.entity_given_name
%dt First name
%dd
%span.given_name= @person.profile.first_name
%dl.entity_family_name
%dt Family name
%dd
%span.family_name= @person.profile.last_name
%dl.entity_fn
%dt Full name
%dd
%span.fn= @person.name
%dl.entity_url
%dt URL
%dd
%a#pod_location.url{:href=>@person.url, :rel=>'me'}= @person.url
%dl.entity_photo
%dt Photo
%dd
%img.photo.avatar{:src=>image_or_default(@person), :width=>'300px', :height=>'300px'}
%dl.entity_photo_medium
%dt Photo
%dd
%img.photo.avatar{:src=>image_or_default(@person, :thumb_medium), :width=>'100px', :height=>'100px'}
%dl.entity_photo_small
%dt Photo
%dd
%img.photo.avatar{:src=>image_or_default(@person, :thumb_small), :width=>'50px', :height=>'50px'}
%dl.entity_searchable
%dt Searchable
%dd
%span.searchable= @person.profile.searchable

View file

@ -11,11 +11,11 @@ javascripts:
- public/javascripts/vendor/jquery.hotkeys.js - public/javascripts/vendor/jquery.hotkeys.js
- public/javascripts/vendor/jquery.autoresize.min.js - public/javascripts/vendor/jquery.autoresize.min.js
- public/javascripts/vendor/jquery.infinitescroll.min.js - public/javascripts/vendor/jquery.infinitescroll.min.js
- public/javascripts/vendor/jquery.autocomplete.js
- public/javascripts/vendor/facebox.js - public/javascripts/vendor/facebox.js
- public/javascripts/vendor/timeago.js - public/javascripts/vendor/timeago.js
- public/javascripts/vendor/fileuploader.js - public/javascripts/vendor/fileuploader.js
- public/javascripts/vendor/Mustache.js - public/javascripts/vendor/Mustache.js
- public/javascripts/jquery.autocomplete-custom.js
- public/javascripts/diaspora.js - public/javascripts/diaspora.js
- public/javascripts/widgets/i18n.js - public/javascripts/widgets/i18n.js
- public/javascripts/widgets/alert.js - public/javascripts/widgets/alert.js

View file

@ -30,5 +30,8 @@ $(document).ready(function() {
$('a').live('tap',function(){ $('a').live('tap',function(){
$(this).addClass('tapped'); $(this).addClass('tapped');
}) })
// autocomplete search box
Search.initialize();
}); });

View file

@ -8,7 +8,7 @@
* http://www.gnu.org/licenses/gpl.html * http://www.gnu.org/licenses/gpl.html
* *
* Revision: $Id: jquery.autocomplete.js 5785 2008-07-12 10:37:33Z joern.zaefferer $ * Revision: $Id: jquery.autocomplete.js 5785 2008-07-12 10:37:33Z joern.zaefferer $
* * Modified by Diaspora
*/ */
;(function($) { ;(function($) {
@ -400,6 +400,7 @@ $.Autocompleter.defaults = {
extraParams: {}, extraParams: {},
selectFirst: true, selectFirst: true,
formatItem: function(row) { return row[0]; }, formatItem: function(row) { return row[0]; },
selectionChanged : function(newItem) {},
formatMatch: null, formatMatch: null,
autoFill: false, autoFill: false,
width: 0, width: 0,
@ -622,6 +623,7 @@ $.Autocompleter.Select = function (options, input, select, config) {
list.scrollTop(offset); list.scrollTop(offset);
} }
} }
options.selectionChanged(activeItem);
}; };
function movePosition(step) { function movePosition(step) {

View file

@ -1,27 +1,51 @@
var Search = { var Search = {
source : '/people.json',
selector : '#global_search input#q',
formatItem: function(row){ formatItem: function(row){
return "<img src='"+"images/user/default.png"+"' class='avatar'/>" + row['name']; if(row['search']) {
return 'Search for ' + row['name'];
} else {
return "<img src='"+ row['avatar'] +"' class='avatar'/>" + row['name'];
}
}, },
formatResult: function(row){ formatResult: function(row){
return row['name']; return row['name'];
}, },
parse : function(data) { parse : function(data) {
return data.map(function(person){ results = data.map(function(person){
return {data : person, value : person['name']} return {data : person, value : person['name']}
}); });
results.push(Search.searchLinkli());
return results;
},
selectItemCallback : function(event, data, formatted) {
$(Search.selector).val(formatted);
window.location = data['url'];
},
options : function(){return {
minChars : 3,
max : 4,
formatItem : Search.formatItem,
formatResult : Search.formatResult,
parse : Search.parse,
};},
searchLinkli : function() {
var searchTerm = $(Search.selector).val();
return {
data : {
'search' : true,
'url' : '/people?q=' + searchTerm,
'name' : searchTerm
},
value : searchTerm
};
},
initialize : function() {
$(Search.selector).autocomplete(Search.source, Search.options());
$(Search.selector).result(Search.selectItemCallback);
} }
} }
$(document).ready(function() {
$('#global_search input').autocomplete('/people.json',
{
minChars : 3,
max : 8,
autoFill : true,
formatItem : Search.formatItem,
formatResult : Search.formatResult,
parse : Search.parse
});
});
//$(":text, textarea").result(findValueCallback).next().click(function() { $(this).prev().search(); });

File diff suppressed because one or more lines are too long

View file

@ -35,7 +35,7 @@ describe ApplicationHelper do
person_image_link(nil).should == "" person_image_link(nil).should == ""
end end
it "returns a link containing the person's photo" do it "returns a link containing the person's photo" do
person_image_link(@person).should include(image_or_default(@person)) person_image_link(@person).should include(@person.profile.image_url)
end end
it "returns a link to the person's profile" do it "returns a link to the person's profile" do
person_image_link(@person).should include(person_path(@person)) person_image_link(@person).should include(person_path(@person))

View file

@ -314,7 +314,7 @@ describe DataConversion::ImportToMysql do
profile = Profile.where(:mongo_id => "4d2b6eb6cc8cb43cc2000001").first profile = Profile.where(:mongo_id => "4d2b6eb6cc8cb43cc2000001").first
profile.image_url_medium.should be_nil profile.image_url_medium.should be_nil
profile.searchable.should == true profile.searchable.should == true
profile.image_url.should be_nil profile[:image_url].should be_nil
profile.gender.should be_nil profile.gender.should be_nil
profile.diaspora_handle.should == profile.person.diaspora_handle profile.diaspora_handle.should == profile.person.diaspora_handle
profile.last_name.should == 'weinstien' profile.last_name.should == 'weinstien'

View file

@ -91,7 +91,7 @@ describe Photo do
@user.profile.image_url = @photo.url(:thumb_large) @user.profile.image_url = @photo.url(:thumb_large)
@user.person.save @user.person.save
@photo.destroy @photo.destroy
Person.find(@user.person.id).profile.image_url.should be_nil Person.find(@user.person.id).profile[:image_url].should be_nil
end end
it 'should not use the imported filename as the url' do it 'should not use the imported filename as the url' do