diff --git a/web/app/assets/javascripts/rateSessionDialog.js b/web/app/assets/javascripts/rateSessionDialog.js new file mode 100644 index 000000000..00d11d126 --- /dev/null +++ b/web/app/assets/javascripts/rateSessionDialog.js @@ -0,0 +1,69 @@ +(function(context,$) { + + "use strict"; + + context.JK = context.JK || {}; + context.JK.RateSessionDialog = function(app, finishedCallback) { + var logger = context.JK.logger; + var dialogId = 'rate-session-dialog'; + var $scopeSelector = "[layout-id='rate-session-dialog']"; + + function showDialog() { + app.layout.showDialog(dialogId); + return true; // false if should not show dialog + } + + function closeDialog() { + app.layout.closeDialog(dialogId); + if (finishedCallback) { + setTimeout(finishedCallback, 100); + } + } + + function events() { + $('#btn-rate-session-cancel', $scopeSelector).click(function(evt) { + closeDialog(); + }); + $('#btn-rate-session-up', $scopeSelector).click(function(evt) { + $(this).hasClass('selected') ? $(this).removeClass('selected') : $(this).addClass('selected'); + if ($('#btn-rate-session-down').hasClass('selected')) { + $('#btn-rate-session-down').removeClass('selected') + } + }); + $('#btn-rate-session-down', $scopeSelector).click(function(evt) { + $(this).hasClass('selected') ? $(this).removeClass('selected') : $(this).addClass('selected'); + if ($('#btn-rate-session-up').hasClass('selected')) { + $('#btn-rate-session-up').removeClass('selected') + } + }); + $('#btn-rate-session-send', $scopeSelector).click(function(evt) { + var url = "/api/participant_histories/"+context.JK.JamServer.clientID+"/rating"; + $.ajax({ + type: "POST", + url: url + }).done(function (response) { + closeDialog(); + }); + }); + } + + function beforeShow(data) { + // confirm user should see dialog + } + + function afterShow(data) { + } + + function initialize() { + var dialogBindings = { + 'beforeShow' : beforeShow, + 'afterShow' : afterShow + }; + app.bindDialog(dialogId, dialogBindings); + events(); + } + + this.initialize = initialize; + this.showDialog = showDialog; + }; +})(window,jQuery); diff --git a/web/app/assets/javascripts/session.js b/web/app/assets/javascripts/session.js index 9b9b3b01d..2819b780a 100644 --- a/web/app/assets/javascripts/session.js +++ b/web/app/assets/javascripts/session.js @@ -1307,14 +1307,24 @@ function sessionLeave(evt) { evt.preventDefault(); - - promptLeave = false; - app.layout.showDialog('leavingSession'); - //context.window.location = '/client#/home'; - + rateSession(); return false; } + function bailOut() { + promptLeave = false; + context.window.location = '/client#/home'; + } + + function rateSession() { + var dialog = new context.JK.RateSessionDialog(context.JK.app, bailOut); + dialog.initialize(); + if (dialog.showDialog() === false) { + bailOut(); + } + return true; + } + function sessionResync(evt) { evt.preventDefault(); var response = context.jamClient.SessionAudioResync(); diff --git a/web/app/controllers/api_music_sessions_controller.rb b/web/app/controllers/api_music_sessions_controller.rb index cb2e266ba..aec1719d3 100644 --- a/web/app/controllers/api_music_sessions_controller.rb +++ b/web/app/controllers/api_music_sessions_controller.rb @@ -151,7 +151,7 @@ class ApiMusicSessionsController < ApiController end def participant_rating - if @history = MusicSessionUserHistory.find(params[:id]) + if @history = MusicSessionUserHistory.find_by_client_id(params[:client_id]) @history.add_rating(params[:rating]) @history.save diff --git a/web/app/views/clients/_rateSession.html.erb b/web/app/views/clients/_rateSession.html.erb index adc56146d..5bb43602e 100644 --- a/web/app/views/clients/_rateSession.html.erb +++ b/web/app/views/clients/_rateSession.html.erb @@ -1,16 +1,16 @@ -