Skip to content

Commit 1f03537

Browse files
committed
more refactoringz for new survey
1 parent 72d5010 commit 1f03537

File tree

1 file changed

+109
-6
lines changed

1 file changed

+109
-6
lines changed

v3/js/opt-frontend-common.js

Lines changed: 109 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,9 @@ function genericOptFrontendReady() {
765765
$("#executeBtn").attr('disabled', false);
766766
$("#executeBtn").click(executeCodeFromScratch);
767767

768-
initializeDisplayModeSurvey();
768+
// for Versions 1 and 2, initialize here. But for version 3+, dynamically
769+
// generate a survey whenever the user successfully executes a piece of code
770+
//initializeDisplayModeSurvey();
769771
}
770772

771773

@@ -1071,6 +1073,10 @@ function optFinishSuccessfulExecution() {
10711073
// compress the logs a bit when there's rapid scrubbing or scrolling)
10721074
myVisualizer.updateHistory = [];
10731075
myVisualizer.updateHistory.push([myVisualizer.curInstr, 0]); // seed it!
1076+
1077+
// For version 3+, dynamically generate a survey whenever the user
1078+
// successfully executes a piece of code
1079+
initializeDisplayModeSurvey();
10741080
}
10751081

10761082

@@ -1147,6 +1153,8 @@ function executePythonCode(pythonSourceCode,
11471153

11481154
handleSuccessFunc();
11491155

1156+
// SUPER HACK -- slip in backendOptionsObj as an extra field
1157+
myVisualizer.backendOptionsObj = backendOptionsObj;
11501158

11511159
// VERY SUBTLE -- reinitialize TogetherJS so that it can detect
11521160
// and sync any new elements that are now inside myVisualizer
@@ -1297,6 +1305,8 @@ What did you just learn? <input type="text" id="sharedSessionWhatLearned" class=
12971305

12981306

12991307
// display-mode survey, which is shown when the user is in 'display' mode
1308+
// As of Version 3, this runs every time code is executed, so make sure event
1309+
// handlers don't unnecessarily stack up
13001310
function initializeDisplayModeSurvey() {
13011311
/* Version 1 - started experiment on 2014-04-09, put on hold on 2014-05-02
13021312
@@ -1411,19 +1421,112 @@ display a brief "Thanks!" note]
14111421
14121422
*/
14131423

1414-
var display_mode_survey_v3 = '\n\
1415-
<div id="vizSurveyLabel" style="font-size: 8pt; color: #666;">\n\
1416-
Support our research by clicking a button when you see something interesting in the visualization.<br/>\n\
1424+
var display_mode_survey_v3a = '\n\
1425+
<div id="vizSurveyLabel">\n\
1426+
Support our research by clicking a button whenever you learn something.<br/>\n\
14171427
</div>\n\
14181428
<div>\n\
14191429
<button class="surveyBtn" type="button">I learned something new!</button>\n\
1420-
<button class="surveyBtn" type="button">I cleared up a misunderstanding!</button>\n\
14211430
<button class="surveyBtn" type="button">I found a bug in my code!</button>\n\
1431+
<button class="surveyBtn" type="button">I cleared up a misunderstanding!</button>\n\
1432+
</div>\n\
1433+
</div>\n';
1434+
1435+
var display_mode_survey_v3b = '\n\
1436+
<div id="vizSurveyLabel">\n\
1437+
Support our research and help future learners by describing what you are learning.\n\
1438+
</div>\n\
1439+
<div style="font-size: 10pt; margin-bottom: 5pt; padding: 1pt;">\n\
1440+
What did you just learn?\n\
1441+
<input style="font-size: 10pt; padding: 1pt;" type="text" id="iJustLearnedInput" size="60" maxlength=300/>\n\
1442+
<button id="iJustLearnedSubmission" type="button" style="font-size: 10pt;">Submit</button>\n\
1443+
<span id="iJustLearnedThanks"\n\
1444+
style="color: #e93f34; font-weight: bold; font-size: 11pt; display: none;">\n\
1445+
Thanks!\n\
1446+
</span>\n\
1447+
</div>';
1448+
1449+
var display_mode_survey_v3c = '\n\
1450+
<div id="vizSurveyLabel">\n\
1451+
Support our research by clicking a button whenever you learn something.<br/>\n\
1452+
</div>\n\
1453+
<div>\n\
1454+
You hoped to learn:\n\
1455+
"<span id="userHopeLearn"></span>"<br/>\n\
1456+
<button class="surveyBtn" type="button">I just learned something about that!</button>\n\
1457+
<button class="surveyBtn" type="button">I just learned something else new!</button>\n\
14221458
</div>\n\
14231459
</div>\n';
14241460

14251461

1426-
var display_mode_survey_HTML = display_mode_survey_v3;
1462+
var testCondition = 'a';
1463+
var display_mode_survey_HTML = '';
1464+
1465+
if (testCondition == 'a') {
1466+
display_mode_survey_HTML = display_mode_survey_v3a;
1467+
} else if (testCondition == 'b') {
1468+
display_mode_survey_HTML = display_mode_survey_v3b;
1469+
} else if (testCondition == 'c') {
1470+
display_mode_survey_HTML = display_mode_survey_v3c;
1471+
} else {
1472+
assert(false);
1473+
}
1474+
14271475
$("#surveyHeader").html(display_mode_survey_HTML);
1476+
$("#vizSurveyLabel").css('font-size', '8pt')
1477+
.css('color', '#666')
1478+
.css('margin-bottom', '5pt');
1479+
$(".surveyBtn").css('margin-right', '6px');
1480+
1481+
// use unbind first so that this function is idempotent
1482+
$('.surveyBtn').unbind().click(function(e) {
1483+
var myArgs = getAppState();
1484+
1485+
var buttonPrompt = $(this).html();
1486+
var res = prompt('You said, "' + buttonPrompt + '"' + '\nPlease describe what you just learned:');
1487+
1488+
if ($.trim(res)) {
1489+
myArgs.surveyQuestion = buttonPrompt;
1490+
myArgs.surveyResponse = res;
1491+
myArgs.surveyVersion = 'v3';
1492+
1493+
// 2014-05-25: implemented more detailed tracing for surveys
1494+
if (myVisualizer) {
1495+
myArgs.updateHistoryJSON = JSON.stringify(myVisualizer.updateHistory);
1496+
}
1497+
1498+
$.get('survey.py', myArgs, function(dat) {});
1499+
}
1500+
});
1501+
1502+
// use unbind first so that this function is idempotent
1503+
$('#iJustLearnedSubmission').unbind().click(function(e) {
1504+
var resp = $("#iJustLearnedInput").val();
1505+
1506+
if (!$.trim(resp)) {
1507+
return;
1508+
}
1509+
1510+
var myArgs = getAppState();
1511+
1512+
myArgs.surveyQuestion = "What did you just learn?";
1513+
myArgs.surveyResponse = resp;
1514+
myArgs.surveyVersion = 'v3';
1515+
1516+
// 2014-05-25: implemented more detailed tracing for surveys
1517+
if (myVisualizer) {
1518+
myArgs.updateHistoryJSON = JSON.stringify(myVisualizer.updateHistory);
1519+
}
1520+
1521+
$.get('survey.py', myArgs, function(dat) {});
1522+
1523+
$("#iJustLearnedInput").val('');
1524+
$("#iJustLearnedThanks").show();
1525+
$.doTimeout('iJustLearnedThanksFadeOut', 1200, function() {
1526+
$("#iJustLearnedThanks").fadeOut(1000);
1527+
});
1528+
});
1529+
1530+
14281531

14291532
}

0 commit comments

Comments
 (0)