2014-02-10 13:03:29 +00:00
|
|
|
(function(context,$) {
|
|
|
|
|
|
2014-02-13 19:55:55 +00:00
|
|
|
"use strict";
|
|
|
|
|
context.JK = context.JK || {};
|
2014-04-10 06:21:21 +00:00
|
|
|
context.JK.SessionHoverBubble = function(sessionId, x, y) {
|
2014-02-10 13:03:29 +00:00
|
|
|
|
2014-02-13 19:55:55 +00:00
|
|
|
var logger = context.JK.logger;
|
|
|
|
|
var rest = context.JK.Rest();
|
|
|
|
|
var hoverSelector = "#session-hover";
|
2014-02-10 13:03:29 +00:00
|
|
|
|
2014-11-21 06:20:27 +00:00
|
|
|
// assumes users are sorted by
|
|
|
|
|
function deDupUsers(users) {
|
|
|
|
|
var deDupedUsers = [];
|
|
|
|
|
|
|
|
|
|
var u = {};
|
|
|
|
|
|
|
|
|
|
$.each(users, function(index, user) {
|
|
|
|
|
if (index > 0) {
|
|
|
|
|
// new user
|
|
|
|
|
if (users[index-1].user_id !== users[index].user_id) {
|
|
|
|
|
u = {};
|
|
|
|
|
u.instruments = user.instruments;
|
|
|
|
|
u.user = user.user;
|
|
|
|
|
deDupedUsers.push(u);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
u.instruments += "|" + user.instruments;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
u.instruments = user.instruments;
|
|
|
|
|
u.user = user.user;
|
|
|
|
|
deDupedUsers.push(u);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return deDupedUsers;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-03 02:18:30 +00:00
|
|
|
this.showBubble = function($hoverElement) {
|
2014-02-13 19:55:55 +00:00
|
|
|
|
2014-11-17 03:40:21 +00:00
|
|
|
return rest.getSessionHistory(sessionId)
|
2014-02-13 19:55:55 +00:00
|
|
|
.done(function(response) {
|
|
|
|
|
$(hoverSelector).html('');
|
|
|
|
|
|
|
|
|
|
// musicians
|
|
|
|
|
var musicianHtml = '';
|
2014-11-21 06:20:27 +00:00
|
|
|
var deDupedUsers = deDupUsers(response.users);
|
|
|
|
|
|
|
|
|
|
$.each(deDupedUsers, function(index, val) {
|
2014-02-13 19:55:55 +00:00
|
|
|
var instrumentHtml = '';
|
|
|
|
|
|
2014-02-14 01:50:56 +00:00
|
|
|
musicianHtml += '<tr><td width="50"><a href="#" class="avatar-tiny"><img src="' + context.JK.resolveAvatarUrl(val.user.photo_url) + '" /></a></td>';
|
|
|
|
|
musicianHtml += '<td width="75"><a href="#">' + val.user.name + '</a></td>';
|
2014-02-13 19:55:55 +00:00
|
|
|
|
|
|
|
|
instrumentHtml = '<td><div class="nowrap">';
|
2014-02-14 01:50:56 +00:00
|
|
|
var instruments = val.instruments.split("|");
|
2014-11-21 06:20:27 +00:00
|
|
|
var deDupedInstruments = [];
|
|
|
|
|
|
2014-02-14 01:50:56 +00:00
|
|
|
$.each(instruments, function(index, instrument) {
|
2014-11-21 06:20:27 +00:00
|
|
|
if ($.inArray(instrument, deDupedInstruments) === -1) {
|
|
|
|
|
deDupedInstruments.push(instrument);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$.each(deDupedInstruments, function(index, instrument) {
|
2014-11-15 18:00:13 +00:00
|
|
|
instrumentHtml += '<img src="' + context.JK.getInstrumentIcon24(instrument) + '" title="' + context.JK.getInstrumentId(instrument) + '" width="24" height="24" /> ';
|
2014-02-13 19:55:55 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
instrumentHtml += '</div></td>';
|
|
|
|
|
|
|
|
|
|
musicianHtml += instrumentHtml;
|
|
|
|
|
musicianHtml += '</tr>';
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var template = $('#template-hover-session').html();
|
|
|
|
|
|
2014-06-06 07:04:52 +00:00
|
|
|
var sessionPageUrl = "/sessions/" + response.id;
|
|
|
|
|
var sessionPageLinkText = "WEB PAGE";
|
|
|
|
|
|
|
|
|
|
// if session hasn't begun, it must be a scheduled session so link to SESSION INFO page
|
|
|
|
|
if (!response.active_music_session && !response.session_removed_at) {
|
|
|
|
|
sessionPageUrl += "/details";
|
|
|
|
|
sessionPageLinkText = "SESSION DETAILS";
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-13 19:55:55 +00:00
|
|
|
var sessionHtml = context.JK.fillTemplate(template, {
|
2014-02-14 07:17:36 +00:00
|
|
|
musicSessionId: response.id,
|
2014-06-06 07:04:52 +00:00
|
|
|
name: response.name,
|
2014-02-14 01:50:56 +00:00
|
|
|
description: response.description,
|
2014-06-06 07:04:52 +00:00
|
|
|
genre: response.genre_id.toUpperCase(),
|
2014-02-14 01:50:56 +00:00
|
|
|
comment_count: response.comment_count,
|
|
|
|
|
like_count: response.like_count,
|
2014-04-09 03:52:30 +00:00
|
|
|
created_at: $.timeago(response.created_at),
|
2014-06-06 07:04:52 +00:00
|
|
|
musicians: musicianHtml,
|
|
|
|
|
url: sessionPageUrl,
|
|
|
|
|
externalLinkText: sessionPageLinkText,
|
2014-07-12 02:38:59 +00:00
|
|
|
start_time: response.pretty_scheduled_start_short,
|
2014-06-06 07:04:52 +00:00
|
|
|
recurrence: response.recurring_mode === 'weekly' ? 'Recurs weekly on this day at this time' : ''
|
2014-02-13 19:55:55 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$(hoverSelector).append('<h2>Session Detail</h2>' + sessionHtml);
|
2014-02-24 02:05:31 +00:00
|
|
|
toggleActionButtons();
|
2014-11-03 02:18:30 +00:00
|
|
|
|
|
|
|
|
var css = context.JK.calculateHoverPosition(x, y, $(hoverSelector).width(), $(hoverSelector).height(), $hoverElement);
|
|
|
|
|
|
|
|
|
|
$(hoverSelector).css(css);
|
|
|
|
|
$(hoverSelector).fadeIn(500);
|
2014-02-13 19:55:55 +00:00
|
|
|
})
|
|
|
|
|
.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);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2014-02-24 02:05:31 +00:00
|
|
|
function toggleActionButtons() {
|
|
|
|
|
if (!context.JK.currentUserId) {
|
|
|
|
|
$("#btnLike", hoverSelector).hide();
|
|
|
|
|
$("#btnShare", hoverSelector).hide();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-13 19:55:55 +00:00
|
|
|
this.hideBubble = function() {
|
|
|
|
|
$(hoverSelector).hide();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.id = function() {
|
|
|
|
|
return hoverSelector;
|
|
|
|
|
};
|
|
|
|
|
}
|
2014-02-10 13:03:29 +00:00
|
|
|
})(window,jQuery);
|