Skip to content

Instantly share code, notes, and snippets.

@nonprofittechy
Created January 19, 2017 15:15
Show Gist options
  • Save nonprofittechy/bce98ac080be8b4ecbbd504bab9ba0d6 to your computer and use it in GitHub Desktop.
Save nonprofittechy/bce98ac080be8b4ecbbd504bab9ba0d6 to your computer and use it in GitHub Desktop.
function runEvaluation() {
console.log("before disabled");
this.disabled = true;
console.log("after disabled");
$('#error').remove();
var origin = $('input[name=origin]:checked').val();
var dest = $('input[name=dest]:checked').val();
var savePrefs = $('#save-prefs').is(':checked');
google.script.run
.withSuccessHandler(
function(textEvaluation, element) {
console.log(textEvaluation)
var gradeHTML = "";
var gradeLevel = textEvaluation.index
if (gradeLevel <= 6) {
// smiley face
var imgtag = '<img class="fkgl-image" src="http://emojipedia-us.s3.amazonaws.com/cache/1b/52/1b526018b526ffcbc024dfeaa5d647d0.png"/>';
} else if (gradeLevel <= 9) {
// neutral face
var imgtag = '<img class="fkgl-image" src="http://emojipedia-us.s3.amazonaws.com/cache/1b/52/1b526018b526ffcbc024dfeaa5d647d0.png"/>';
} else if (gradeLevel <= 11) {
// frowny face
var imgtag = '<img class="fkgl-image" src="http://emojipedia-us.s3.amazonaws.com/cache/8f/f5/8ff5fb3fbb1cf23d9d7f1558e0b95021.png"/>';
} else if (gradeLevel > 11) {
// angry face
var imgtag = '<img class="fkgl-image" src="http://emojipedia-us.s3.amazonaws.com/cache/08/4e/084ee20e931bf8cb42c6952678f3e160.png"/>';
}
gradeHTML = '<span class="fkgl-gradelevel">' + gradeLevel + '</span>' + imgtag;
$('#fkgl-index').html(gradeHTML);
var suggestions = '<ul class="suggestions-list">'
for (var i=0; i < textEvaluation.suggestions.length; i++) {
suggestions += '<li class="suggestion-item"><ul><li>Suggestion: ';
suggestions += textEvaluation.suggestions[i].summary + "</li>";
suggestions += '<ul><li class="suggestion-content">' + textEvaluation.suggestions[i].content + "</li></ul></ul>";
}
suggestions += "</ul>"
$('#suggestions').html(suggestions);
element.disabled = false;
})
.withFailureHandler(
function(msg, element) {
showError(msg, $('#button-bar'));
element.disabled = false;
})
.withUserObject(this)
.getTextEvaluation();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment