diff --git a/web/app/assets/javascripts/accounts_sessions.js b/web/app/assets/javascripts/accounts_sessions.js
index 1d8ece9ac..906a77ba6 100644
--- a/web/app/assets/javascripts/accounts_sessions.js
+++ b/web/app/assets/javascripts/accounts_sessions.js
@@ -10,7 +10,7 @@
var scheduledSessions = {};
function beforeShow(data) {
- userId = data.id;
+ userId = context.JK.currentUserId;
}
function afterShow(data) {
@@ -24,9 +24,18 @@
$('#account-sessions-content-scroller form .error').removeClass("error")
}
- /****************** MAIN PORTION OF SCREEN *****************/
- // events for main screen
+ function cancelSession(e) {
+ e.preventDefault();
+
+ // var session_id = $(e.target).attr('data-id');
+ // rest.cancelSession({session_id: session_id})
+ // .done(function() {
+ // })
+ // .fail(app.ajaxError);
+ }
+
function events() {
+ $(".session-cancel-button").on('click', cancelSession);
}
function appendSessions(template) {
@@ -38,7 +47,11 @@
scheduledSessions[session.id] = session;
});
- var template = context._.template($('#template-account-session').html(), {sessions: sessionList}, {variable: 'data'});
+ var template = context._.template(
+ $('#template-account-session').html(),
+ {sessions: sessionList, current_user: userId},
+ {variable: 'data'}
+ );
appendSessions(template);
}
diff --git a/web/app/assets/javascripts/jam_rest.js b/web/app/assets/javascripts/jam_rest.js
index 71fc486cd..d766a898c 100644
--- a/web/app/assets/javascripts/jam_rest.js
+++ b/web/app/assets/javascripts/jam_rest.js
@@ -97,6 +97,20 @@
});
}
+ function cancelSession(options) {
+ var sessionId = options["session_id"];
+ delete options["session_id"];
+
+ return $.ajax({
+ type: "DELETE",
+ dataType: "JSON",
+ contentType: 'application/json',
+ url: "/api/sessions/" + sessionId,
+ data: JSON.stringify(options),
+ processData: false
+ });
+ }
+
function findSessions(query) {
return $.ajax({
type: "GET",
@@ -1141,6 +1155,7 @@
this.uploadMusicNotations = uploadMusicNotations;
this.legacyJoinSession = legacyJoinSession;
this.joinSession = joinSession;
+ this.cancelSession = cancelSession;
this.getUserDetail = getUserDetail;
this.getCities = getCities;
this.getRegions = getRegions;
diff --git a/web/app/assets/javascripts/sessionCancelDialog.js b/web/app/assets/javascripts/sessionCancelDialog.js
new file mode 100644
index 000000000..3ed621e9d
--- /dev/null
+++ b/web/app/assets/javascripts/sessionCancelDialog.js
@@ -0,0 +1,94 @@
+(function(context,$) {
+
+ "use strict";
+ context.JK = context.JK || {};
+ context.JK.SessionCancelDialog = 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() {
+ 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);
\ No newline at end of file
diff --git a/web/app/views/clients/_account_sessions.html.erb b/web/app/views/clients/_account_sessions.html.erb
index 83f513527..74d15aa56 100644
--- a/web/app/views/clients/_account_sessions.html.erb
+++ b/web/app/views/clients/_account_sessions.html.erb
@@ -67,8 +67,10 @@