add session cancel feature

This commit is contained in:
Bert Owen 2014-06-18 04:57:48 +08:00
parent 07c1a4c85d
commit aca8b86316
5 changed files with 156 additions and 6 deletions

View File

@ -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);
}

View File

@ -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;

View File

@ -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);

View File

@ -67,8 +67,10 @@
<br class="all"/>
<div class="left w20 mb5"></div>
<div class="right w80 mb5">
<a href="#" class="button-orange">DETAILS</a>
<a href="#" class="button-orange">CANCEL SESSION</a>
<a href="#" data-id="{{session.id}}" class="button-orange session-detail-button">DETAILS</a>
{% if (data.current_user == session.user_id) { %}
<a href="#" class="button-orange session-cancel-button">CANCEL SESSION</a>
{% } %}
</div>
</div>
</td>

View File

@ -0,0 +1,26 @@
.dialog.dialog-overlay-sm{layout: 'dialog', 'layout-id' => 'session-cancel-dialog', id: 'session-cancel-dialog'}
.content-head
= image_tag 'content/icon_checkmark_circle.png', :alt => "", :class => "content-icon", :width => "20", :height => "20"
%h1 cancel session
.dialog-inner
%h2 SESSION
%span.session-name
%br/
%span.scheduled-start
%br/
%span.schedule-recurrence
%br/
%br/
.error{:style => 'display:none'}
%input{:type => 'radio', :name => 'cancel', :value => 'yes', :checked => true} Cancel RSVP just for this one session
%br/
Enter a message to the other musicians in the session (optional):
%textarea.w95.p5.f15{id: 'txtComment', rows: '2', placeholder: 'Enter a comment...'}
%br/
%br/
.left
%a.button-orange{:href => 'TBD', :rel => 'external', :target => '_blank'} HELP
.right
%a.button-grey{:id => 'btnCancel', 'layout-action' => 'close'} CANCEL
%a.button-orange{:id => 'btnCancelSession'} CANCEL SESSION
%br{:clear => "all"}/