94 lines
2.6 KiB
JavaScript
94 lines
2.6 KiB
JavaScript
(function(context,$) {
|
|
|
|
"use strict";
|
|
context.JK = context.JK || {};
|
|
context.JK.RsvpCancelDialog = function(app, sessionId, rsvpRequestId) {
|
|
var logger = context.JK.logger;
|
|
var rest = context.JK.Rest();
|
|
var $screen = null;
|
|
var dialogId = 'rsvp-cancel-dialog';
|
|
var $btnCancel = $("#btnCancelRsvp");
|
|
|
|
function beforeShow(data) {
|
|
}
|
|
|
|
function afterShow(data) {
|
|
|
|
rest.getSessionHistory(sessionId)
|
|
.done(function(response) {
|
|
if (response) {
|
|
$('.session-name', $screen).html(response.name);
|
|
$('.scheduled-start', $screen).html(response.scheduled_start);
|
|
|
|
if (response.recurring_mode !== null) {
|
|
$('.schedule-recurrence', $screen).html("Recurs " + response.recurring_mode + " on this day at this time");
|
|
}
|
|
}
|
|
})
|
|
.fail(function(xhr) {
|
|
|
|
});
|
|
}
|
|
|
|
function afterHide() {
|
|
}
|
|
|
|
function showDialog() {
|
|
return app.layout.showDialog('rsvp-cancel-dialog');
|
|
}
|
|
|
|
function events() {
|
|
$btnCancel.unbind('click');
|
|
$btnCancel.click(function(e) {
|
|
e.preventDefault();
|
|
|
|
var error = false;
|
|
var cancelOption = $('input[name="cancel"]:checked', $screen).val();
|
|
rest.cancelRsvpRequest(sessionId, rsvpRequestId, cancelOption)
|
|
.done(function(response) {
|
|
var comment = $.trim($('#txtComment', $screen).val());
|
|
if (comment.length > 0) {
|
|
rest.addSessionInfoComment(sessionId, comment)
|
|
.done(function(response) {
|
|
|
|
})
|
|
.fail(function(xhr) {
|
|
error = true;
|
|
$('.error', $screen).html("Unexpected error occurred while saving message (" + xhr.status + ")");
|
|
$('.error', $screen).show();
|
|
});
|
|
}
|
|
|
|
if (!error) {
|
|
app.layout.closeDialog(dialogId);
|
|
$btnCancel.trigger("rsvpCancelEvent");
|
|
}
|
|
})
|
|
.fail(function(xhr) {
|
|
$('.error', $screen).html("Unexpected error occurred while cancelling RSVP request (" + xhr.status + ")");
|
|
$('.error', $screen).show();
|
|
});
|
|
});
|
|
}
|
|
|
|
function initialize() {
|
|
|
|
var dialogBindings = {
|
|
'beforeShow' : beforeShow,
|
|
'afterShow' : afterShow,
|
|
'afterHide': afterHide
|
|
};
|
|
|
|
app.bindDialog(dialogId, dialogBindings);
|
|
|
|
$screen = $('[layout-id="' + dialogId + '"]');
|
|
|
|
events();
|
|
}
|
|
|
|
this.initialize = initialize;
|
|
this.showDialog = showDialog;
|
|
}
|
|
|
|
return this;
|
|
})(window,jQuery); |