(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() { if (context.JK.JamServer.clientID) { app.layout.showDialog(dialogId); return true; // false if should not show dialog } return false; } function closeDialog() { app.layout.closeDialog(dialogId); if (finishedCallback) { setTimeout(finishedCallback, 10); } } function getRating() { if ($('#btn-rate-session-down', $scopeSelector).hasClass('selected')) { return -1; } else if ($('#btn-rate-session-up', $scopeSelector).hasClass('selected')) { return 1; } return 0; } function getComment() { return $('#txt-rate-session-comment',"[layout-id='rate-session-dialog']").val(); } function events() { $('#btn-rate-session-cancel', $scopeSelector).click(function(evt) { closeDialog(); }); $('#btn-rate-session-up', $scopeSelector).click(function(evt) { if ($(this).hasClass('selected')) { $(this).removeClass('selected') } else { $(this).addClass('selected'); } if ($('#btn-rate-session-down').hasClass('selected')) { $('#btn-rate-session-down').removeClass('selected') } }); $('#btn-rate-session-down', $scopeSelector).click(function(evt) { if ($(this).hasClass('selected')) { $(this).removeClass('selected') } else { $(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, data: { rating: getRating(), comment: getComment() } }).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);