2014-04-30 16:44:37 +00:00
|
|
|
(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() {
|
2014-04-30 20:49:32 +00:00
|
|
|
if (context.JK.JamServer.clientID) {
|
|
|
|
|
app.layout.showDialog(dialogId);
|
|
|
|
|
return true; // false if should not show dialog
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2014-04-30 16:44:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function closeDialog() {
|
|
|
|
|
app.layout.closeDialog(dialogId);
|
|
|
|
|
if (finishedCallback) {
|
2014-04-30 20:49:32 +00:00
|
|
|
setTimeout(finishedCallback, 10);
|
2014-04-30 16:44:37 +00:00
|
|
|
}
|
|
|
|
|
}
|
2014-04-30 20:49:32 +00:00
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
2014-04-30 16:44:37 +00:00
|
|
|
|
|
|
|
|
function events() {
|
|
|
|
|
$('#btn-rate-session-cancel', $scopeSelector).click(function(evt) {
|
|
|
|
|
closeDialog();
|
|
|
|
|
});
|
|
|
|
|
$('#btn-rate-session-up', $scopeSelector).click(function(evt) {
|
2014-04-30 20:49:32 +00:00
|
|
|
if ($(this).hasClass('selected')) {
|
|
|
|
|
$(this).removeClass('selected')
|
|
|
|
|
} else {
|
|
|
|
|
$(this).addClass('selected');
|
|
|
|
|
}
|
2014-04-30 16:44:37 +00:00
|
|
|
if ($('#btn-rate-session-down').hasClass('selected')) {
|
|
|
|
|
$('#btn-rate-session-down').removeClass('selected')
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
$('#btn-rate-session-down', $scopeSelector).click(function(evt) {
|
2014-04-30 20:49:32 +00:00
|
|
|
if ($(this).hasClass('selected')) {
|
|
|
|
|
$(this).removeClass('selected')
|
|
|
|
|
} else {
|
|
|
|
|
$(this).addClass('selected');
|
|
|
|
|
}
|
2014-04-30 16:44:37 +00:00
|
|
|
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",
|
2014-04-30 20:49:32 +00:00
|
|
|
url: url,
|
|
|
|
|
data: { rating: getRating(), comment: getComment() }
|
2014-04-30 16:44:37 +00:00
|
|
|
}).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);
|