VRFS-1746 RSVP cancel dialog work

This commit is contained in:
Brian Smith 2014-05-29 02:33:37 -04:00
parent a0696ce610
commit f1229f6842
9 changed files with 210 additions and 35 deletions

View File

@ -205,9 +205,9 @@ module JamRuby
rsvp_request.canceled = true
rsvp_request.cancel_all = false
when 'no'
rsvp_request.canceled = false
rsvp_request.cancel_all = false
# when 'no'
# rsvp_request.canceled = false
# rsvp_request.cancel_all = false
when 'all'
rsvp_request.canceled = true

View File

@ -135,6 +135,15 @@
});
}
function getRsvpRequests(sessionId) {
return $.ajax({
url: '/api/rsvp_requests?session_id=' + sessionId,
type: "GET",
dataType : 'json',
contentType: 'application/json'
});
}
function submitRsvpRequest(sessionId, slotIds) {
return $.ajax({
url: '/api/rsvp_requests',
@ -145,6 +154,20 @@
});
}
function cancelRsvpRequest(sessionId, rsvpRequestId, cancelAll) {
var cancel = "yes";
if (cancelAll) {
cancel = "all";
}
return $.ajax({
url: '/api/rsvp_requests/' + rsvpRequestId,
type: "DELETE",
data : JSON.stringify({"session_id": sessionId, "cancelled": cancel}),
dataType : 'json',
contentType: 'application/json'
});
}
function getOpenSessionSlots(sessionId, openOnly) {
var url = '/api/rsvp_slots?session_id=' + sessionId;
@ -1086,7 +1109,9 @@
this.addSessionComment = addSessionComment;
this.addSessionInfoComment = addSessionInfoComment;
this.addSessionLike = addSessionLike;
this.getRsvpRequests = getRsvpRequests;
this.submitRsvpRequest = submitRsvpRequest;
this.cancelRsvpRequest = cancelRsvpRequest;
this.getOpenSessionSlots = getOpenSessionSlots;
this.addRecordingComment = addRecordingComment;
this.addRecordingLike = addRecordingLike;

View File

@ -0,0 +1,94 @@
(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() {
app.layout.showDialog('rsvp-cancel-dialog');
}
function events() {
$btnCancel.unbind('click');
$btnCancel.click(function(e) {
e.preventDefault();
var error = false;
rest.cancelRsvpRequest(sessionId, rsvpRequestId)
.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();
});
}
})
.fail(function(xhr) {
error = true;
$('.error', $screen).html("Unexpected error occurred while cancelling RSVP request (" + xhr.status + ")");
$('.error', $screen).show();
});
if (!error) {
app.layout.closeDialog(dialogId);
$btnCancel.trigger("rsvpCancelEvent");
}
});
}
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

@ -6,6 +6,8 @@
var logger = context.JK.logger;
var rest = context.JK.Rest();
var $screen = null;
var dialogId = 'rsvp-submit-dialog';
var $btnSubmit = $("#btnSubmitRsvp");
function beforeShow(data) {
}
@ -28,7 +30,6 @@
});
// if the session has slots, get the open ones
rest.getOpenSessionSlots(sessionId, true)
.done(function(response) {
if (response && response.length > 0) {
@ -36,8 +37,6 @@
var instrument = val.instrument_id;
var instrumentTitleCase = context.JK.toTitleCase(instrument);
// var instrumentTitleCase = instrument.charAt(0).toUpperCase() + instrument.substr(1).toLowerCase();
// var instTitleCase = val.instrument_id.charAt(0).toUpperCase() + context.val.instrument_id.charAt(0)
$('.rsvp-instruments', $screen).append('<input type="checkbox" value="' + val.id + '"/>' + instrumentTitleCase + "<br/>");
});
}
@ -55,12 +54,12 @@
}
function showDialog() {
app.layout.showDialog('rsvp-submit-dialog');
app.layout.showDialog(dialogId);
}
function events() {
$("#btnSubmit").unbind('click');
$("#btnSubmit").click(function(e) {
$btnSubmit.unbind('click');
$btnSubmit.click(function(e) {
e.preventDefault();
var slotIds = [];
$("input:checked", '.rsvp-instruments').each(function(index) {
@ -95,8 +94,8 @@
});
if (!error) {
app.layout.closeDialog('rsvp-submit-dialog');
$("#btnSubmit").trigger("rsvpSubmitEvent");
app.layout.closeDialog(dialogId);
$btnSubmit.trigger("rsvpSubmitEvent");
}
});
}
@ -109,9 +108,9 @@
'afterHide': afterHide
};
app.bindDialog('rsvp-submit-dialog', dialogBindings);
app.bindDialog(dialogId, dialogBindings);
$screen = $('[layout-id="rsvp-submit-dialog"]');
$screen = $('[layout-id="' + dialogId + '"]');
events();
}

View File

@ -36,13 +36,15 @@
}
function launchRsvpSubmitDialog(sessionId) {
console.log("launching submit");
var rsvpDialog = new JK.RsvpSubmitDialog(JK.app, sessionId);
rsvpDialog.initialize();
rsvpDialog.showDialog();
}
function launchRsvpCancelDialog(sessionId) {
var rsvpDialog = new JK.RsvpCancelDialog(JK.app, sessionId);
function launchRsvpCancelDialog(sessionId, rsvpRequestId) {
console.log("launching cancel");
var rsvpDialog = new JK.RsvpCancelDialog(JK.app, sessionId, rsvpRequestId);
rsvpDialog.initialize();
rsvpDialog.showDialog();
}

View File

@ -8,6 +8,7 @@
var logger = context.JK.logger;
var rest = JK.Rest();
var ui = new context.JK.UIHelper(app);
var $btnAction = $("#btn-action");
function addComment(musicSessionId) {
console.log("here");
@ -56,7 +57,14 @@
});
}
function initComments(musicSessionId) {
function initialize(musicSessionId) {
registerScheduledSessionComment();
var $parent = $('.landing-sidebar');
context.JK.bindHoverEvents($parent);
context.JK.setInstrumentAssetPath($('.instrument-icon', $parent));
// render comments
$(".landing-comment-scroller").empty();
rest.getSessionHistory(musicSessionId)
.done(function(response) {
@ -70,20 +78,34 @@
.fail(function(xhr) {
});
}
function initialize(musicSessionId) {
registerScheduledSessionComment();
rest.getRsvpRequests(musicSessionId)
.done(function(rsvp) {
if (rsvp && rsvp.length > 0) {
if (rsvp.canceled) {
$('.call-to-action').html('Your RSVP request to this session has been cancelled.');
$btnAction.hide();
}
else {
$('.call-to-action').html('Tell session organizer if you can no longer join this session');
$btnAction.html('CANCEL RSVP');
$btnAction.click(function(e) {
ui.launchRsvpCancelDialog(musicSessionId, rsvp.id);
});
}
}
// no RSVP
else {
$('.call-to-action').html("Tell the session creator you'd like to play in this session");
$btnAction.html('RSVP NOW!');
$btnAction.click(function(e) {
ui.launchRsvpSubmitDialog(musicSessionId);
});
}
})
.fail(function(xhr) {
initComments(musicSessionId);
var $parent = $('.landing-sidebar');
context.JK.bindHoverEvents($parent);
context.JK.setInstrumentAssetPath($('.instrument-icon', $parent));
$("#btn-rsvp").click(function(e) {
ui.launchRsvpSubmitDialog(musicSessionId);
});
});
$("#btnPostComment").click(function(e) {
if ($.trim($("#txtSessionInfoComment").val()).length > 0) {
@ -96,6 +118,10 @@
$(document).on("rsvpSubmitEvent", function() {
location.reload();
});
$(document).on("rsvpCancelEvent", function() {
location.reload();
});
}
this.initialize = initialize;

View File

@ -0,0 +1,29 @@
.dialog.dialog-overlay-sm{layout: 'dialog', 'layout-id' => 'rsvp-cancel-dialog', id: 'rsvp-cancel-dialog'}
.content-head
= image_tag 'content/icon_checkmark_circle.png', :alt => "", :class => "content-icon", :width => "20", :height => "20"
%h1 cancel rsvp
.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 => 'single', :checked => true} Cancel RSVP just for this one session
%br/
%input{:type => 'radio', :name => 'cancel', :value => 'all'} Cancel RSVP for all future sessions
%br/
%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 => 'btnCancelRsvp'} CANCEL RSVP
%br{:clear => "all"}/

View File

@ -20,8 +20,8 @@
%br/
%br/
.left
%a.button-orange{:href => 'TBD', :rel => 'external'} HELP
%a.button-orange{:href => 'TBD', :rel => 'external', :target => '_blank'} HELP
.right
%a.button-grey{:id => 'btnCancel', :href => 'TBD', 'layout-action' => 'close'} CANCEL
%a.button-orange{:id => 'btnSubmit', :href => 'TBD'} SUBMIT RSVP
%a.button-grey{:id => 'btnCancel', 'layout-action' => 'close'} CANCEL
%a.button-orange{:id => 'btnSubmitRsvp'} SUBMIT RSVP
%br{:clear => "all"}/

View File

@ -14,10 +14,10 @@
%span.f12 Session Creator
%br/
%br/
.f12 Tell the session creator you'd like to play in this session
%br/
%a.button-orange{:id => "btn-rsvp"}
RSVP NOW!
- if current_user.id != @music_session.creator.id
.f12.call-to-action
%br/
%a.button-orange{:id => "btn-action"}
.landing-details
.left.f20.teal
%strong SESSION