Bug 658598: Test Pilot surveys should be able to run code on pageLoad like studies can. r=dtownsend DONTBUILD

This commit is contained in:
Jono S Xia 2011-05-23 11:57:07 -07:00
Родитель d75c57de1c
Коммит 3705805b96
2 изменённых файлов: 16 добавлений и 6 удалений

Просмотреть файл

@ -91,6 +91,9 @@ function onBuiltinSurveyLoad() {
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);
}
}
@ -114,7 +117,7 @@ function drawSurveyForm(task, contentDiv) {
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;
@ -129,7 +132,7 @@ function drawSurveyForm(task, contentDiv) {
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);
@ -148,7 +151,7 @@ function drawSurveyForm(task, contentDiv) {
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);
@ -188,7 +191,7 @@ function drawSurveyForm(task, contentDiv) {
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;
@ -213,7 +216,7 @@ function drawSurveyForm(task, contentDiv) {
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");
@ -243,7 +246,7 @@ function drawSurveyForm(task, contentDiv) {
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);

Просмотреть файл

@ -961,6 +961,7 @@ TestPilotBuiltinSurvey.prototype = {
this._versionNumber = surveyInfo.versionNumber;
this._questions = surveyInfo.surveyQuestions;
this._explanation = surveyInfo.surveyExplanation;
this._onPageLoad = surveyInfo.onPageLoad;
},
get taskType() {
@ -988,6 +989,12 @@ TestPilotBuiltinSurvey.prototype = {
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 );