2011-01-14 15:15:32 +00:00
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
// This file extends and proxies the default behavior defined in vitro/webapp/web/js/menupage/browseByVClass.js
// Saving the original getIndividuals function from browseByVClass
var getPersonIndividuals = browseByVClass . getIndividuals ;
// Assigning the proxy function
2011-01-31 04:04:23 +00:00
browseByVClass . getIndividuals = function ( vclassUri , alpha , page , scroll ) {
2011-07-15 19:07:57 +00:00
var url = this . dataServiceUrl + encodeURIComponent ( vclassUri ) ;
2011-01-14 15:15:32 +00:00
if ( alpha && alpha != "all" ) {
url = url + '&alpha=' + alpha ;
}
2011-01-26 14:33:13 +00:00
if ( page ) {
url += '&page=' + page ;
} else {
page = 1 ;
}
2011-01-31 04:04:23 +00:00
if ( typeof scroll === "undefined" ) {
scroll = true ;
}
2011-01-14 15:15:32 +00:00
2011-02-03 13:55:06 +00:00
// Scroll to #menupage-intro page unless told otherwise
if ( scroll != false ) {
// only scroll back up if we're past the top of the #browse-by section
2011-07-15 19:07:57 +00:00
var scrollPosition = browseByVClass . getPageScroll ( ) ;
var browseByOffset = $ ( '#browse-by' ) . offset ( ) ;
2011-02-03 13:55:06 +00:00
if ( scrollPosition [ 1 ] > browseByOffset . top ) {
$ . scrollTo ( '#menupage-intro' , 500 ) ;
}
}
2011-01-14 15:15:32 +00:00
$ . getJSON ( url , function ( results ) {
2011-07-06 21:56:05 +00:00
var individualList = "" ;
2011-02-03 03:06:45 +00:00
2011-02-03 22:32:01 +00:00
// Catch exceptions when empty individuals result set is returned
// This is very likely to happen now since we don't have individual counts for each letter and always allow the result set to be filtered by any letter
2011-11-28 17:46:32 +00:00
if ( ! results . individuals || results . individuals . length == 0 ) {
2011-02-03 22:32:01 +00:00
browseByVClass . emptyResultSet ( results . vclass , alpha )
} else {
2011-07-15 19:07:57 +00:00
var vclassName = results . vclass . name ;
2011-02-03 22:32:01 +00:00
$ . each ( results . individuals , function ( i , item ) {
2011-07-06 21:56:05 +00:00
var individual ,
label ,
firstName ,
lastName ,
fullName ,
2011-07-15 19:07:57 +00:00
mostSpecificTypes ,
2011-07-06 21:56:05 +00:00
preferredTitle ,
2011-07-15 19:07:57 +00:00
moreInfo ,
2011-07-06 21:56:05 +00:00
uri ,
profileUrl ,
image ,
listItem ;
individual = results . individuals [ i ] ;
label = individual . label ;
firstName = individual . firstName ;
lastName = individual . lastName ;
2011-02-03 22:32:01 +00:00
if ( firstName && lastName ) {
fullName = firstName + ' ' + lastName ;
} else {
fullName = label ;
}
2011-07-15 19:07:57 +00:00
mostSpecificTypes = individual . mostSpecificTypes ;
2011-07-06 21:56:05 +00:00
if ( individual . preferredTitle ) {
preferredTitle = individual . preferredTitle ;
2011-07-15 19:07:57 +00:00
moreInfo = browseByVClass . getMoreInfo ( mostSpecificTypes , vclassName , preferredTitle ) ;
} else {
moreInfo = browseByVClass . getMoreInfo ( mostSpecificTypes , vclassName ) ;
2011-02-03 22:32:01 +00:00
}
2011-07-06 21:56:05 +00:00
uri = individual . URI ;
profileUrl = individual . profileUrl ;
if ( ! individual . thumbUrl ) {
2011-02-03 22:32:01 +00:00
image = browseByVClass . baseUrl + '/images/placeholders/person.thumbnail.jpg' ;
} else {
2011-07-06 21:56:05 +00:00
image = browseByVClass . baseUrl + individual . thumbUrl ;
2011-02-03 22:32:01 +00:00
}
// Build the content of each list item, piecing together each component
listItem = '<li class="vcard individual foaf-person" role="listitem" role="navigation">' ;
2011-02-11 16:02:15 +00:00
listItem += '<img src="' + image + '" width="90" alt="' + fullName + '" />' ;
2011-02-03 22:32:01 +00:00
listItem += '<h1 class="fn thumb"><a href="' + profileUrl + '" title="View the profile page for ' + fullName + '">' + fullName + '</a></h1>' ;
2011-07-15 19:07:57 +00:00
if ( moreInfo != '' ) {
listItem += '<span class="title">' + moreInfo + '</span>' ;
2011-02-03 22:32:01 +00:00
}
listItem += '</li>' ;
individualList += listItem ;
} )
// Remove existing content
browseByVClass . wipeSlate ( ) ;
// And then add the new content
browseByVClass . individualsInVClass . append ( individualList ) ;
// Check to see if we're dealing with pagination
if ( results . pages . length ) {
2011-07-15 19:07:57 +00:00
var pages = results . pages ;
2011-02-03 22:32:01 +00:00
browseByVClass . pagination ( pages , page ) ;
2011-01-14 15:15:32 +00:00
}
2011-02-03 22:32:01 +00:00
2011-02-03 13:55:06 +00:00
}
2011-06-29 14:46:01 +00:00
// Set selected class, alpha and page
// Do this whether or not there are any results
$ ( 'h3.selected-class' ) . text ( results . vclass . name ) ;
browseByVClass . selectedVClass ( results . vclass . URI ) ;
browseByVClass . selectedAlpha ( alpha ) ;
2011-01-14 15:15:32 +00:00
} ) ;
} ;