// Wait until dom is ready...
$( document ).ready(function() {
getSatisfactionScore = function(){
$.post(ddeLoc + "getsatisfaction", '{"sessionid":"' + getSessionId() + '"}')
.done( function(dataReturned){
// Show the last satisfaction score
// Since I'm trying to make this generic (and don't want to have to change lots of target HTML pages) this is all
// done by injecting the elements into the DOM
var li = document.querySelector("#navbar .nav #satisfaction");
if (null == li)
{
// Not in the UI already, so inject it
var ul = document.querySelector("#navbar .nav");
li = document.createElement("li");
li.id = "satisfaction";
li.classList.add("dropdown");
ul.appendChild(li);
}
var smiley = "undefined"
if (""==dataReturned.Satisfaction_Value)
smiley = "undefined";
else{
var satisfactionValue = parseFloat(dataReturned.Satisfaction_Value);
console.log("Satisfaction value is " + satisfactionValue);
//"Satisfaction_Value" should be 0.0 to 100.0. Map to our image
// Note that this could be done in the rule, but easier here
if (satisfactionValue<=20)
smiley = "1";
else if (satisfactionValue<=40)
smiley = "2";
else if (satisfactionValue<=60)
smiley = "3";
else if (satisfactionValue<=80)
smiley = "4";
else
smiley = "5";
}
// If the user clicks on this then we always show the survey, as they'll probably want to change it
li.innerHTML = "";
})
.error(function(XMLHttpRequest, textStatus, errorThrown){
// There's probably no rule, so we'll not do anything here
console.log("DDE call failed: " + textStatus + " / " + errorThrown)
})
}
// Ask DDE if this user should have the survey shown
getShowSurvey = function()
{
$.post(ddeLoc + "can-show-satisfaction-survey", '{"sessionid":"' + getSessionId() + '"}')
.done( function(dataReturned){
console.log("Can we show the survey? " + dataReturned.output);
if ("true"==dataReturned.output)
{
// Truthy? Then inject the survey HTML
showSurvey();
}
})
.error(function(XMLHttpRequest, textStatus, errorThrown){
// There's probably no rule, so we'll not do anything here
if (console.log){
console.log("DDE call failed: " + textStatus + " / " + errorThrown)
}
})
}
// Show the survey. This might be a bit intrusive, so we only show it if a rule says we can (or if the user explicitly clicks for it)
showSurvey = function(){
// Since I'm trying to make this generic (and don't want to have to change lots of target HTML pages) this is all
// done by injecting the elements into the DOM
var surveyBar = document.querySelector("#surveyBar");
if (null == surveyBar)
{
// Not in the UI already, so inject it above the featuresbar
var featuresBar = document.querySelector("#featuresBar");
var ul = document.querySelector("#navbar .nav");
surveyBar = document.createElement("section");
surveyBar.id = "surveyBar";
surveyBar.classList.add("full-width","bg-blue");
// Yes, this is an awkward way of generating a bit of UI, but I can't be bothered with HTML templates
surveyHtml = '