Bug 658598: Test Pilot surveys should be able to run code on pageLoad like studies can. r=dtownsend DONTBUILD
authorJono S Xia <jdicarlo@mozilla.com>
Mon, 23 May 2011 11:57:07 -0700
changeset 70008 783480c46028d7b393afb4e338c191e8bba0f82e
parent 70007 aca490d48c951bdb5403c5a0beeccde1b587864b
child 70009 fbb3643ddf68049b7cccc84b9ffb0fc72d932980
push id20153
push userdtownsend@mozilla.com
push dateMon, 23 May 2011 18:57:24 +0000
treeherdermozilla-central@783480c46028 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdtownsend
bugs658598
milestone6.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 658598: Test Pilot surveys should be able to run code on pageLoad like studies can. r=dtownsend DONTBUILD
browser/app/profile/extensions/testpilot@labs.mozilla.com/content/survey-generator.js
browser/app/profile/extensions/testpilot@labs.mozilla.com/modules/tasks.js
--- a/browser/app/profile/extensions/testpilot@labs.mozilla.com/content/survey-generator.js
+++ b/browser/app/profile/extensions/testpilot@labs.mozilla.com/content/survey-generator.js
@@ -86,16 +86,19 @@ function onBuiltinSurveyLoad() {
   } else {
     contentDiv.innerHTML = "";
     if (task.surveyExplanation) {
       explanation.innerHTML = task.surveyExplanation;
     } else {
       explanation.innerHTML = "";
     }
     drawSurveyForm(task, contentDiv);
+    // Allow surveys to define arbitrary page load handlers - call them
+    // after creating the rest of the page:
+    task.onPageLoad(task, document);
   }
 }
 
 function drawSurveyForm(task, contentDiv) {
   let surveyQuestions = task.surveyQuestions;
 
   /* Fill form fields with old survey answers if available --
    * but not if the survey version has changed since you stored them!!
@@ -109,32 +112,32 @@ function drawSurveyForm(task, contentDiv
   submitButton.setAttribute("style", "");
   let changeButton = document.getElementById("change-answers");
   changeButton.setAttribute("style", "display:none");
   // Loop through questions and render html form input elements for each
   // one.
   for (let i = 0; i < surveyQuestions.length; i++) {
     let question = surveyQuestions[i].question;
     let explanation = surveyQuestions[i].explanation;
-    let elem;
+    let elem, j;
 
     elem = document.createElement("h3");
     elem.innerHTML = (i+1) + ". " + question;
     contentDiv.appendChild(elem);
     if (explanation) {
       elem = document.createElement("p");
       elem.setAttribute("class", "survey-question-explanation");
       elem.innerHTML = explanation;
       contentDiv.appendChild(elem);
     }
     // If you've done this survey before, preset all inputs using old answers
     let choices = surveyQuestions[i].choices;
     switch (surveyQuestions[i].type) {
     case MULTIPLE_CHOICE:
-      for (let j = 0; j < choices.length; j++) {
+      for (j = 0; j < choices.length; j++) {
         let newRadio = document.createElement("input");
         newRadio.setAttribute("type", "radio");
         newRadio.setAttribute("name", "answer_to_" + i);
         newRadio.setAttribute("value", j);
         if (oldAnswers && oldAnswers[i] == String(j)) {
           newRadio.setAttribute("checked", "true");
         }
         let label = document.createElement("span");
@@ -143,17 +146,17 @@ function drawSurveyForm(task, contentDiv
         contentDiv.appendChild(label);
         contentDiv.appendChild(document.createElement("br"));
       }
       break;
     case CHECK_BOXES:
     case CHECK_BOXES_WITH_FREE_ENTRY:
       let checkboxName = "answer_to_" + i;
       // Check boxes:
-      for (let j = 0; j < choices.length; j++) {
+      for (j = 0; j < choices.length; j++) {
         let newCheck = document.createElement("input");
         newCheck.setAttribute("type", "checkbox");
         newCheck.setAttribute("name", checkboxName);
         newCheck.setAttribute("value", j);
         if (oldAnswers && oldAnswers[i]) {
           for each (let an in oldAnswers[i]) {
             if (an == String(j)) {
               newCheck.setAttribute("checked", "true");
@@ -183,17 +186,17 @@ function drawSurveyForm(task, contentDiv
           }, false);
         let label = document.createElement("span");
         label.innerHTML = surveyQuestions[i].free_entry + "&nbsp:&nbsp";
         let inputBox = document.createElement("textarea");
         inputBox.setAttribute("id", freeformId);
         inputBox.addEventListener(
           "keypress", function() {
             let elements = document.getElementsByName(checkboxName);
-            for (let j = (elements.length - 1); j >= 0; j--) {
+            for (j = (elements.length - 1); j >= 0; j--) {
               if (elements[j].value == freeformId) {
                 elements[j].checked = true;
                 break;
               }
             }
           }, false);
         if (oldAnswers && oldAnswers[i]) {
           for each (let an in oldAnswers[i]) {
@@ -208,17 +211,17 @@ function drawSurveyForm(task, contentDiv
         contentDiv.appendChild(label);
         contentDiv.appendChild(inputBox);
       }
       break;
     case SCALE:
       let label = document.createElement("span");
       label.innerHTML = surveyQuestions[i].min_label;
       contentDiv.appendChild(label);
-      for (let j = surveyQuestions[i].scale_minimum;
+      for (j = surveyQuestions[i].scale_minimum;
            j <= surveyQuestions[i].scale_maximum;
            j++) {
         let newRadio = document.createElement("input");
         newRadio.setAttribute("type", "radio");
         newRadio.setAttribute("name", "answer_to_" + i);
         newRadio.setAttribute("value", j);
         if (oldAnswers && oldAnswers[i] == String(j)) {
           newRadio.setAttribute("checked", "true");
@@ -238,17 +241,17 @@ function drawSurveyForm(task, contentDiv
       }
       contentDiv.appendChild(inputBox);
       break;
     case MULTIPLE_CHOICE_WITH_FREE_ENTRY:
       let checked = false;
       let freeformId = "freeform_" + i;
       let radioName = "answer_to_" + i;
 
-      for (let j = 0; j < choices.length; j++) {
+      for (j = 0; j < choices.length; j++) {
         let newRadio = document.createElement("input");
         newRadio.setAttribute("type", "radio");
         newRadio.setAttribute("name", radioName);
         newRadio.setAttribute("value", j);
         newRadio.addEventListener(
           "click", function() {
             let inputBox = document.getElementById(freeformId);
             if (inputBox) {
--- a/browser/app/profile/extensions/testpilot@labs.mozilla.com/modules/tasks.js
+++ b/browser/app/profile/extensions/testpilot@labs.mozilla.com/modules/tasks.js
@@ -956,16 +956,17 @@ TestPilotBuiltinSurvey.prototype = {
                    surveyInfo.surveyName,
                    surveyInfo.surveyUrl,
                    surveyInfo.summary,
                    surveyInfo.thumbnail);
     this._studyId = surveyInfo.uploadWithExperiment; // what study do we belong to
     this._versionNumber = surveyInfo.versionNumber;
     this._questions = surveyInfo.surveyQuestions;
     this._explanation = surveyInfo.surveyExplanation;
+    this._onPageLoad = surveyInfo.onPageLoad;
   },
 
   get taskType() {
     return TaskConstants.TYPE_SURVEY;
   },
 
   get surveyExplanation() {
     return this._explanation;
@@ -983,16 +984,22 @@ TestPilotBuiltinSurvey.prototype = {
   get defaultUrl() {
     return this.currentStatusUrl;
   },
 
   get relatedStudyId() {
     return this._studyId;
   },
 
+  onPageLoad: function(task, document) {
+    if (this._onPageLoad) {
+      this._onPageLoad(task, document);
+    }
+  },
+
   onDetailPageOpened: function TPS_onDetailPageOpened() {
     if (this._status < TaskConstants.STATUS_IN_PROGRESS) {
       this.changeStatus( TaskConstants.STATUS_IN_PROGRESS, true );
     }
   },
 
   get oldAnswers() {
     let surveyResults =