145 lines
4.3 KiB
JavaScript
145 lines
4.3 KiB
JavaScript
(function(context,$) {
|
|
"use strict";
|
|
|
|
context.JK = context.JK || {};
|
|
context.JK.FindMusicianScreen = function(app) {
|
|
|
|
var logger = context.JK.logger;
|
|
var musicians = {};
|
|
var musicianCounts = [0, 0, 0];
|
|
var musicianList;
|
|
|
|
function removeSpinner() {
|
|
$('<div[layout-id=findMusician] .content .spinner').remove();
|
|
}
|
|
|
|
function addSpinner() {
|
|
removeSpinner();
|
|
$('<div[layout-id=findMusician] .content').append('<div class="spinner spinner-large"></div>')
|
|
}
|
|
|
|
function loadMusicians(queryString) {
|
|
addSpinner();
|
|
|
|
// squelch nulls and undefines
|
|
queryString = !!queryString ? queryString : "";
|
|
|
|
$.ajax({
|
|
type: "GET",
|
|
url: "/api/musicians?" + queryString,
|
|
async: true,
|
|
success: afterLoadMusicians,
|
|
complete: removeSpinner,
|
|
error: app.ajaxError
|
|
});
|
|
}
|
|
|
|
function search() {
|
|
logger.debug("Searching for musicians...");
|
|
clearResults();
|
|
var queryString = '';
|
|
|
|
// instrument filter
|
|
var instruments = context.JK.InstrumentSelectorHelper.getSelectedInstruments('#find-musician-instrument');
|
|
if (instruments !== null && instruments.length > 0) {
|
|
queryString += "instruments=" + instruments.join(',');
|
|
}
|
|
|
|
// keyword filter
|
|
var keyword = $('#musician-keyword-srch').val();
|
|
if (keyword !== null && keyword.length > 0 && keyword !== 'Search by Keyword') {
|
|
if (queryString.length > 0) {
|
|
queryString += "&";
|
|
}
|
|
queryString += "keyword=" + $('#musician-keyword-srch').val();
|
|
}
|
|
loadMusicians(queryString);
|
|
}
|
|
|
|
function refreshDisplay() {
|
|
var priorVisible;
|
|
}
|
|
|
|
function afterLoadMusicians(musicianList) {
|
|
// display the 'no musicians' banner if appropriate
|
|
var $noMusiciansFound = $('#musicians-none-found');
|
|
if(musicianList.length == 0) {
|
|
$noMusiciansFound.show();
|
|
}
|
|
else {
|
|
$noMusiciansFound.hide();
|
|
}
|
|
|
|
startMusicianLatencyChecks(musicianList);
|
|
context.JK.GA.trackFindMusicians(musicianList.length);
|
|
}
|
|
|
|
/**
|
|
* Render a single musician line into the table.
|
|
* It will be inserted at the appropriate place according to the
|
|
* sortScore in musicianLatency.
|
|
*/
|
|
function renderMusician(musicianId) {
|
|
// store musician in the appropriate bucket and increment category counts
|
|
var musician = musicians[musicianId];
|
|
|
|
refreshDisplay();
|
|
}
|
|
|
|
function beforeShow(data) {
|
|
context.JK.InstrumentSelectorHelper.render('#find-musician-instrument');
|
|
}
|
|
|
|
function afterShow(data) {
|
|
clearResults();
|
|
refreshDisplay();
|
|
loadMusicians();
|
|
}
|
|
|
|
function clearResults() {
|
|
musicians = {};
|
|
}
|
|
|
|
function events() {
|
|
$('#musician-keyword-srch').focus(function() {
|
|
$(this).val('');
|
|
});
|
|
|
|
$("#musician-keyword-srch").keypress(function(evt) {
|
|
if (evt.which === 13) {
|
|
evt.preventDefault();
|
|
search();
|
|
}
|
|
});
|
|
$('#btn-refresh').on("click", search);
|
|
}
|
|
|
|
/**
|
|
* Initialize, providing an instance of the MusicianLatency class.
|
|
*/
|
|
function initialize(latency) {
|
|
|
|
var screenBindings = {
|
|
'beforeShow': beforeShow,
|
|
'afterShow': afterShow
|
|
};
|
|
app.bindScreen('findMusician', screenBindings);
|
|
|
|
musicianList = new context.JK.MusicianList(app);
|
|
|
|
events();
|
|
}
|
|
|
|
this.initialize = initialize;
|
|
this.renderMusician = renderMusician;
|
|
this.afterShow = afterShow;
|
|
|
|
// Following exposed for easier testing.
|
|
this.setMusician = setMusician;
|
|
this.clearResults = clearResults;
|
|
this.getCategoryEnum = getCategoryEnum;
|
|
|
|
return this;
|
|
};
|
|
|
|
})(window,jQuery); |