jam-cloud/web/app/assets/javascripts/rateSessionDialog.js

124 lines
4.3 KiB
JavaScript
Raw Normal View History

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')) {
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')
}
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;
}
2014-05-07 01:33:27 +00:00
var url = "/api/participant_histories/"+clientId+"/rating";
2014-04-30 16:44:37 +00:00
$.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) {
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
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);