(function(context,$) {
"use strict";
context.JK = context.JK || {};
context.JK.SessionHoverBubble = function(sessionId, position) {
var logger = context.JK.logger;
var rest = context.JK.Rest();
var instrumentLogoMap = context.JK.getInstrumentIconMap24();
var hoverSelector = "#session-hover";
this.showBubble = function() {
$(hoverSelector).css({left: position.left-100, top: position.top+10});
$(hoverSelector).fadeIn(500);
rest.getSessionHistory(sessionId)
.done(function(response) {
$(hoverSelector).html('');
// musicians
var musicianHtml = '';
$.each(response.users, function(index, val) {
var instrumentHtml = '';
musicianHtml += '
 + ') | ';
musicianHtml += '' + val.user.name + ' | ';
instrumentHtml = '';
var instruments = val.instruments.split("|");
$.each(instruments, function(index, instrument) {
instrumentHtml += '  ';
});
instrumentHtml += ' | ';
musicianHtml += instrumentHtml;
musicianHtml += '
';
});
var template = $('#template-hover-session').html();
var sessionHtml = context.JK.fillTemplate(template, {
musicSessionId: response.id,
description: response.description,
genre: response.genres.toUpperCase(),
comment_count: response.comment_count,
like_count: response.like_count,
created_at: context.JK.formatDateTime(response.created_at),
musicians: musicianHtml
});
$(hoverSelector).append('Session Detail
' + sessionHtml);
})
.fail(function(xhr) {
if(xhr.status >= 500) {
context.JK.fetchUserNetworkOrServerFailure();
}
else if(xhr.status == 404) {
context.JK.entityNotFound("Session");
}
else {
context.JK.app.ajaxError(arguments);
}
});
};
this.hideBubble = function() {
$(hoverSelector).hide();
};
this.id = function() {
return hoverSelector;
};
}
})(window,jQuery);