VRFS-1892 refresh only the affected session row when updating RSVPs
This commit is contained in:
parent
34a6843616
commit
7555d8b65a
|
|
@ -3,32 +3,33 @@
|
|||
"use strict";
|
||||
context.JK = context.JK || {};
|
||||
context.JK.RsvpSubmitDialog = function(app, sessionId) {
|
||||
var EVENTS = context.JK.EVENTS;
|
||||
var logger = context.JK.logger;
|
||||
var rest = context.JK.Rest();
|
||||
var $screen = null;
|
||||
var $dialog = null;
|
||||
var dialogId = 'rsvp-submit-dialog';
|
||||
var $btnSubmit = $("#btnSubmitRsvp");
|
||||
|
||||
function beforeShow(data) {
|
||||
$('.error', $screen).hide();
|
||||
$('.error', $dialog).hide();
|
||||
}
|
||||
|
||||
function afterShow(data) {
|
||||
$('.rsvp-instruments', $screen).empty();
|
||||
$('.rsvp-instruments', $dialog).empty();
|
||||
|
||||
rest.getSessionHistory(sessionId)
|
||||
.done(function(response) {
|
||||
if (response) {
|
||||
$('.session-name', $screen).html(response.name);
|
||||
$('.session-name', $dialog).html(response.name);
|
||||
|
||||
$('.scheduled-start', $screen).html(response.pretty_scheduled_start_with_timezone);
|
||||
$('.scheduled-start', $dialog).html(response.pretty_scheduled_start_with_timezone);
|
||||
|
||||
if (response.recurring_mode !== null && response.recurring_mode === 'weekly') {
|
||||
$('.schedule-recurrence', $screen).html("Recurs " + response.recurring_mode + " on this day at this time");
|
||||
$('.schedule-recurrence', $dialog).html("Recurs " + response.recurring_mode + " on this day at this time");
|
||||
}
|
||||
|
||||
if (response['is_unstructured_rsvp?']) {
|
||||
$('.rsvp-instruments', $screen).append('<input type="checkbox" value="unstructured"/>Any Instrument<br/>');
|
||||
$('.rsvp-instruments', $dialog).append('<input type="checkbox" value="unstructured"/>Any Instrument<br/>');
|
||||
}
|
||||
|
||||
if (response.open_slots && response.open_slots.length > 0) {
|
||||
|
|
@ -36,7 +37,7 @@
|
|||
var instrument = val.instrument_id;
|
||||
|
||||
var instrumentTitleCase = context.JK.toTitleCase(instrument);
|
||||
$('.rsvp-instruments', $screen).append('<input type="checkbox" value="' + val.id + '"/>' + instrumentTitleCase + "<br/>");
|
||||
$('.rsvp-instruments', $dialog).append('<input type="checkbox" value="' + val.id + '"/>' + instrumentTitleCase + "<br/>");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -55,20 +56,23 @@
|
|||
$btnSubmit.unbind('click');
|
||||
$btnSubmit.click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var slotIds = [];
|
||||
$("input:checked", '.rsvp-instruments').each(function(index) {
|
||||
slotIds.push($(this).val());
|
||||
});
|
||||
|
||||
if (slotIds.length === 0) {
|
||||
$('.error', $screen).show();
|
||||
$('.error', $dialog).show();
|
||||
return;
|
||||
}
|
||||
|
||||
var error = false;
|
||||
|
||||
// TODO: show spinner??
|
||||
rest.submitRsvpRequest(sessionId, slotIds)
|
||||
.done(function(response) {
|
||||
var comment = $.trim($('.txtComment', $screen).val());
|
||||
var comment = $.trim($('.txtComment', $dialog).val());
|
||||
if (comment.length > 0) {
|
||||
rest.addSessionInfoComment(sessionId, comment)
|
||||
.done(function(response) {
|
||||
|
|
@ -76,20 +80,20 @@
|
|||
})
|
||||
.fail(function(xhr, textStatus, errorMessage) {
|
||||
error = true;
|
||||
$('.error', $screen).html("Unexpected error occurred while saving message (" + xhr.status + ")");
|
||||
$('.error', $screen).show();
|
||||
$('.error', $dialog).html("Unexpected error occurred while saving message (" + xhr.status + ")");
|
||||
$('.error', $dialog).show();
|
||||
});
|
||||
}
|
||||
|
||||
if (!error) {
|
||||
$dialog.triggerHandler(EVENTS.RSVP_SUBMITTED);
|
||||
app.layout.closeDialog(dialogId);
|
||||
$btnSubmit.trigger("rsvpSubmitEvent");
|
||||
}
|
||||
})
|
||||
.fail(function(xhr, textStatus, errorMessage) {
|
||||
var error = JSON.parse(xhr.responseText);
|
||||
$('.error', $screen).html(error.message);
|
||||
$('.error', $screen).show();
|
||||
$('.error', $dialog).html(error.message);
|
||||
$('.error', $dialog).show();
|
||||
});
|
||||
|
||||
return false;
|
||||
|
|
@ -106,7 +110,7 @@
|
|||
|
||||
app.bindDialog(dialogId, dialogBindings);
|
||||
|
||||
$screen = $('[layout-id="' + dialogId + '"]');
|
||||
$dialog = $('[layout-id="' + dialogId + '"]');
|
||||
|
||||
events();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -324,11 +324,6 @@
|
|||
});
|
||||
|
||||
$('#btn-refresh').on("click", search);
|
||||
|
||||
// this event is raised by the RSVP submit dialog after submitting an RSVP request
|
||||
$(document).on("rsvpSubmitEvent", function() {
|
||||
$('#btn-refresh').trigger('click');
|
||||
});
|
||||
}
|
||||
|
||||
function initialize() {
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
DIALOG_CLOSED : 'dialog_closed',
|
||||
SHOW_SIGNUP : 'show_signup',
|
||||
SHOW_SIGNIN : 'show_signin',
|
||||
RSVP_SUBMITTED: 'rsvp_submitted',
|
||||
RSVP_CANCELED : 'rsvp_canceled'
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
function renderInactiveSession(session, tbGroup) {
|
||||
function renderInactiveSession(session, tbGroup, $rowToUpdate) {
|
||||
|
||||
var openSlots = false;
|
||||
var hasInvitation = false;
|
||||
|
|
@ -188,40 +188,36 @@
|
|||
var showRsvpLink = true;
|
||||
var noLinkText = '';
|
||||
|
||||
if(approvedRsvpId) {
|
||||
if (approvedRsvpId) {
|
||||
showRsvpLink = false;
|
||||
noLinkText = $('<span class="text">You have been confirmed for this session. <a href="#">Cancel</a></span>');
|
||||
noLinkText.find('a').click(function() {
|
||||
var rsvpCancelDlg = new context.JK.RsvpCancelDialog(app, session.id, approvedRsvpId);
|
||||
rsvpCancelDlg.initialize();
|
||||
app.layout.showDialog('rsvp-cancel-dialog')
|
||||
ui.launchRsvpCancelDialog(session.id, approvedRsvpId)
|
||||
.one(EVENTS.RSVP_CANCELED, function() {
|
||||
// VRFS-1891
|
||||
})
|
||||
.one(EVENTS.DIALOG_CLOSED, function() {
|
||||
$(this).unbind(EVENTS.RSVP_CANCELED);
|
||||
});
|
||||
return false;
|
||||
return false;
|
||||
});
|
||||
}
|
||||
else if(pendingRsvpId) {
|
||||
else if (pendingRsvpId) {
|
||||
showRsvpLink = false;
|
||||
noLinkText = $('<span class="text">You have RSVP\'ed to this session. <a href="#">Cancel</a></span>');
|
||||
noLinkText.find('a').click(function() {
|
||||
var rsvpCancelDlg = new context.JK.RsvpCancelDialog(app, session.id, pendingRsvpId);
|
||||
rsvpCancelDlg.initialize();
|
||||
app.layout.showDialog('rsvp-cancel-dialog')
|
||||
ui.launchRsvpCancelDialog(session.id, pendingRsvpId)
|
||||
.one(EVENTS.RSVP_CANCELED, function() {
|
||||
// VRFS-1891
|
||||
})
|
||||
.one(EVENTS.DIALOG_CLOSED, function() {
|
||||
$(this).unbind(EVENTS.RSVP_CANCELED);
|
||||
});
|
||||
return false;
|
||||
return false;
|
||||
});
|
||||
}
|
||||
else if(!openSlots) {
|
||||
showRsvpLink = false
|
||||
else if (!openSlots) {
|
||||
showRsvpLink = false;
|
||||
noLinkText = '<span class="text">No more openings in this session.</span>';
|
||||
}
|
||||
else if (!openRsvps && !hasInvitation) {
|
||||
|
|
@ -229,8 +225,6 @@
|
|||
noLinkText = '<span class="text">You need an invitation to RSVP to this session.</span>';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// notation files
|
||||
if (session.music_notations) {
|
||||
for (i=0; i < session.music_notations.length; i++) {
|
||||
|
|
@ -239,19 +233,38 @@
|
|||
}
|
||||
|
||||
var sessionVals = buildSessionObject(session, notationFileHtml, rsvpUsersHtml, openSlotsHtml, latencyHtml);
|
||||
|
||||
sessionVals.scheduled_start = session.pretty_scheduled_start_with_timezone;
|
||||
|
||||
sessionVals.rsvp_link_display_style = showRsvpLink ? "block" : "none";
|
||||
|
||||
var row = context.JK.fillTemplate($inactiveSessionTemplate.html(), sessionVals);
|
||||
$(tbGroup).append(row);
|
||||
|
||||
// initial page load
|
||||
if (!$rowToUpdate) {
|
||||
$(tbGroup).append(row);
|
||||
}
|
||||
// inline update after an RSVP submission / cancellation
|
||||
else {
|
||||
$rowToUpdate.replaceWith(row);
|
||||
}
|
||||
|
||||
var $parentRow = $('tr[data-session-id=' + session.id + ']', tbGroup);
|
||||
|
||||
if (showRsvpLink) {
|
||||
|
||||
$('.rsvp-msg', $parentRow).hide();
|
||||
var $parentRow = $('tr[data-session-id=' + session.id + ']', tbGroup);
|
||||
|
||||
$('.rsvp-link', $parentRow).click(function(evt) {
|
||||
ui.launchRsvpSubmitDialog(session.id);
|
||||
ui.launchRsvpSubmitDialog(session.id)
|
||||
.one(EVENTS.RSVP_SUBMITTED, function() {
|
||||
rest.getSessionHistory(session.id)
|
||||
.done(function(response) {
|
||||
renderInactiveSession(response, tbGroup, $parentRow);
|
||||
});
|
||||
})
|
||||
.one(EVENTS.DIALOG_CLOSED, function() {
|
||||
$(this).unbind(EVENTS.RSVP_SUBMITTED);
|
||||
});
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -201,11 +201,11 @@
|
|||
|
||||
addLatencyDetails();
|
||||
|
||||
$(document).on("rsvpSubmitEvent", function() {
|
||||
$(document).on(EVENTS.RSVP_SUBMITTED, function() {
|
||||
location.reload();
|
||||
});
|
||||
|
||||
$(document).on("rsvpCancelEvent", function() {
|
||||
$(document).on(EVENTS.RSVP_CANCELED, function() {
|
||||
location.reload();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue