Changeset 71 for Dev/trunk/classes/SurveyCreationTool.php
- Timestamp:
- 08/03/11 22:20:43 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk/classes/SurveyCreationTool.php
r69 r71 15 15 $this->survey = $survey; 16 16 $this->timeStamp = $timeStamp; 17 17 var_dump($_POST); 18 var_dump($survey); 18 19 if (isset($this->survey->id)) 19 20 SurveyCreationTool::javascript($this->survey->id); … … 38 39 /* autosave every 3 minutes */ 39 40 setTimeout("save('<?php echo $id; ?>')", 180000); 40 41 41 42 var questionCount = 1; 42 43 43 44 function getNewQuestion(title, description) 44 45 { 45 46 if (title == null) 46 47 var title = 'Untitled Question'; 47 48 else { 49 title.replace("'", "'"); 50 } 51 48 52 if (description != null) 49 var description = description; 53 { 54 description.replace("'", "'"); 55 } 50 56 else 51 57 var description = 'Write a question description here.'; 52 58 53 59 var questionDiv = document.createElement("div"); 54 60 var htmlStr = … … 57 63 "<th>Question " + questionCount + "</th>" + 58 64 "<tr><td><label for='questionTitle'>Title</label></td>" + 59 "<td><input type='text' class='questionTitle' name='questionTitle" + questionCount + "' onfocus='handleFocus(this)' size='30' value='" + title + "' /></td></tr>" +65 "<td><input id='questionTitle' type='text' class='questionTitle' name='questionTitle" + questionCount + "' onfocus='handleFocus(this)' size='30' /></td></tr>" + 60 66 "<tr><td><label for='questionDescription'>Description</label></td>" + 61 67 "<td><input type='text' class='questionDescription' name='questionDescription" + questionCount + "' onfocus='handleFocus(this)' size='60' value='" + description + "' /></td>" + … … 71 77 "<div id='answersDiv" + questionCount + "' class='answersDiv'></div>" + 72 78 "</div>"; 73 79 80 /* TODO: get rid of innerHTML bullshit and do dynamically so that ' will work */ 81 74 82 questionDiv.innerHTML = htmlStr; 75 83 76 84 return questionDiv; 77 85 } 78 86 79 87 function handleType(select, answers) 80 88 { … … 82 90 var type = select.valueOf().value; 83 91 var answersDiv = document.getElementById("answersDiv" + numQ ); 84 92 85 93 removeQuestionID(numQ); 86 94 87 95 answersDiv.answerCount = 1; 88 96 answersDiv.clicked = null; 89 97 90 98 switch (type) { 91 99 case 'mc': … … 100 108 else 101 109 addOption(numQ); 102 110 103 111 break; 104 112 case 'text': … … 107 115 case 'int': 108 116 answersDiv.innerHTML = ""; 109 117 110 118 //min max 111 119 if (answers != null) … … 139 147 140 148 } 141 149 142 150 function handleAnswerChange(questionNumber) 143 151 { 144 152 removeQuestionID(questionNumber); 145 153 } 146 154 147 155 function removeQuestionID(questionNumber) 148 156 { … … 156 164 157 165 } 158 159 166 167 160 168 function addOption(questionNumber, optionStr) 161 169 { … … 163 171 var answerCount = answersDiv.answerCount; 164 172 var answerDiv = document.createElement("div"); 165 173 166 174 if (optionStr == null) 167 175 var optionStr = "Option " + answerCount; 168 169 176 177 170 178 answerDiv.className = "answerDiv"; 171 179 172 180 var htmlStr = "<input type='text' name='q" + 173 181 questionNumber + "ans" + answerCount + "' onchange='handleAnswerChange(" + questionNumber + ")' value='" + optionStr + "' />"; 174 182 175 183 if (answersDiv.clicked == null) 176 184 { … … 178 186 + " class='surveyButton' onclick='addOption(" + questionNumber + ")' value='Add Option' />" + 179 187 "<input type='button' class='surveyButton' onclick='removeOption(" + questionNumber + ")' value='x' />"; 180 188 181 189 answersDiv.clicked = true; 182 190 } 183 191 184 192 answerDiv.innerHTML = htmlStr; 185 193 186 194 answerDiv.prev = answersDiv.lastAnswer; //singly linked list 187 195 answersDiv.lastAnswer = answerDiv; 188 196 189 197 answersDiv.appendChild(answerDiv); 190 198 answersDiv.answerCount++; 191 199 192 200 handleAnswerChange(questionNumber); 193 201 } 194 202 195 203 function removeOption(questionNumber) 196 204 { 197 205 var answersDiv = document.getElementById("answersDiv" + questionNumber); 198 206 199 207 if (answersDiv.lastAnswer.prev != null) 200 208 { … … 203 211 answersDiv.answerCount--; 204 212 } 205 213 206 214 handleAnswerChange(questionNumber); 207 215 } 208 216 209 217 function minMax(questionNumber, min, max) 210 218 { … … 213 221 if (max == null) 214 222 var max = ''; 215 223 216 224 var answersDiv = document.getElementById("answersDiv" + questionNumber); 217 225 218 226 var answerDiv = document.createElement("div"); 219 227 220 228 answerDiv.className = "answerDiv"; 221 229 answerDiv.innerHTML = "<label for='min'>Min</label><input type='text' class='intBox' onchange='checkInt(this)' value='" + min + "' name='q" + questionNumber + "ans1' />" + 222 230 "<label for='max'>Max</label><input type='text' class='intBox' onchange='checkInt(this)' value='" + max + "' name='q" + questionNumber + "ans2' />"; 223 231 224 232 answersDiv.appendChild(answerDiv); 225 233 } 226 234 227 235 function minMaxIncr(questionNumber, left, right, incr) 228 236 { 229 237 if (left == null) 230 238 var left = ''; 239 else 240 left.replace("'", "'"); 231 241 if (right == null) 232 242 var right = ''; 243 else 244 right.replace("'", "'"); 233 245 if (incr == null) 234 246 var incr = ''; 235 247 236 248 var answersDiv = document.getElementById("answersDiv" + questionNumber); 237 249 238 250 var answerDiv = document.createElement("div"); 239 251 answerDiv.className = "answerDiv"; 240 answerDiv.innerHTML = "<label>Left label</label><input type='text' value='" + left + "' onchange='handleAnswerChange(" + questionNumber + ")' name='q" + questionNumber + "ans1' />" + 241 "<label>Right label</label><input type='text' value='" + right + "' onchange='handleAnswerChange(" + questionNumber + ")' name='q" + questionNumber + "ans2' />" + 242 "<label>Scale count</label><input type='text' class='intBox' value='" + incr + "' onblur='checkInt(this)' onchange='handleAnswerChange(" + questionNumber + ")' name='q" + questionNumber + "ans3' />" + 243 "<div id='inputCheckFeedback'" + questionNumber + ""; 244 252 253 var leftLabel = document.createElement("label"); 254 var rightLabel = document.createElement("label"); 255 var scaleLabel = document.createElement("label"); 256 leftLabel.innerHTML = "Left label"; 257 rightLabel.innerHTML = "Right label"; 258 scaleLabel.innerHTML = "Scale count"; 259 260 var leftInput = document.createElement("input"); 261 leftInput.type = "text"; 262 leftInput.value = left; 263 leftInput.name= "q" + questionNumber + "ans1"; 264 leftInput.setAttribute("onchange", "handleAnswerChange(" 265 + questionNumber + ")"); 266 267 var rightInput = document.createElement("input"); 268 rightInput.type = "text"; 269 rightInput.value = right; 270 rightInput.name = "q" + questionNumber + "ans2"; 271 rightInput.setAttribute("onchange", "handleAnswerChange(" 272 + questionNumber + ")"); 273 274 var scaleInput = document.createElement("input"); 275 scaleInput.type = "text"; 276 scaleInput.className = "intBox"; 277 scaleInput.value = incr; 278 scaleInput.setAttribute("onblur", "checkInt(this)"); 279 scaleInput.setAttribute("onchange", "handleAnswerChange(" 280 + questionNumber + ")"); 281 282 answerDiv.appendChild(leftLabel); 283 answerDiv.appendChild(leftInput); 284 answerDiv.appendChild(rightLabel); 285 answerDiv.appendChild(rightInput); 286 answerDiv.appendChild(scaleLabel); 287 answerDiv.appendChild(scaleInput); 288 245 289 answersDiv.appendChild(answerDiv); 246 290 } 247 248 291 292 249 293 function addQuestion(title, description) 250 294 { 251 295 var questionsDiv = document.getElementById('questionsDiv'); 252 296 var newQuestion = getNewQuestion(title, description); 253 297 254 298 255 299 newQuestion.prev = document.lastQuestion; … … 259 303 questionCount++; 260 304 } 261 305 262 306 function removeLastQuestion() 263 307 { 264 308 var questionsDiv = document.getElementById('questionsDiv'); 265 309 266 310 if (document.lastQuestion.prev != null) 267 311 { … … 275 319 } 276 320 } 277 321 278 322 function save(surveyID) 279 323 { … … 283 327 var questionsDiv = document.getElementById('questionsDiv'); 284 328 form.action = "surveycreation.php"; 285 329 286 330 /* extra time stamp */ 287 331 var date = new Date(); … … 294 338 timeStampInput.value = timeStamp; 295 339 timeStampInput.type = "hidden"; 296 340 297 341 var surveyIDInput = document.createElement("input"); 298 342 surveyIDInput.name = "surveyID"; 299 343 surveyIDInput.value = surveyID; 300 344 surveyIDInput.type = "hidden"; 301 345 302 346 questionsDiv.appendChild(timeStampInput); 303 347 questionsDiv.appendChild(surveyIDInput); … … 305 349 } 306 350 } 307 351 308 352 function selectAll(input) 309 353 { 310 354 input.select(); 311 355 } 312 356 313 357 /* --- input checking --- */ 314 358 function checksPassed() 315 359 { 316 360 var form = document.getElementById('survey'); 317 361 318 362 for (var i = 0; i < form.length; i++) 319 363 { … … 323 367 return true; 324 368 } 325 369 326 370 function checkInt(input) 327 371 { … … 339 383 } 340 384 } 341 385 342 386 </script> 343 387 <?php … … 412 456 /* Put all answers in js array */ 413 457 foreach ($question->answers as $numA => $answer) { 414 echo "answers[" . $numA . "] = '" . $answer . "'; "; 458 echo 'answers[' . $numA . '] = "' . $answer . '"; '; 459 ?> 460 461 <?php 415 462 } 416 463 ?> 417 418 addQuestion( '<?php echo $question->title; ?>', '<?php echo $question->description; ?>');419 464 var title = "<?php echo $question->title; ?>"; 465 addQuestion(title, "<?php echo $question->description; ?>"); 466 420 467 var select = document.getElementById('<?php echo $numQ; ?>'); 421 468 var type = '<?php echo $question->type; ?>'; … … 425 472 { 426 473 select.options[i].selected = true; 427 handleType(select, answers) 474 handleType(select, answers); 428 475 break; 429 476 } 430 477 } 431 432 478 479 433 480 /* questionID stuff */ 434 481 var questionIDInput = document.createElement("input"); … … 437 484 questionIDInput.value = "<?php echo $question->id; ?>"; 438 485 questionIDInput.type = "hidden"; 439 486 440 487 document.getElementById("questionsDiv").appendChild(questionIDInput); 441 488
Note: See TracChangeset
for help on using the changeset viewer.