2014-04-30 16:44:37 +00:00
|
|
|
(function(context,$) {
|
|
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
context.JK = context.JK || {};
|
2014-05-01 06:35:16 +00:00
|
|
|
context.JK.RateSessionDialog = function(app) {
|
2014-04-30 16:44:37 +00:00
|
|
|
var logger = context.JK.logger;
|
|
|
|
|
var dialogId = 'rate-session-dialog';
|
|
|
|
|
var $scopeSelector = "[layout-id='rate-session-dialog']";
|
2014-05-07 01:33:27 +00:00
|
|
|
var clientId = context.JK.JamServer.clientID;
|
2014-04-30 16:44:37 +00:00
|
|
|
|
2014-05-01 01:48:57 +00:00
|
|
|
function reset() {
|
2014-05-07 01:33:27 +00:00
|
|
|
clientId = context.JK.JamServer.clientID;
|
2014-05-01 01:48:57 +00:00
|
|
|
$('#btn-rate-session-up', $scopeSelector).removeClass('selected');
|
|
|
|
|
$('#btn-rate-session-down', $scopeSelector).removeClass('selected');
|
|
|
|
|
$('#txt-rate-session-comment',"[layout-id='rate-session-dialog']").val('');
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-30 16:44:37 +00:00
|
|
|
function showDialog() {
|
2014-05-07 01:33:27 +00:00
|
|
|
if (clientId) {
|
|
|
|
|
reset();
|
2014-05-01 06:35:16 +00:00
|
|
|
$.ajax({
|
|
|
|
|
type: "GET",
|
2014-05-07 01:33:27 +00:00
|
|
|
url: "/api/participant_histories/"+clientId
|
2014-05-01 06:35:16 +00:00
|
|
|
}).done(function (response) {
|
|
|
|
|
if (response &&
|
|
|
|
|
response.hasOwnProperty('should_rate_session') &&
|
|
|
|
|
true==response['should_rate_session']) {
|
|
|
|
|
app.layout.showDialog(dialogId);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return true;
|
2014-04-30 20:49:32 +00:00
|
|
|
}
|
|
|
|
|
return false;
|
2014-04-30 16:44:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function closeDialog() {
|
|
|
|
|
app.layout.closeDialog(dialogId);
|
|
|
|
|
}
|
2014-04-30 20:49:32 +00:00
|
|
|
|
|
|
|
|
function getRating() {
|
|
|
|
|
if ($('#btn-rate-session-down', $scopeSelector).hasClass('selected')) {
|
2018-07-29 16:09:03 +00:00
|
|
|
console.log("user chose a bad rating")
|
2014-04-30 20:49:32 +00:00
|
|
|
return -1;
|
|
|
|
|
} else if ($('#btn-rate-session-up', $scopeSelector).hasClass('selected')) {
|
2018-07-29 16:09:03 +00:00
|
|
|
console.log("user chose a good rating")
|
2014-04-30 20:49:32 +00:00
|
|
|
return 1;
|
|
|
|
|
}
|
2018-07-29 16:09:03 +00:00
|
|
|
console.log("user chose no rating")
|
2014-04-30 20:49:32 +00:00
|
|
|
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();
|
2015-07-15 15:04:45 +00:00
|
|
|
return false;
|
2014-04-30 16:44:37 +00:00
|
|
|
});
|
|
|
|
|
$('#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')
|
|
|
|
|
}
|
2014-05-01 01:48:57 +00:00
|
|
|
return false;
|
2014-04-30 16:44:37 +00:00
|
|
|
});
|
|
|
|
|
$('#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')
|
|
|
|
|
}
|
2014-05-01 01:48:57 +00:00
|
|
|
return false;
|
2014-04-30 16:44:37 +00:00
|
|
|
});
|
|
|
|
|
$('#btn-rate-session-send', $scopeSelector).click(function(evt) {
|
2014-05-01 01:48:57 +00:00
|
|
|
var rr = getRating(), cc = getComment();
|
|
|
|
|
if (0 == rr && 0 == cc.length) {
|
|
|
|
|
closeDialog();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2017-10-16 02:32:51 +00:00
|
|
|
if (0 == rr) {
|
|
|
|
|
context.JK.Banner.showNotice('Please select the thumbs up or thumbs down when leaving a rating.<br/><br/>Thank you!')
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-05-07 01:33:27 +00:00
|
|
|
var url = "/api/participant_histories/"+clientId+"/rating";
|
2018-07-22 19:19:21 +00:00
|
|
|
// get backend details too
|
|
|
|
|
if(context.jamClient.getAllClientsStateMap) {
|
|
|
|
|
var backendDetails = context.jamClient.getAllClientsStateMap()
|
|
|
|
|
console.log("got backend details", backendDetails)
|
|
|
|
|
}
|
2021-02-02 00:59:47 +00:00
|
|
|
|
2014-04-30 16:44:37 +00:00
|
|
|
$.ajax({
|
|
|
|
|
type: "POST",
|
2014-04-30 20:49:32 +00:00
|
|
|
url: url,
|
2018-07-22 19:19:21 +00:00
|
|
|
data: { rating: getRating(), comment: getComment(), backend_details: backendDetails }
|
2014-04-30 16:44:37 +00:00
|
|
|
}).done(function (response) {
|
2014-05-01 01:48:57 +00:00
|
|
|
var qq = getRating();
|
|
|
|
|
if (0 < qq) {
|
|
|
|
|
context.JK.GA.trackSessionQuality(context.JK.GA.SessionQualityTypes.good);
|
|
|
|
|
} else if (0 > qq){
|
|
|
|
|
context.JK.GA.trackSessionQuality(context.JK.GA.SessionQualityTypes.poor);
|
|
|
|
|
}
|
2014-04-30 16:44:37 +00:00
|
|
|
});
|
2021-02-02 00:59:47 +00:00
|
|
|
closeDialog();
|
2014-05-01 01:48:57 +00:00
|
|
|
return false;
|
2014-04-30 16:44:37 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|