From aca8b86316b796366c33c2bd18d834b7810019c3 Mon Sep 17 00:00:00 2001 From: Bert Owen Date: Wed, 18 Jun 2014 04:57:48 +0800 Subject: [PATCH] add session cancel feature --- .../assets/javascripts/accounts_sessions.js | 21 ++++- web/app/assets/javascripts/jam_rest.js | 15 +++ .../assets/javascripts/sessionCancelDialog.js | 94 +++++++++++++++++++ .../views/clients/_account_sessions.html.erb | 6 +- .../clients/_sessionCancelDialog.html.haml | 26 +++++ 5 files changed, 156 insertions(+), 6 deletions(-) create mode 100644 web/app/assets/javascripts/sessionCancelDialog.js create mode 100644 web/app/views/clients/_sessionCancelDialog.html.haml 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 @@
- DETAILS - CANCEL SESSION + DETAILS + {% if (data.current_user == session.user_id) { %} + CANCEL SESSION + {% } %}
diff --git a/web/app/views/clients/_sessionCancelDialog.html.haml b/web/app/views/clients/_sessionCancelDialog.html.haml new file mode 100644 index 000000000..5ceefbfca --- /dev/null +++ b/web/app/views/clients/_sessionCancelDialog.html.haml @@ -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"}/ \ No newline at end of file