2013-01-25 08:00:53 +00:00
( function ( context , $ ) {
2014-03-02 03:19:13 +00:00
"use strict" ;
context . JK = context . JK || { } ;
context . JK . SessionList = function ( app ) {
2014-07-10 20:22:00 +00:00
var EVENTS = context . JK . EVENTS ;
2014-06-25 21:54:31 +00:00
var gearUtils = context . JK . GearUtils ;
2014-08-18 15:37:55 +00:00
var sessionUtils = context . JK . SessionUtils ;
var helpBubble = context . JK . HelpBubbleHelper ;
2014-03-02 03:19:13 +00:00
var logger = context . JK . logger ;
var rest = context . JK . Rest ( ) ;
2014-06-23 04:58:37 +00:00
var ui = new context . JK . UIHelper ( app ) ;
var $activeSessionTemplate = $ ( '#template-active-session-row' ) ;
var $inactiveSessionTemplate = $ ( '#template-inactive-session-row' ) ;
var $notationFileTemplate = $ ( '#template-notation-files' ) ;
var $openSlotsTemplate = $ ( '#template-open-slots' ) ;
var $latencyTemplate = $ ( '#template-latency' ) ;
var $musicianTemplate = $ ( '#template-musician-info' ) ;
var showJoinLink = true ;
2014-12-19 20:00:49 +00:00
var showListenLink = true ;
2015-01-09 08:08:03 +00:00
var MAX _MINUTES _SHOW _START = 15 ;
2014-06-23 04:58:37 +00:00
2014-12-19 20:00:49 +00:00
// related to listen
function stateChange ( e , data ) {
2015-01-01 20:22:42 +00:00
var $listenLink = data . element ;
var $parent = $listenLink . closest ( '.action-links' )
//console.log(e,$(this))
var $listenText = $ ( '.listen-link-text' , $parent ) ;
var $listenDetails = $ ( '.listen-link-details' , $parent ) ;
2014-12-19 20:00:49 +00:00
if ( data . displayText )
{
if ( data . state == 'playing' ) {
$listenText . text ( 'Stop Listening' )
}
else {
$listenText . text ( context . JK . toTitleCase ( data . displayText ) )
$listenDetails . addClass ( 'statusing' )
}
}
if ( data . isEnd ) {
2015-01-02 21:29:31 +00:00
//$listenDetails.removeClass('statusing')
//$listenText.text('Listen')
2015-01-01 02:39:22 +00:00
stopPlay ( $listenLink ) ;
2014-12-19 20:00:49 +00:00
}
2014-06-23 04:58:37 +00:00
2014-12-19 20:00:49 +00:00
if ( data . isSessionOver ) {
$listenLink . removeClass ( 'inprogress' ) . addClass ( 'ended' )
}
}
function startPlay ( $listenLink ) {
$listenLink . find ( 'img' ) . attr ( 'src' , '/assets/content/pause-icon.jpg' ) ;
$listenLink . trigger ( 'play.listenBroadcast' ) ;
}
function stopPlay ( $listenLink ) {
$listenLink . find ( 'img' ) . attr ( 'src' , '/assets/content/listen-icon.jpg' ) ;
$listenLink . trigger ( 'pause.listenBroadcast' ) ;
}
function togglePlay ( ) {
var $listenLink = $ ( this )
2015-01-01 02:39:22 +00:00
var $parent = $listenLink . closest ( '.action-links' ) ;
var $listenText = $ ( '.listen-link-text' , $parent ) ;
var $listenDetails = $ ( '.listen-link-details' , $parent ) ;
2020-03-26 20:12:49 +00:00
if ( true ) {
context . JK . Banner . showAlert ( 'Disabled Due to High Demand' , 'JamKazam has been under very high demand recently.<br/><br/>This feature is disabled while we scale up the backend servers and technology.' )
2014-12-19 20:00:49 +00:00
}
else {
2020-03-26 20:12:49 +00:00
if ( $listenLink . data ( 'listenbroadcast-playstate' ) == 'playing' ) {
$listenText . text ( 'Listen' )
$listenDetails . removeClass ( 'statusing' )
stopPlay ( $listenLink ) ;
}
else {
startPlay ( $listenLink ) ;
}
2014-12-19 20:00:49 +00:00
}
return false ;
}
function renderActiveSession ( session , tbGroup , myAudioLatency ) {
2014-06-23 04:58:37 +00:00
var i = 0 ;
2014-09-17 07:14:43 +00:00
var inSessionUsersHtml = '' , rsvpFirst3UsersHtml = '' , rsvpRemainingUsersHtml = '' , openSlotsFirst3Html = '' , openSlotsRemainingHtml = '' , latencyInSessionHtml = '' , latencyFirst3Html = '' , latencyRemainingHtml = '' , notationFileHtml = '' ;
2014-06-23 04:58:37 +00:00
// this is used to track which users are already in the session so we can exclude them from the
// "RSVPs" section
var inSessionUsers = [ ] ;
2014-06-25 04:30:56 +00:00
showJoinLink = session . musician _access ;
2014-12-19 20:00:49 +00:00
showListenLink = session . fan _access && session . active _music _session && session . active _music _session . mount ;
2014-06-25 04:30:56 +00:00
2014-06-23 04:58:37 +00:00
// render musicians who are already in the session
2014-06-27 05:53:33 +00:00
if ( session . active _music _session && "participants" in session . active _music _session && session . active _music _session . participants . length > 0 ) {
2014-06-23 04:58:37 +00:00
for ( i = 0 ; i < session . active _music _session . participants . length ; i ++ ) {
inSessionUsers . push ( session . active _music _session . participants [ i ] . user . id ) ;
var inSessionUserInfo = createInSessionUser ( session . active _music _session . participants [ i ] ) ;
inSessionUsersHtml += inSessionUserInfo [ 0 ] ;
2014-09-17 07:14:43 +00:00
latencyInSessionHtml += inSessionUserInfo [ 1 ] ;
2014-03-07 20:20:34 +00:00
}
2014-06-23 04:58:37 +00:00
}
2014-06-27 05:53:33 +00:00
// this provides a buffer at the top to shift the first latency tag down in the event there are NO in-session musicians
else {
2014-09-17 07:14:43 +00:00
latencyInSessionHtml += "<div style='height:15px;'> </div>" ;
2014-06-27 05:53:33 +00:00
}
2014-06-23 04:58:37 +00:00
// render users who have approved RSVPs
if ( session . approved _rsvps ) {
2014-09-17 07:14:43 +00:00
var approvedRsvpCount = session . approved _rsvps . length ;
for ( i = 0 ; i < approvedRsvpCount ; i ++ ) {
2014-06-26 02:20:32 +00:00
// do not show the user in this section if he is already in the session
if ( $ . inArray ( session . approved _rsvps [ i ] . id , inSessionUsers ) === - 1 ) {
2014-06-25 04:30:56 +00:00
if ( session . approved _rsvps [ i ] . id === context . JK . currentUserId ) {
showJoinLink = true ;
}
2014-09-17 16:49:58 +00:00
var rsvpUserInfo = createRsvpUser ( session . approved _rsvps [ i ] , session , approvedRsvpCount , i ) ;
2014-09-17 07:14:43 +00:00
if ( i < 3 ) {
rsvpFirst3UsersHtml += rsvpUserInfo [ 0 ] ;
latencyFirst3Html += rsvpUserInfo [ 1 ] ;
}
else {
rsvpRemainingUsersHtml += rsvpUserInfo [ 0 ] ;
latencyRemainingHtml += rsvpUserInfo [ 1 ] ;
}
2014-06-23 04:58:37 +00:00
}
2014-06-26 02:20:32 +00:00
else {
2014-06-26 11:49:49 +00:00
showJoinLink = true ;
2014-06-26 02:20:32 +00:00
}
2014-06-23 04:58:37 +00:00
}
}
2014-03-07 20:20:34 +00:00
2014-07-08 18:34:03 +00:00
// render if anyone interested
if ( session [ 'is_unstructured_rsvp?' ] ) {
2014-09-19 05:12:22 +00:00
openSlotsFirst3Html += sessionUtils . createOpenSlot ( $openSlotsTemplate , { description : 'Any Instrument' } ) ;
2014-07-08 18:34:03 +00:00
}
2014-06-23 04:58:37 +00:00
// render open slots
if ( session . open _slots ) {
2014-09-17 07:14:43 +00:00
var openSlotCount = session . open _slots . length ;
for ( i = 0 ; i < openSlotCount ; i ++ ) {
if ( i < 3 ) {
openSlotsFirst3Html += sessionUtils . createOpenSlot ( $openSlotsTemplate , session . open _slots [ i ] , openSlotCount , i ) ;
}
else {
openSlotsRemainingHtml += sessionUtils . createOpenSlot ( $openSlotsTemplate , session . open _slots [ i ] , openSlotCount , i ) ;
}
2014-06-23 04:58:37 +00:00
}
}
2014-03-02 03:19:13 +00:00
2014-06-25 04:30:56 +00:00
// notation files
if ( session . music _notations ) {
for ( i = 0 ; i < session . music _notations . length ; i ++ ) {
notationFileHtml += createNotationFile ( session . music _notations [ i ] ) ;
}
}
2014-03-02 03:19:13 +00:00
2014-09-25 13:08:01 +00:00
var sessionVals = buildSessionObject ( session , notationFileHtml , rsvpFirst3UsersHtml , rsvpRemainingUsersHtml , openSlotsFirst3Html , openSlotsRemainingHtml , latencyFirst3Html , latencyRemainingHtml , latencyInSessionHtml ) ;
2014-06-23 04:58:37 +00:00
sessionVals . in _session _musicians = inSessionUsersHtml . length > 0 ? inSessionUsersHtml : 'N/A' ;
sessionVals . join _link _display _style = showJoinLink ? "block" : "none" ;
2014-12-19 20:00:49 +00:00
sessionVals . listen _link _display _style = showListenLink ? "inline-block" : "none" ;
2015-01-12 02:43:15 +00:00
if ( ! session . fan _access ) {
sessionVals . listen _link _text = '' ;
}
else if ( session . active _music _session && session . active _music _session . mount ) {
sessionVals . listen _link _text = 'Listen' ;
}
else {
2015-01-12 19:37:50 +00:00
sessionVals . listen _link _text = '' ;
2015-01-12 02:43:15 +00:00
}
2015-01-12 19:37:50 +00:00
2015-01-12 02:43:15 +00:00
2014-06-23 04:58:37 +00:00
2014-08-18 15:37:55 +00:00
var $row = $ ( context . JK . fillTemplate ( $activeSessionTemplate . html ( ) , sessionVals ) ) ;
var $offsetParent = $ ( tbGroup ) . closest ( '.content' ) ;
2014-09-22 19:20:58 +00:00
var $latencyBadges = $row . find ( '.latency-value' ) ;
context . _ . each ( $latencyBadges , function ( latencyBadge ) {
var $latencyBadge = $ ( latencyBadge ) ;
var full _score = $latencyBadge . attr ( 'data-full-score' ) || null ;
var internet _score = $latencyBadge . attr ( 'data-internet-score' ) || null ;
var audio _latency = $latencyBadge . attr ( 'data-audio-latency' ) || null ;
var latencyBadgeUserId = $latencyBadge . attr ( 'data-user-id' ) ;
var scoreOptions = { offsetParent : $offsetParent } ;
helpBubble . scoreBreakdown ( $latencyBadge , context . JK . currentUserId == latencyBadgeUserId , full _score , myAudioLatency , audio _latency , internet _score , scoreOptions ) ;
} ) ;
2014-08-18 15:37:55 +00:00
$ ( tbGroup ) . append ( $row ) ;
2014-06-23 04:58:37 +00:00
2014-09-17 07:14:43 +00:00
var $parentRow = $ ( 'tr[data-session-id=' + session . id + ']' , tbGroup ) ;
2014-09-17 16:49:58 +00:00
// wire up "more" links
$ ( 'a.more.slots' , $parentRow ) . click ( toggleSlots ) ;
2014-09-18 01:32:16 +00:00
$ ( 'a.more.rsvps' , $parentRow ) . click ( toggleRsvps ) ;
2014-09-17 07:14:43 +00:00
2014-10-22 07:01:11 +00:00
$ ( '.notation-link' ) . click ( function ( evt ) {
rest . getMusicNotation ( $ ( this ) . attr ( 'data-notation-id' ) )
. done ( function ( result ) {
window . open ( result , '_blank' ) ;
} )
. fail ( function ( xhr , textStatus , errorMessage ) {
if ( xhr . status === 403 ) {
app . ajaxError ( xhr , textStatus , errorMessage ) ;
}
} ) ;
} ) ;
2014-12-19 20:00:49 +00:00
// enable listen button
if ( showListenLink ) {
var $listenLink = $ ( '.listen-link' , $parentRow )
var $listenText = $ ( '.listen-link-text' , $parentRow )
var $listenDetailHover = $ ( '.listen-detail-hover' , $parentRow )
$listenLink . parent ( ) . hoverIntent ( {
over : function ( ) {
$listenDetailHover . show ( ) ;
} ,
out : function ( ) {
$listenDetailHover . hide ( ) ;
}
} )
$listenLink . attr ( 'data-music-session' , session . id ) . attr ( 'fan-access' , session . fan _access ) . attr ( 'data-audio-src' , session . active _music _session . mount . url ) . attr ( 'data-audio-type' , session . active _music _session . mount . mime _type )
$listenLink . listenBroadcast ( { lazyAudioInit : true , hoverOptions : { offsetParent : $offsetParent } , detailHelper : $listenDetailHover } ) ;
$listenLink . bind ( 'statechange.listenBroadcast' , stateChange ) ;
$listenLink . click ( togglePlay ) ;
}
2014-06-25 04:30:56 +00:00
if ( showJoinLink ) {
2015-02-02 00:14:39 +00:00
// wire up the Join Link to the T&Cs dialog
2014-06-25 04:30:56 +00:00
$ ( '.join-link' , $parentRow ) . click ( function ( evt ) {
2015-02-02 00:14:39 +00:00
sessionUtils . ensureValidClient ( app , gearUtils , function ( ) {
sessionUtils . joinSession ( session . id ) ;
} ) ;
2014-06-25 04:30:56 +00:00
} ) ;
}
2014-06-23 04:58:37 +00:00
}
2014-08-18 15:37:55 +00:00
function renderInactiveSession ( session , tbGroup , $rowToUpdate , myAudioLatency ) {
2014-06-23 04:58:37 +00:00
var openSlots = false ;
var hasInvitation = false ;
2014-07-10 20:22:00 +00:00
var approvedRsvpId = null ; // if set, the user has an accepted RSVP
var pendingRsvpId = null ; // if set, the user has a pending RSVP
2014-06-23 04:58:37 +00:00
var hasPendingOrDeclinedRsvp = false ;
var openRsvps = session . open _rsvps ;
var i = 0 ;
2014-09-17 07:14:43 +00:00
var rsvpFirst3UsersHtml = '' , rsvpRemainingUsersHtml = '' , openSlotsFirst3Html = '' , openSlotsRemainingHtml = '' , latencyFirst3Html = '' , latencyRemainingHtml = '' , notationFileHtml = '' ;
2014-06-23 04:58:37 +00:00
2014-07-10 20:22:00 +00:00
context . _ . each ( session . pending _rsvp _requests , function ( pending _rsvp _request ) {
2014-08-15 04:32:45 +00:00
if ( pending _rsvp _request . user _id === context . JK . currentUserId ) {
2014-07-10 20:22:00 +00:00
pendingRsvpId = pending _rsvp _request . id ;
}
} ) ;
2014-06-23 04:58:37 +00:00
// render users who have approved RSVPs
2014-06-27 05:53:33 +00:00
if ( session . approved _rsvps && session . approved _rsvps . length > 0 ) {
2014-09-17 07:14:43 +00:00
var approvedRsvpCount = session . approved _rsvps . length ;
2014-07-10 20:22:00 +00:00
context . _ . each ( session . approved _rsvps , function ( approved _rsvp ) {
if ( approved _rsvp . id === context . JK . currentUserId ) {
approvedRsvpId = approved _rsvp . rsvp _request _id ;
2014-06-23 04:58:37 +00:00
}
2014-09-17 07:14:43 +00:00
2014-09-17 16:49:58 +00:00
var rsvpUserInfo = createRsvpUser ( approved _rsvp , session , approvedRsvpCount , i ) ;
2014-09-17 07:14:43 +00:00
if ( i < 3 ) {
rsvpFirst3UsersHtml += rsvpUserInfo [ 0 ] ;
latencyFirst3Html += rsvpUserInfo [ 1 ] ;
}
else {
rsvpRemainingUsersHtml += rsvpUserInfo [ 0 ] ;
latencyRemainingHtml += rsvpUserInfo [ 1 ] ;
}
i ++ ;
2014-07-10 20:22:00 +00:00
} ) ;
2014-06-23 04:58:37 +00:00
}
2014-06-27 05:53:33 +00:00
// this provides a buffer at the top to shift the first latency tag down in the event there are NO RSVP musicians
else {
2014-09-17 07:14:43 +00:00
latencyFirst3Html += "<div style='height:15px;'> </div>" ;
2014-06-27 05:53:33 +00:00
}
2013-01-25 08:00:53 +00:00
2014-07-08 18:34:03 +00:00
if ( session [ 'is_unstructured_rsvp?' ] ) {
2014-07-10 20:57:48 +00:00
openSlots = true ; // unstructured RSVP means there are always open slots
2014-09-17 07:14:43 +00:00
openSlotsFirst3Html += sessionUtils . createOpenSlot ( $openSlotsTemplate , { description : 'Any Instrument' } ) ;
2014-07-08 18:34:03 +00:00
}
2014-06-23 04:58:37 +00:00
// render open slots
if ( session . open _slots ) {
2014-09-17 07:14:43 +00:00
var openSlotCount = session . open _slots . length ;
for ( i = 0 ; i < openSlotCount ; i ++ ) {
2014-06-23 04:58:37 +00:00
openSlots = true ;
2014-09-17 07:14:43 +00:00
if ( i < 3 ) {
openSlotsFirst3Html += sessionUtils . createOpenSlot ( $openSlotsTemplate , session . open _slots [ i ] , openSlotCount , i ) ;
}
else {
openSlotsRemainingHtml += sessionUtils . createOpenSlot ( $openSlotsTemplate , session . open _slots [ i ] , openSlotCount , i ) ;
}
2014-06-23 04:58:37 +00:00
}
}
2014-02-19 06:27:18 +00:00
2014-06-23 04:58:37 +00:00
// render pending invitations
if ( session . pending _invitations ) {
for ( i = 0 ; i < session . pending _invitations . length ; i ++ ) {
2014-06-25 04:30:56 +00:00
if ( session . pending _invitations [ i ] . id === context . JK . currentUserId ) {
2014-06-23 04:58:37 +00:00
hasInvitation = true ;
}
2013-01-25 08:00:53 +00:00
}
2014-06-23 04:58:37 +00:00
}
2013-01-25 08:00:53 +00:00
2014-08-15 04:32:45 +00:00
// notation files
if ( session . music _notations ) {
for ( i = 0 ; i < session . music _notations . length ; i ++ ) {
notationFileHtml += createNotationFile ( session . music _notations [ i ] ) ;
}
}
2014-09-17 07:14:43 +00:00
var sessionVals = buildSessionObject ( session , notationFileHtml , rsvpFirst3UsersHtml , rsvpRemainingUsersHtml ,
2014-09-25 13:08:01 +00:00
openSlotsFirst3Html , openSlotsRemainingHtml , latencyFirst3Html , latencyRemainingHtml , '' ) ;
2014-09-17 07:14:43 +00:00
2014-08-15 04:32:45 +00:00
sessionVals . scheduled _start = session . pretty _scheduled _start _with _timezone ;
2014-08-18 15:37:55 +00:00
var $row = $ ( context . JK . fillTemplate ( $inactiveSessionTemplate . html ( ) , sessionVals ) ) ;
var $offsetParent = $ ( tbGroup ) . closest ( '.content' ) ;
2014-09-22 19:20:58 +00:00
var $latencyBadges = $row . find ( '.latency-value' ) ;
context . _ . each ( $latencyBadges , function ( latencyBadge ) {
var $latencyBadge = $ ( latencyBadge ) ;
var full _score = $latencyBadge . attr ( 'data-full-score' ) || null ;
var internet _score = $latencyBadge . attr ( 'data-internet-score' ) || null ;
var audio _latency = $latencyBadge . attr ( 'data-audio-latency' ) || null ;
var latencyBadgeUserId = $latencyBadge . attr ( 'data-user-id' ) ;
var scoreOptions = { offsetParent : $offsetParent } ;
helpBubble . scoreBreakdown ( $latencyBadge , context . JK . currentUserId == latencyBadgeUserId , full _score , myAudioLatency , audio _latency , internet _score , scoreOptions ) ;
} )
2014-08-18 15:37:55 +00:00
2014-08-15 04:32:45 +00:00
// initial page load
if ( ! $rowToUpdate ) {
2014-08-18 15:37:55 +00:00
$ ( tbGroup ) . append ( $row ) ;
2014-08-15 04:32:45 +00:00
}
// inline update after an RSVP submission / cancellation
else {
2014-08-18 15:37:55 +00:00
$rowToUpdate . replaceWith ( $row ) ;
2014-08-15 04:32:45 +00:00
}
var $parentRow = $ ( 'tr[data-session-id=' + session . id + ']' , tbGroup ) ;
2014-09-17 07:14:43 +00:00
// wire up "more" links
$ ( 'a.more.slots' , $parentRow ) . click ( toggleSlots ) ;
2014-09-18 01:32:16 +00:00
$ ( 'a.more.rsvps' , $parentRow ) . click ( toggleRsvps ) ;
2014-09-17 07:14:43 +00:00
2014-07-10 20:22:00 +00:00
var showRsvpLink = true ;
2015-02-02 00:14:39 +00:00
var sessionLinkText = '' ;
2015-01-08 04:18:07 +00:00
$ ( '.rsvp-link-text' , $parentRow ) . hide ( ) ;
2014-07-10 20:22:00 +00:00
2015-01-09 08:08:03 +00:00
function showStartSessionButton ( scheduledStart ) {
var now = new Date ( ) ;
var scheduledDate = new Date ( scheduledStart ) ;
var minutesFromStart = ( scheduledDate . getTime ( ) - now . getTime ( ) ) / ( 1000 * 60 ) ;
2015-01-12 06:20:19 +00:00
return minutesFromStart <= MAX _MINUTES _SHOW _START ;
2015-01-09 08:08:03 +00:00
} ;
2015-01-08 04:18:07 +00:00
if ( session . creator . id === context . JK . currentUserId ) {
2014-06-23 04:58:37 +00:00
showRsvpLink = false ;
2015-02-02 00:14:39 +00:00
sessionLinkText = $ ( '<span class="text"><a class="start" style="color: #fc0">Start session now?</a></span>' ) ;
sessionLinkText . find ( 'a' ) . click ( function ( ) {
2015-01-08 04:18:07 +00:00
ui . launchSessionStartDialog ( session ) ;
return false ;
} ) ;
}
else if ( approvedRsvpId ) {
showRsvpLink = false ;
2015-01-09 07:10:44 +00:00
2015-01-10 20:09:06 +00:00
if ( session . scheduled _start && showStartSessionButton ( session . scheduled _start ) ) {
2015-02-02 00:14:39 +00:00
sessionLinkText = $ ( '<span class="text"><a class="start" style="color: #fc0">Start session now?</a> | <a class="cancel" style="color: #fc0">Cancel RSVP</a></span>' ) ;
sessionLinkText . find ( 'a.start' ) . click ( function ( ) {
2015-01-09 08:08:03 +00:00
ui . launchSessionStartDialog ( session ) ;
return false ;
} ) ;
}
else {
2015-02-02 00:14:39 +00:00
sessionLinkText = $ ( '<span class="text"><a class="cancel" style="color: #fc0">Cancel RSVP</a></span>' ) ;
2015-01-09 08:08:03 +00:00
}
2015-01-09 07:10:44 +00:00
// wire cancel link
2015-02-02 00:14:39 +00:00
sessionLinkText . find ( 'a.cancel' ) . click ( function ( ) {
2014-07-16 05:20:59 +00:00
ui . launchRsvpCancelDialog ( session . id , approvedRsvpId )
2014-07-10 20:22:00 +00:00
. one ( EVENTS . RSVP _CANCELED , function ( ) {
2014-08-15 04:32:45 +00:00
rest . getSessionHistory ( session . id )
. done ( function ( response ) {
2014-08-18 15:37:55 +00:00
renderInactiveSession ( response , tbGroup , $parentRow , myAudioLatency ) ;
2014-08-15 04:32:45 +00:00
} ) ;
2014-07-10 20:22:00 +00:00
} )
. one ( EVENTS . DIALOG _CLOSED , function ( ) {
$ ( this ) . unbind ( EVENTS . RSVP _CANCELED ) ;
} ) ;
2014-07-16 05:20:59 +00:00
return false ;
2014-07-10 20:22:00 +00:00
} ) ;
}
2015-01-09 07:10:44 +00:00
else if ( hasInvitation ) {
showRsvpLink = false ;
2015-01-09 08:08:03 +00:00
2015-01-10 20:09:06 +00:00
if ( session . scheduled _start && showStartSessionButton ( session . scheduled _start ) ) {
2015-02-02 00:14:39 +00:00
sessionLinkText = $ ( '<span class="text"><a class="start" style="color: #fc0">Start session now?</a></span>' ) ;
sessionLinkText . find ( 'a' ) . click ( function ( ) {
2015-01-09 08:08:03 +00:00
ui . launchSessionStartDialog ( session ) ;
return false ;
} ) ;
}
2015-01-09 07:10:44 +00:00
}
2014-07-16 05:20:59 +00:00
else if ( pendingRsvpId ) {
2014-07-10 20:22:00 +00:00
showRsvpLink = false ;
2015-02-02 00:14:39 +00:00
sessionLinkText = $ ( '<span class="text"><a class="cancel" style="color: #fc0">Cancel RSVP</a></span>' ) ;
sessionLinkText . find ( 'a' ) . click ( function ( ) {
2014-07-16 05:20:59 +00:00
ui . launchRsvpCancelDialog ( session . id , pendingRsvpId )
2014-07-10 20:22:00 +00:00
. one ( EVENTS . RSVP _CANCELED , function ( ) {
2014-08-15 04:32:45 +00:00
rest . getSessionHistory ( session . id )
. done ( function ( response ) {
2014-08-18 15:37:55 +00:00
renderInactiveSession ( response , tbGroup , $parentRow , myAudioLatency ) ;
2014-08-15 04:32:45 +00:00
} ) ;
2014-07-10 20:22:00 +00:00
} )
. one ( EVENTS . DIALOG _CLOSED , function ( ) {
$ ( this ) . unbind ( EVENTS . RSVP _CANCELED ) ;
} ) ;
2014-07-16 05:20:59 +00:00
return false ;
2014-07-10 20:22:00 +00:00
} ) ;
2014-06-23 04:58:37 +00:00
}
2014-07-16 05:20:59 +00:00
else if ( ! openSlots ) {
showRsvpLink = false ;
2015-02-02 00:14:39 +00:00
sessionLinkText = '<span class="text">No more openings in this session.</span>' ;
2014-07-10 20:57:48 +00:00
}
else if ( ! openRsvps && ! hasInvitation ) {
showRsvpLink = false ;
2015-02-02 00:14:39 +00:00
sessionLinkText = '<span class="text">You need an invitation to RSVP to this session.</span>' ;
2014-07-10 20:57:48 +00:00
}
2014-07-16 05:20:59 +00:00
2014-06-23 04:58:37 +00:00
if ( showRsvpLink ) {
2014-07-03 04:51:54 +00:00
$ ( '.rsvp-msg' , $parentRow ) . hide ( ) ;
2014-08-15 04:32:45 +00:00
$ ( '.rsvp-link' , $parentRow ) . show ( ) ;
2015-01-08 04:18:07 +00:00
$ ( '.rsvp-link-text' , $parentRow ) . show ( ) ;
2014-07-16 05:20:59 +00:00
2014-06-23 04:58:37 +00:00
$ ( '.rsvp-link' , $parentRow ) . click ( function ( evt ) {
2014-07-16 05:20:59 +00:00
ui . launchRsvpSubmitDialog ( session . id )
. one ( EVENTS . RSVP _SUBMITTED , function ( ) {
rest . getSessionHistory ( session . id )
. done ( function ( response ) {
2014-08-18 15:37:55 +00:00
renderInactiveSession ( response , tbGroup , $parentRow , myAudioLatency ) ;
2014-07-16 05:20:59 +00:00
} ) ;
} )
. one ( EVENTS . DIALOG _CLOSED , function ( ) {
$ ( this ) . unbind ( EVENTS . RSVP _SUBMITTED ) ;
} ) ;
2014-07-10 20:22:00 +00:00
return false ;
2014-03-02 03:19:13 +00:00
} ) ;
2014-06-23 04:58:37 +00:00
}
else {
2015-02-02 00:14:39 +00:00
$ ( '.rsvp-msg' , $parentRow ) . html ( sessionLinkText ) . show ( ) ;
2014-08-15 04:32:45 +00:00
$ ( '.rsvp-link' , $parentRow ) . hide ( ) ;
2014-06-23 04:58:37 +00:00
}
}
2014-09-25 13:08:01 +00:00
function buildSessionObject ( session , notationFileHtml , rsvpFirst3UsersHtml , rsvpRemainingUsersHtml , openSlotsFirst3Html , openSlotsRemainingHtml , latencyFirst3Html , latencyRemainingHtml , latencyInSessionHtml ) {
2014-06-23 04:58:37 +00:00
return {
id : session . id ,
name : session . name ,
description : session . description || "(No description)" ,
notation _files : notationFileHtml . length > 0 ? notationFileHtml : 'N/A' ,
genres : session . genres . join ( ', ' ) ,
2014-09-17 07:14:43 +00:00
rsvp _musicians _first _3 : rsvpFirst3UsersHtml . length > 0 ? rsvpFirst3UsersHtml : 'N/A' ,
rsvp _musicians _remaining : rsvpRemainingUsersHtml . length > 0 ? rsvpRemainingUsersHtml : 'N/A' ,
open _slots _first _3 : openSlotsFirst3Html . length > 0 ? openSlotsFirst3Html : 'No slots available' ,
open _slots _remaining : openSlotsRemainingHtml . length > 0 ? openSlotsRemainingHtml : 'No slots available' ,
latency _first _3 : latencyFirst3Html ,
latency _remaining : latencyRemainingHtml ,
2014-09-25 13:08:01 +00:00
latency _in _session : latencyInSessionHtml ,
2014-06-23 04:58:37 +00:00
language : session . language _description ,
musician _access : session . musician _access _description ,
fan _access : session . fan _access _description ,
legal _policy : session . legal _policy
} ;
}
2013-10-16 07:23:43 +00:00
2014-06-23 04:58:37 +00:00
function createInSessionUser ( participant ) {
var instrumentLogoHtml = '' ;
var j ;
2014-12-28 05:19:25 +00:00
var existingTracks = [ ] ;
2014-06-23 04:58:37 +00:00
// loop through the tracks to get the instruments
for ( j = 0 ; j < participant . tracks . length ; j ++ ) {
var track = participant . tracks [ j ] ;
2014-12-28 05:19:25 +00:00
if ( existingTracks . indexOf ( track . instrument _id ) < 0 ) {
existingTracks . push ( track . instrument _id ) ;
logger . debug ( "Find:Finding instruments. Participant tracks:" , participant . tracks ) ;
var inst = context . JK . getInstrumentIcon24 ( track . instrument _id ) ;
instrumentLogoHtml += '<img title="' + context . JK . getInstrumentId ( track . instrument _id ) + '" hoveraction="instrument" data-instrument-id="' + track . instrument _id + '" src="' + inst + '" width="24" height="24" /> ' ;
}
2014-06-23 04:58:37 +00:00
}
2013-10-16 07:23:43 +00:00
2014-06-23 04:58:37 +00:00
var id = participant . user . id ;
var name = participant . user . name ;
var musicianVals = {
userId : id ,
avatar _url : context . JK . resolveAvatarUrl ( participant . user . photo _url ) ,
profile _url : "/client#/profile/" + id ,
musician _name : name ,
2014-09-25 13:08:01 +00:00
instruments : instrumentLogoHtml ,
more _link : ''
2014-06-23 04:58:37 +00:00
} ;
var musicianHtml = context . JK . fillTemplate ( $musicianTemplate . html ( ) , musicianVals ) ;
2014-08-18 15:37:55 +00:00
var latencyHtml = context . _ . template ( $latencyTemplate . html ( ) , $ . extend ( sessionUtils . createLatency ( participant . user ) , participant . user ) , { variable : 'data' } ) ;
2014-06-23 04:58:37 +00:00
return [ musicianHtml , latencyHtml ] ;
}
2014-09-17 07:14:43 +00:00
function createRsvpUser ( user , session , rsvpCount , currentIndex ) {
2014-06-23 04:58:37 +00:00
var instrumentLogoHtml = '' ;
2014-03-02 03:19:13 +00:00
2014-06-23 04:58:37 +00:00
var j ;
// loop through the tracks to get the instruments
if ( "instrument_list" in user ) {
for ( j = 0 ; j < user . instrument _list . length ; j ++ ) {
var instrument = user . instrument _list [ j ] ;
2014-07-08 18:34:03 +00:00
var inst = context . JK . getInstrumentIcon24 ( instrument . id ) ;
2014-11-15 18:00:13 +00:00
instrumentLogoHtml += '<img title="' + context . JK . getInstrumentId ( instrument . id ) + '" hoveraction="instrument" data-instrument-id="' + instrument . id + '" src="' + inst + '" width="24" height="24" /> ' ;
2014-06-23 04:58:37 +00:00
}
}
2014-04-09 17:25:52 +00:00
2014-09-17 16:49:58 +00:00
var moreLinkHtml = '' ;
if ( rsvpCount > 3 && currentIndex === 2 ) {
moreLinkHtml = '<a class="rsvps more">more</a><a class="details-arrow arrow-down-orange"></a>' ;
}
2014-06-23 04:58:37 +00:00
var id = user . id ;
var name = user . name ;
var musicianVals = {
userId : id ,
avatar _url : context . JK . resolveAvatarUrl ( user . photo _url ) ,
profile _url : "/client#/profile/" + id ,
musician _name : name ,
2014-09-17 16:49:58 +00:00
instruments : instrumentLogoHtml ,
more _link : moreLinkHtml
2014-06-23 04:58:37 +00:00
} ;
2014-03-06 18:17:47 +00:00
2014-06-23 04:58:37 +00:00
var musicianHtml = context . JK . fillTemplate ( $musicianTemplate . html ( ) , musicianVals ) ;
2014-08-18 15:37:55 +00:00
var latencyHtml = context . _ . template ( $latencyTemplate . html ( ) , $ . extend ( sessionUtils . createLatency ( user ) , user ) , { variable : 'data' } ) ;
2014-06-23 04:58:37 +00:00
return [ musicianHtml , latencyHtml ] ;
}
2014-06-25 04:30:56 +00:00
function createNotationFile ( notation ) {
var notationVals = {
2014-09-06 07:30:29 +00:00
notation _id : notation . id ,
2014-10-22 07:01:11 +00:00
file _url : notation . viewable ? notation . file _url + '?target=_blank' : '#' ,
file _name : notation . file _name ,
link _class : notation . viewable ? '' : 'notation-link'
2014-06-25 04:30:56 +00:00
} ;
return context . JK . fillTemplate ( $notationFileTemplate . html ( ) , notationVals ) ;
}
2014-09-17 07:14:43 +00:00
function toggleSlots ( ) {
var $div = $ ( this ) . closest ( 'table' ) . next ( ) ;
var $arrow = $ ( this ) . next ( ) ;
if ( $div . is ( ":visible" ) ) {
$ ( this ) . text ( 'more' ) ;
$arrow . removeClass ( 'arrow-up-orange' ) ;
$arrow . addClass ( 'arrow-down-orange' ) ;
$div . hide ( ) ;
}
else {
$ ( this ) . text ( 'less' ) ;
$arrow . addClass ( 'arrow-up-orange' ) ;
$arrow . removeClass ( 'arrow-down-orange' ) ;
$div . show ( ) ;
}
}
2014-09-18 01:32:16 +00:00
function toggleRsvps ( ) {
var sessionId = $ ( this ) . closest ( 'tr[data-session-id]' ) . attr ( 'data-session-id' ) ;
2014-09-17 16:49:58 +00:00
// musicians
var $musicians = $ ( this ) . closest ( 'table' ) . next ( ) ;
// latency indicators that need expanding / collapsing
var $extraLatencies = $ ( "#latency-extra-" + sessionId ) ;
var $arrow = $ ( this ) . next ( ) ;
if ( $musicians . is ( ":visible" ) ) {
$ ( this ) . text ( 'more' ) ;
$arrow . removeClass ( 'arrow-up-orange' ) ;
$arrow . addClass ( 'arrow-down-orange' ) ;
$musicians . hide ( ) ;
$extraLatencies . hide ( ) ;
}
else {
$ ( this ) . text ( 'less' ) ;
$arrow . addClass ( 'arrow-up-orange' ) ;
$arrow . removeClass ( 'arrow-down-orange' ) ;
$musicians . show ( ) ;
$extraLatencies . show ( ) ;
}
}
2014-06-23 04:58:37 +00:00
this . renderActiveSession = renderActiveSession ;
this . renderInactiveSession = renderInactiveSession ;
2014-03-02 03:19:13 +00:00
return this ;
2014-07-08 18:34:03 +00:00
} } ) ( window , jQuery ) ;