Changeset 115 for Dev/trunk/classes/QuestionCreationTool.php
- Timestamp:
- 09/28/11 10:59:33 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk/classes/QuestionCreationTool.php
r114 r115 7 7 */ 8 8 class QuestionCreationTool { 9 9 10 private $questions; 10 private $questionEditPanel;11 11 12 12 public function __construct($questions) { … … 24 24 var type = select.valueOf().value; 25 25 clearSpecifications(); 26 26 27 27 /* set answerCount for options */ 28 28 document.getElementById("answerSpecifications").answerCount = 1; 29 29 30 30 switch (type) { 31 31 case "text": … … 44 44 break; 45 45 default: 46 46 47 47 break; 48 48 } 49 49 50 50 } 51 51 52 52 function clearSpecifications() 53 53 { … … 56 56 specs.clicked = null; 57 57 specs.lastAnswer = null; 58 58 59 59 var questionType = document.getElementById("questionType"); 60 60 var buttons = document.getElementById("questionButtons"); … … 62 62 questionType.removeChild(buttons); 63 63 } 64 64 65 65 function addOption() 66 66 { 67 67 var specs = document.getElementById("answerSpecifications"); 68 68 69 69 addAddRemoveOptionButtonsOnce(specs); 70 70 addAnswerInput(specs); 71 72 } 73 71 72 } 73 74 74 function removeOption() 75 75 { 76 76 var specs = document.getElementById("answerSpecifications"); 77 77 78 78 if(specs.lastAnswer.prev != null) 79 79 { … … 83 83 } 84 84 } 85 85 86 86 function addAnswerInput(specs) 87 87 { 88 88 var answerCount = specs.answerCount; 89 89 90 90 /* set value for option textbox */ 91 91 var optionStr = "Option " + answerCount; 92 92 93 93 /* the input textbox */ 94 94 var answerInput = document.createElement("input"); … … 97 97 answerInput.setAttribute("value", optionStr); 98 98 answerInput.className = "answerInput"; 99 99 100 100 specs.appendChild(answerInput); 101 101 102 102 /* Singly linked list */ 103 103 answerInput.prev = specs.lastAnswer; // remember last one 104 104 specs.lastAnswer = answerInput; // new lastAnswer 105 105 106 106 specs.answerCount++; 107 107 } 108 108 109 109 function addAddRemoveOptionButtonsOnce(specs) 110 110 { … … 116 116 var typeBox = document.getElementById("questionType"); 117 117 typeBox.appendChild(buttonsDiv); 118 118 119 119 addAddOptionButton(buttonsDiv); 120 120 addRemoveOptionButton(buttonsDiv); 121 121 122 122 specs.clicked = true; 123 123 } 124 124 } 125 125 126 126 function addAddOptionButton(buttonsDiv) 127 127 { … … 134 134 buttonsDiv.appendChild(addOpt); 135 135 } 136 136 137 137 function addRemoveOptionButton(buttonsDiv) 138 138 { … … 144 144 buttonsDiv.appendChild(removeOpt); 145 145 } 146 146 147 147 function minMax(min, max) 148 148 { … … 151 151 if (max == null) 152 152 var max = ''; 153 153 154 154 var specs = document.getElementById("answerSpecifications"); 155 155 156 156 var answerDiv = document.createElement("div"); 157 157 158 158 answerDiv.className = "answerDiv"; 159 159 answerDiv.innerHTML = "<label for='min'>Min</label><input type='text' class='intBox' onchange='checkInt(this)' value='" + min + "' name='ans1' />" + 160 160 "<label for='max'>Max</label><input type='text' class='intBox' onchange='checkInt(this)' value='" + max + "' name='ans2' />"; 161 161 162 162 specs.appendChild(answerDiv); 163 163 } 164 164 165 165 function checkInt(input) 166 166 { … … 178 178 } 179 179 } 180 180 181 181 function minMaxIncr(left, right, incr) 182 182 { … … 191 191 if (incr == null) 192 192 var incr = ''; 193 193 194 194 var specs = document.getElementById("answerSpecifications"); 195 195 196 196 var answerDiv = document.createElement("div"); 197 197 answerDiv.className = "answerDiv"; 198 198 199 199 var leftLabel = document.createElement("label"); 200 200 var rightLabel = document.createElement("label"); … … 203 203 rightLabel.innerHTML = "Right label"; 204 204 scaleLabel.innerHTML = "Scale count"; 205 205 206 206 var leftInput = document.createElement("input"); 207 207 leftInput.type = "text"; … … 209 209 leftInput.name= "ans1"; 210 210 leftInput.setAttribute("onchange", "handleAnswerChange()"); 211 211 212 212 var rightInput = document.createElement("input"); 213 213 rightInput.type = "text"; … … 215 215 rightInput.name = "ans2"; 216 216 rightInput.setAttribute("onchange", "handleAnswerChange()"); 217 217 218 218 var scaleInput = document.createElement("input"); 219 219 scaleInput.type = "text"; … … 223 223 scaleInput.setAttribute("onchange", ""); 224 224 scaleInput.name = "ans3"; 225 225 226 226 answerDiv.appendChild(leftLabel); 227 227 answerDiv.appendChild(leftInput); … … 230 230 answerDiv.appendChild(scaleLabel); 231 231 answerDiv.appendChild(scaleInput); 232 232 233 233 specs.appendChild(answerDiv); 234 234 } 235 235 236 236 function newCategory() 237 237 { 238 238 var categoryBox = document.getElementById("categoryBox"); 239 239 categoryBox.innerHTML = ""; 240 240 241 241 var categoryInput = document.createElement("input"); 242 242 categoryInput.name = "questionCategory"; 243 243 244 244 categoryBox.appendChild(categoryInput); 245 245 } 246 246 247 247 function clearFields() 248 248 { … … 253 253 clearType(); 254 254 } 255 255 256 256 function clearCategory() 257 257 { 258 258 var categoryBox = document.getElementById("categoryBox"); 259 259 categoryBox.innerHTML = ""; 260 260 261 261 var questionCategorySelect = document.createElement("select"); 262 262 questionCategorySelect.setAttribute("name", "questionCategory"); 263 263 questionCategorySelect.id = "questionCategorySelect"; 264 264 265 265 var newCategoryButton = document.createElement("input"); 266 266 newCategoryButton.setAttribute("type", "button"); … … 268 268 newCategoryButton.setAttribute("value", "New Category"); 269 269 newCategoryButton.className = "surveyButton"; 270 270 271 271 categoryBox.appendChild(questionCategorySelect); 272 272 categoryBox.appendChild(newCategoryButton); 273 273 } 274 274 275 275 function clearCode() 276 276 { … … 278 278 codeInput.value = ""; 279 279 } 280 280 281 281 function clearTitle() 282 282 { … … 284 284 titleInput.value =""; 285 285 } 286 286 287 287 function clearDescription() 288 288 { … … 290 290 descriptionInput.value = ""; 291 291 } 292 292 293 293 function clearType() 294 294 { … … 297 297 clearSpecifications(); 298 298 } 299 299 300 300 </script> 301 301 <?php … … 306 306 <div id="questionListWrapper"> 307 307 <select id="questionsList" size="9999"> 308 308 <?php $this->populateList(); ?> 309 309 </select> 310 310 </div> … … 315 315 ?> 316 316 <div id="questionCreation" class="floatLeft"> 317 317 <?php $this->displayForm(); ?> 318 318 </div> 319 319 <?php … … 327 327 <td><label for="questionCategory">Category</label></td> 328 328 <td id="categoryBox"><!-- Select should be filled with existing categories--> 329 <select id="questionCategorySelect" name="questionCategory"> 330 <option value='Uncategorized' selected='selected'>Uncategorized</option> 331 </select> 332 <!-- New category button --> 333 <input type="button" class="surveyButton" onclick="newCategory()" value="New Category" /> 329 <?php $this->questionCategorySelect(); ?> 334 330 </td> 335 331 </tr> … … 365 361 <?php 366 362 } 363 364 private function questionCategorySelect() { 365 ?> 366 <select id="questionCategorySelect" name="questionCategory"> 367 <option value='Uncategorized' selected='selected'>Uncategorized</option> 368 <?php $this->generateCategoryOptions(); ?> 369 </select> 370 <!-- New category button --> 371 <input type="button" class="surveyButton" onclick="newCategory()" value="New Category" /> 372 <?php 373 } 367 374 368 private function populateList()375 private function generateCategoryOptions() 369 376 { 370 foreach ($this->questions as $question) 371 { 377 $categories = array(); 378 379 foreach ($this->questions as $question) { 380 $category = $question->category; 381 if (! array_search($category, $categories)) // if not in categories 382 { 383 array_push($categories, $category); 384 } 385 } 386 387 // You might want to escape quotes and stuff here 388 foreach ($categories as $category) { 372 389 ?> 373 <option value="<?php echo $question->code; ?>"> 374 <?php echo $question->code . " - " . $question->title; ?> 375 </option> 390 <option value="<?php echo $category;?>"><?php echo $category; ?></option> 376 391 <?php 377 392 } 378 393 } 379 394 380 } 381 ?> 395 private function populateList() { 396 foreach ($this->questions as $question) { 397 ?> 398 <option value="<?php echo $question->code; ?>"> 399 <?php echo $question->code . " - " . $question->title; ?> 400 </option> 401 <?php 402 } 403 } 404 405 } 406 ?>
Note: See TracChangeset
for help on using the changeset viewer.