refactored code related to joining a session (Terms / Join Request dialog display logic) into SessionUtils
This commit is contained in:
parent
072f3101c7
commit
7290188681
|
|
@ -239,7 +239,6 @@
|
|||
renderScheduledSessions(json);
|
||||
});
|
||||
}
|
||||
/******************************************************/
|
||||
|
||||
function beforeShow(data) {
|
||||
context.JK.GenreSelectorHelper.render('#find-session-genre', 'Any Genre');
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
var textMessageDialog = null;
|
||||
var queuedNotification = null;
|
||||
var queuedNotificationCreatedAt = null;
|
||||
var sessionUtils = context.JK.SessionUtils;
|
||||
|
||||
function isNotificationsPanelVisible() {
|
||||
return $contents.is(':visible')
|
||||
|
|
@ -446,22 +447,11 @@
|
|||
context.JK.popExternalLink('/sessions/' + args.session_id);
|
||||
}
|
||||
|
||||
/*********** TODO: THE NEXT 3 FUNCTIONS ARE COPIED FROM sessionList.js. REFACTOR TO COMMON PLACE. *************/
|
||||
function joinSession(args) {
|
||||
// NOTE: invited musicians get their own notification, so no need to check if user has invitation here
|
||||
// like other places because an invited user would never get this notification
|
||||
if (args.musician_access) {
|
||||
if (args.approval_required) {
|
||||
openAlert(args.session_id);
|
||||
}
|
||||
else {
|
||||
openTerms(args);
|
||||
}
|
||||
}
|
||||
sessionUtils.joinSession(args.session_id);
|
||||
deleteNotification(args.notification_id);
|
||||
}
|
||||
|
||||
|
||||
function registerJoinRequestApproved() {
|
||||
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.JOIN_REQUEST_APPROVED, function(header, payload) {
|
||||
logger.debug("Handling JOIN_REQUEST_APPROVED msg " + JSON.stringify(payload));
|
||||
|
|
@ -1173,19 +1163,6 @@
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
function onCreateJoinRequest(sessionId) {
|
||||
var joinRequest = {};
|
||||
joinRequest.music_session = sessionId;
|
||||
joinRequest.user = context.JK.currentUserId;
|
||||
rest.createJoinRequest(joinRequest)
|
||||
.done(function(response) {
|
||||
|
||||
}).error(context.JK.app.ajaxError);
|
||||
|
||||
context.JK.app.layout.closeDialog('alert');
|
||||
}
|
||||
|
||||
function approveJoinRequest(args) {
|
||||
rest.updateJoinRequest(args.join_request_id, true)
|
||||
.done(function(response) {
|
||||
|
|
@ -1193,13 +1170,6 @@
|
|||
}).error(app.ajaxError);
|
||||
}
|
||||
|
||||
function rejectJoinRequest(args) {
|
||||
rest.updateJoinRequest(args.join_request_id, false)
|
||||
.done(function(response) {
|
||||
deleteNotification(args.notification_id);
|
||||
}).error(app.ajaxError);
|
||||
}
|
||||
|
||||
function openTerms(args) {
|
||||
var termsDialog = new context.JK.TermsDialog(app, args, onTermsAccepted);
|
||||
termsDialog.initialize();
|
||||
|
|
@ -1208,17 +1178,14 @@
|
|||
|
||||
function onTermsAccepted(args) {
|
||||
deleteNotification(args.notification_id);
|
||||
context.location = '/client#/session/' + args.session_id;
|
||||
sessionUtils.onJoinSessionTermsAccepted(args.session_id);
|
||||
}
|
||||
|
||||
|
||||
function openAlert(sessionId) {
|
||||
var alertDialog = new context.JK.AlertDialog(context.JK.app, "YES",
|
||||
"You must be approved to join this session. Would you like to send a request to join?",
|
||||
sessionId, onCreateJoinRequest);
|
||||
|
||||
alertDialog.initialize();
|
||||
context.JK.app.layout.showDialog('alert');
|
||||
function rejectJoinRequest(args) {
|
||||
rest.updateJoinRequest(args.join_request_id, false)
|
||||
.done(function(response) {
|
||||
deleteNotification(args.notification_id);
|
||||
}).error(app.ajaxError);
|
||||
}
|
||||
|
||||
function listenToRecording(args) {
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@
|
|||
})
|
||||
})
|
||||
.done(function(){
|
||||
joinClick(session.id);
|
||||
sessionUtils.joinSession(session.id);
|
||||
})
|
||||
|
||||
return false;
|
||||
|
|
@ -376,108 +376,6 @@
|
|||
return context.JK.fillTemplate($notationFileTemplate.html(), notationVals);
|
||||
}
|
||||
|
||||
function joinClick(sessionId) {
|
||||
var hasInvitation = false;
|
||||
var session = null;
|
||||
// we need to do a real-time check of the session in case the settings have
|
||||
// changed while the user was sitting on the Find Session screen
|
||||
rest.getSession(sessionId)
|
||||
.done(function(response) {
|
||||
session = response;
|
||||
if ("invitations" in session) {
|
||||
var invitation;
|
||||
// user has invitations for this session
|
||||
for (var i=0; i < session.invitations.length; i++) {
|
||||
invitation = session.invitations[i];
|
||||
// session contains an invitation for this user
|
||||
if (invitation.receiver_id === JK.currentUserId) {
|
||||
hasInvitation = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (session) {
|
||||
// if user has an invitation, always open terms and allow joining regardless of settings
|
||||
if (hasInvitation) {
|
||||
logger.debug("Found invitation for user " + JK.currentUserId + ", session " + sessionId);
|
||||
openTerms(sessionId);
|
||||
}
|
||||
else {
|
||||
if(session.user_id == JK.currentUserId) {
|
||||
openTerms(sessionId);
|
||||
}
|
||||
else if (session.musician_access) {
|
||||
if (session.approval_required) {
|
||||
openAlert(sessionId);
|
||||
}
|
||||
else {
|
||||
openTerms(sessionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.fail(function(xhr, textStatus, errorMessage) {
|
||||
logger.debug("xhr.status = " + xhr.status);
|
||||
if (xhr.status === 404) {
|
||||
sessionNotJoinableAlert();
|
||||
}
|
||||
else {
|
||||
JK.app.notify(
|
||||
{ title: "Unable to Join Session",
|
||||
text: "There was an unexpected error while attempting to join the session."
|
||||
},
|
||||
null,
|
||||
true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function openAlert(sessionId) {
|
||||
var alertDialog = new context.JK.AlertDialog(app, "YES",
|
||||
"You must be approved to join this session. Would you like to send a request to join?",
|
||||
sessionId, onCreateJoinRequest);
|
||||
|
||||
alertDialog.initialize();
|
||||
app.layout.showDialog('alert');
|
||||
}
|
||||
|
||||
function sessionNotJoinableAlert() {
|
||||
var alertDialog = new context.JK.AlertDialog(app, "OK",
|
||||
"This session is over or is no longer public and cannot be joined. Please click Refresh to update the session list.",
|
||||
null,
|
||||
function(evt) {
|
||||
app.layout.closeDialog('alert');
|
||||
}
|
||||
);
|
||||
|
||||
alertDialog.initialize();
|
||||
app.layout.showDialog('alert');
|
||||
}
|
||||
|
||||
function onCreateJoinRequest(sessionId) {
|
||||
var joinRequest = {};
|
||||
joinRequest.music_session = sessionId;
|
||||
joinRequest.user = context.JK.currentUserId;
|
||||
rest.createJoinRequest(joinRequest)
|
||||
.done(function(response) {
|
||||
|
||||
}).error(app.ajaxError);
|
||||
|
||||
app.layout.closeDialog('alert');
|
||||
}
|
||||
|
||||
function openTerms(sessionId) {
|
||||
var termsDialog = new context.JK.TermsDialog(app, sessionId, onTermsAccepted);
|
||||
termsDialog.initialize();
|
||||
app.layout.showDialog('terms');
|
||||
}
|
||||
|
||||
function onTermsAccepted(sessionId) {
|
||||
context.location = '/client#/session/' + sessionId;
|
||||
}
|
||||
|
||||
this.renderActiveSession = renderActiveSession;
|
||||
this.renderInactiveSession = renderInactiveSession;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,8 +11,6 @@
|
|||
context.JK.SessionUtils = sessionUtils;
|
||||
var logger = context.JK.logger;
|
||||
|
||||
|
||||
|
||||
var LATENCY = sessionUtils.LATENCY = {
|
||||
ME : {description: "ME", style: "latency-me", min: -1, max: -1},
|
||||
GOOD : {description: "GOOD", style: "latency-good", min: 0.0, max: 40.0},
|
||||
|
|
@ -124,6 +122,108 @@
|
|||
}
|
||||
}
|
||||
|
||||
sessionUtils.joinSession = function(sessionId) {
|
||||
var hasInvitation = false;
|
||||
var session = null;
|
||||
// we need to do a real-time check of the session in case the settings have
|
||||
// changed while the user was sitting on the Find Session screen
|
||||
rest.getSession(sessionId)
|
||||
.done(function(response) {
|
||||
session = response;
|
||||
if ("invitations" in session) {
|
||||
var invitation;
|
||||
// user has invitations for this session
|
||||
for (var i=0; i < session.invitations.length; i++) {
|
||||
invitation = session.invitations[i];
|
||||
// session contains an invitation for this user
|
||||
if (invitation.receiver_id === JK.currentUserId) {
|
||||
hasInvitation = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (session) {
|
||||
// if user has an invitation, always open terms and allow joining regardless of settings
|
||||
if (hasInvitation) {
|
||||
logger.debug("Found invitation for user " + JK.currentUserId + ", session " + sessionId);
|
||||
openJoinSessionTerms(sessionId);
|
||||
}
|
||||
else {
|
||||
if(session.user_id == JK.currentUserId) {
|
||||
openJoinSessionTerms(sessionId);
|
||||
}
|
||||
else if (session.musician_access) {
|
||||
if (session.approval_required) {
|
||||
openJoinRequestAlert(sessionId);
|
||||
}
|
||||
else {
|
||||
openJoinSessionTerms(sessionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.fail(function(xhr, textStatus, errorMessage) {
|
||||
logger.debug("xhr.status = " + xhr.status);
|
||||
if (xhr.status === 404) {
|
||||
sessionNotJoinableAlert();
|
||||
}
|
||||
else {
|
||||
context.JK.app.notify(
|
||||
{ title: "Unable to Join Session",
|
||||
text: "There was an unexpected error while attempting to join the session."
|
||||
},
|
||||
null,
|
||||
true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function openJoinRequestAlert(sessionId) {
|
||||
var alertDialog = new context.JK.AlertDialog(JK.app, "YES",
|
||||
"You must be approved to join this session. Would you like to send a request to join?",
|
||||
sessionId, onCreateJoinRequest);
|
||||
|
||||
alertDialog.initialize();
|
||||
context.JK.app.layout.showDialog('alert');
|
||||
}
|
||||
|
||||
function sessionNotJoinableAlert() {
|
||||
var alertDialog = new context.JK.AlertDialog(JK.app, "OK",
|
||||
"This session is over or is no longer public and cannot be joined. Please click Refresh to update the session list.",
|
||||
null,
|
||||
function(evt) {
|
||||
context.JK.app.layout.closeDialog('alert');
|
||||
}
|
||||
);
|
||||
|
||||
alertDialog.initialize();
|
||||
context.JK.app.layout.showDialog('alert');
|
||||
}
|
||||
|
||||
sessionUtils.openJoinSessionTerms = function(sessionId) {
|
||||
var termsDialog = new context.JK.TermsDialog(context.JK.app, sessionId, onJoinSessionTermsAccepted);
|
||||
termsDialog.initialize();
|
||||
context.JK.app.layout.showDialog('terms');
|
||||
}
|
||||
|
||||
sessionUtils.onJoinSessionTermsAccepted = function(sessionId) {
|
||||
context.location = '/client#/session/' + sessionId;
|
||||
}
|
||||
|
||||
function onCreateJoinRequest(sessionId) {
|
||||
var joinRequest = {};
|
||||
joinRequest.music_session = sessionId;
|
||||
joinRequest.user = context.JK.currentUserId;
|
||||
rest.createJoinRequest(joinRequest)
|
||||
.done(function(response) {
|
||||
|
||||
}).error(context.JK.app.ajaxError);
|
||||
|
||||
context.JK.app.layout.closeDialog('alert');
|
||||
}
|
||||
|
||||
sessionUtils.FTUEPageEnter = function() {
|
||||
logger.debug("sessionUtils: FTUEPageEnter");
|
||||
clearAudioTimeout();
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
<script type="text/javascript">
|
||||
var rest = JK.Rest();
|
||||
var logger = JK.logger;
|
||||
var sessionUtils = JK.SessionUtils;
|
||||
|
||||
// function addLike(userId) {
|
||||
// rest.addLike({user_id: userId})
|
||||
|
|
@ -16,107 +17,10 @@
|
|||
// });
|
||||
// }
|
||||
|
||||
/*********** TODO: THE NEXT 6 FUNCTIONS ARE COPIED FROM sessionList.js. REFACTOR TO COMMON PLACE. *************/
|
||||
|
||||
function joinClick(sessionId) {
|
||||
var hasInvitation = false;
|
||||
var session = null;
|
||||
// we need to do a real-time check of the session in case the settings have
|
||||
// changed while the user was sitting on the Find Session screen
|
||||
rest.getSession(sessionId)
|
||||
.done(function(response) {
|
||||
session = response;
|
||||
if ("invitations" in session) {
|
||||
var invitation;
|
||||
// user has invitations for this session
|
||||
for (var i=0; i < session.invitations.length; i++) {
|
||||
invitation = session.invitations[i];
|
||||
// session contains an invitation for this user
|
||||
if (invitation.receiver_id === JK.currentUserId) {
|
||||
hasInvitation = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (session) {
|
||||
// if user has an invitation, always open terms and allow joining regardless of settings
|
||||
if (hasInvitation) {
|
||||
logger.debug("Found invitation for user " + JK.currentUserId + ", session " + sessionId);
|
||||
openTerms(sessionId);
|
||||
}
|
||||
else {
|
||||
if (session.musician_access) {
|
||||
if (session.approval_required) {
|
||||
openAlert(sessionId);
|
||||
}
|
||||
else {
|
||||
openTerms(sessionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.fail(function(xhr, textStatus, errorMessage) {
|
||||
logger.debug("xhr.status = " + xhr.status);
|
||||
if (xhr.status === 404) {
|
||||
sessionNotJoinableAlert();
|
||||
}
|
||||
else {
|
||||
JK.app.notify(
|
||||
{ title: "Unable to Join Session",
|
||||
text: "There was an unexpected error while attempting to join the session."
|
||||
},
|
||||
null,
|
||||
true);
|
||||
}
|
||||
});
|
||||
sessionUtils.joinSession(sessionId);
|
||||
}
|
||||
|
||||
function openAlert(sessionId) {
|
||||
var alertDialog = new JK.AlertDialog(JK.app, "YES",
|
||||
"You must be approved to join this session. Would you like to send a request to join?",
|
||||
sessionId, onCreateJoinRequest);
|
||||
|
||||
alertDialog.initialize();
|
||||
JK.app.layout.showDialog('alert');
|
||||
}
|
||||
|
||||
function sessionNotJoinableAlert() {
|
||||
var alertDialog = new JK.AlertDialog(JK.app, "OK",
|
||||
"This session is over or is no longer public and cannot be joined. Please click Refresh to update the session list.",
|
||||
null,
|
||||
function(evt) {
|
||||
JK.app.layout.closeDialog('alert');
|
||||
}
|
||||
);
|
||||
|
||||
alertDialog.initialize();
|
||||
JK.app.layout.showDialog('alert');
|
||||
}
|
||||
|
||||
function onCreateJoinRequest(sessionId) {
|
||||
var joinRequest = {};
|
||||
joinRequest.music_session = sessionId;
|
||||
joinRequest.user = JK.currentUserId;
|
||||
rest.createJoinRequest(joinRequest)
|
||||
.done(function(response) {
|
||||
|
||||
}).error(JK.app.ajaxError);
|
||||
|
||||
JK.app.layout.closeDialog('alert');
|
||||
}
|
||||
|
||||
function openTerms(sessionId) {
|
||||
var termsDialog = new JK.TermsDialog(JK.app, sessionId, onTermsAccepted);
|
||||
termsDialog.initialize();
|
||||
JK.app.layout.showDialog('terms');
|
||||
}
|
||||
|
||||
function onTermsAccepted(sessionId) {
|
||||
window.location = '/client#/session/' + sessionId;
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function addMusicianFollowing(userId) {
|
||||
rest.addFollowing({user_id: userId})
|
||||
.done(function(response) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue