;
}
if (loading || matches) {
// If the autocomplete menu is displayed when position search begins or when
// position search results arrive, make the menu go away:
$(this.refs.input.getDOMNode()).blur();
}
return (
{spinner}
{posPopup}
);
}
}); // PositionSearch
PositionPopup = React.createClass({
// Helper component: when there are multiple matches from position/search,
// display them in a popup box with links for the user to choose a position.
mixins: [PathUpdate, ImmutableUpdate],
// update(path + 'hidePosPopup') called when user clicks to hide popup
// update(path + 'positionMatch', matches): user clicks position link in popup
// (matches obj is from hgFind)
propTypes: { positionMatches: pt.object.isRequired, // Immutable.Map: multiple search results
},
makePosMatchLink: function(matches, i) {
// Display a search result; if for a specific position, make a URL to choose that pos.
var position = matches.get('position');
var description = matches.get('description');
description = description ? ' - ' + description : null;
var posName = matches.get('posName');
var posLabel = posName;
if (position) {
// Wrap posName with a link to select this position
var update = this.props.update;
var path = this.props.path.concat('positionMatch');
var onClick = function(e) {
update(path, matches);
e.preventDefault();
e.stopPropagation();
};
posLabel =
{posName}{' at ' + position}
;
}
return (
{posLabel} {description}
);
},
makePosPopupSection: function(trackMatches, i) {
// Make a section for results from one track.
return (
{trackMatches.get('description')}
{trackMatches.get('matches').map(this.makePosMatchLink).toJS()}
);
},
render: function() {
// Display position matches if necessary.
return (
{this.props.positionMatches.map(this.makePosPopupSection).toJS()}
);
}
}); // PositionPopup
// Without this, jshint complains that PositionSearch is not used. Module system would help.
PositionSearch = PositionSearch;