diff --git a/ruby/lib/jam_ruby/models/rsvp_request.rb b/ruby/lib/jam_ruby/models/rsvp_request.rb index a949f9306..ed8ea3736 100644 --- a/ruby/lib/jam_ruby/models/rsvp_request.rb +++ b/ruby/lib/jam_ruby/models/rsvp_request.rb @@ -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 diff --git a/web/app/assets/javascripts/jam_rest.js b/web/app/assets/javascripts/jam_rest.js index de51572e0..963a34d15 100644 --- a/web/app/assets/javascripts/jam_rest.js +++ b/web/app/assets/javascripts/jam_rest.js @@ -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; diff --git a/web/app/assets/javascripts/rsvpCancelDialog.js b/web/app/assets/javascripts/rsvpCancelDialog.js index e69de29bb..828af34b7 100644 --- a/web/app/assets/javascripts/rsvpCancelDialog.js +++ b/web/app/assets/javascripts/rsvpCancelDialog.js @@ -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); \ No newline at end of file diff --git a/web/app/assets/javascripts/rsvpSubmitDialog.js b/web/app/assets/javascripts/rsvpSubmitDialog.js index 2f6c49d00..8360d5bf8 100644 --- a/web/app/assets/javascripts/rsvpSubmitDialog.js +++ b/web/app/assets/javascripts/rsvpSubmitDialog.js @@ -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('' + instrumentTitleCase + "
"); }); } @@ -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(); } diff --git a/web/app/assets/javascripts/ui_helper.js b/web/app/assets/javascripts/ui_helper.js index a4b1240d1..b9e4f64f5 100644 --- a/web/app/assets/javascripts/ui_helper.js +++ b/web/app/assets/javascripts/ui_helper.js @@ -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(); } diff --git a/web/app/assets/javascripts/web/scheduled_session.js b/web/app/assets/javascripts/web/scheduled_session.js index 857b47e02..30398fa88 100644 --- a/web/app/assets/javascripts/web/scheduled_session.js +++ b/web/app/assets/javascripts/web/scheduled_session.js @@ -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; diff --git a/web/app/views/clients/_rsvpCancelDialog.html.haml b/web/app/views/clients/_rsvpCancelDialog.html.haml index e69de29bb..218126cca 100644 --- a/web/app/views/clients/_rsvpCancelDialog.html.haml +++ b/web/app/views/clients/_rsvpCancelDialog.html.haml @@ -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"}/ \ No newline at end of file diff --git a/web/app/views/clients/_rsvpSubmitDialog.html.haml b/web/app/views/clients/_rsvpSubmitDialog.html.haml index cbd69287d..319313bc9 100644 --- a/web/app/views/clients/_rsvpSubmitDialog.html.haml +++ b/web/app/views/clients/_rsvpSubmitDialog.html.haml @@ -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"}/ \ No newline at end of file diff --git a/web/app/views/music_sessions/session_info.html.haml b/web/app/views/music_sessions/session_info.html.haml index 12da1ff4a..3fcbdba8d 100644 --- a/web/app/views/music_sessions/session_info.html.haml +++ b/web/app/views/music_sessions/session_info.html.haml @@ -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