Changeset 53
- Timestamp:
- 07/26/11 15:02:58 (14 years ago)
- Location:
- Dev/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk/classes/SurveyCreationTool.php
r50 r53 37 37 /* autosave every 3 minutes */ 38 38 setTimeout("save('<?php echo $id; ?>')", 180000); 39 39 40 40 var questionCount = 1; 41 41 42 42 function getNewQuestion(title, description) 43 43 { 44 44 if (title == null) 45 45 var title = 'Untitled Question'; 46 46 47 47 if (description != null) 48 48 var description = description; 49 49 else 50 50 var description = 'Write a question description here.'; 51 51 52 52 var questionDiv = document.createElement("div"); 53 53 var htmlStr = … … 70 70 "<div id='answersDiv" + questionCount + "' class='answersDiv'></div>" + 71 71 "</div>"; 72 72 73 73 questionDiv.innerHTML = htmlStr; 74 74 75 75 return questionDiv; 76 76 } 77 77 78 78 function handleFocus(input) 79 79 { … … 90 90 } 91 91 } 92 92 93 93 function handleBlur(input) 94 94 { 95 95 var surveyTitle = document.getElementById('surveyTitle'); 96 96 var surveyDescription = document.getElementById('surveyDescription'); 97 97 98 98 if (input.value == "") 99 99 { 100 100 input.style.color = "gray"; 101 101 input.clicked = null; 102 102 103 103 if (input == surveyTitle) 104 104 { … … 111 111 } 112 112 } 113 113 114 114 function handleType(select, answers) 115 115 { … … 117 117 var type = select.valueOf().value; 118 118 var answersDiv = document.getElementById("answersDiv" + numQ ); 119 119 120 120 removeQuestionID(numQ); 121 121 122 122 answersDiv.answerCount = 1; 123 123 answersDiv.clicked = null; 124 124 125 125 switch (type) { 126 126 case 'mc': … … 135 135 else 136 136 addOption(numQ); 137 137 138 138 break; 139 139 case 'text': … … 142 142 case 'int': 143 143 answersDiv.innerHTML = ""; 144 144 145 145 //min max 146 146 if (answers != null) … … 174 174 175 175 } 176 176 177 177 function handleAnswerChange(questionNumber) 178 178 { 179 179 removeQuestionID(questionNumber); 180 180 } 181 181 182 182 function removeQuestionID(questionNumber) 183 183 { … … 191 191 192 192 } 193 194 193 194 195 195 function addOption(questionNumber, optionStr) 196 196 { … … 198 198 var answerCount = answersDiv.answerCount; 199 199 var answerDiv = document.createElement("div"); 200 200 201 201 if (optionStr == null) 202 202 var optionStr = "Option " + answerCount; 203 204 203 204 205 205 answerDiv.className = "answerDiv"; 206 206 207 207 var htmlStr = "<input type='text' name='q" + 208 208 questionNumber + "ans" + answerCount + "' onchange='handleAnswerChange(" + questionNumber + ")' value='" + optionStr + "' />"; 209 209 210 210 if (answersDiv.clicked == null) 211 211 { … … 213 213 + " class='surveyButton' onclick='addOption(" + questionNumber + ")' value='Add Option' />" + 214 214 "<input type='button' class='surveyButton' onclick='removeOption(" + questionNumber + ")' value='x' />"; 215 215 216 216 answersDiv.clicked = true; 217 217 } 218 218 219 219 answerDiv.innerHTML = htmlStr; 220 220 221 221 answerDiv.prev = answersDiv.lastAnswer; //singly linked list 222 222 answersDiv.lastAnswer = answerDiv; 223 223 224 224 answersDiv.appendChild(answerDiv); 225 225 answersDiv.answerCount++; 226 226 227 227 handleAnswerChange(questionNumber); 228 228 } 229 229 230 230 function removeOption(questionNumber) 231 231 { 232 232 var answersDiv = document.getElementById("answersDiv" + questionNumber); 233 233 234 234 if (answersDiv.lastAnswer.prev != null) 235 235 { … … 238 238 answersDiv.answerCount--; 239 239 } 240 240 241 241 handleAnswerChange(questionNumber); 242 242 } 243 243 244 244 function minMax(questionNumber, min, max) 245 245 { … … 248 248 if (max == null) 249 249 var max = ''; 250 250 251 251 var answersDiv = document.getElementById("answersDiv" + questionNumber); 252 252 253 253 var answerDiv = document.createElement("div"); 254 254 255 255 answerDiv.className = "answerDiv"; 256 answerDiv.innerHTML = "<label for='min'>Min</label><input type='text' value='" + min + "' name='q" + questionNumber + "ans1' />" +257 "<label for='max'>Max</label><input type='text' value='" + max + "' name='q" + questionNumber + "ans2' />";258 256 answerDiv.innerHTML = "<label for='min'>Min</label><input type='text' class='intBox' onchange='checkInt(this)' value='" + min + "' name='q" + questionNumber + "ans1' />" + 257 "<label for='max'>Max</label><input type='text' class='intBox' onchange='checkInt(this)' value='" + max + "' name='q" + questionNumber + "ans2' />"; 258 259 259 answersDiv.appendChild(answerDiv); 260 260 } 261 261 262 262 function minMaxIncr(questionNumber, left, right, incr) 263 263 { … … 268 268 if (incr == null) 269 269 var incr = ''; 270 270 271 271 var answersDiv = document.getElementById("answersDiv" + questionNumber); 272 272 273 273 var answerDiv = document.createElement("div"); 274 274 answerDiv.className = "answerDiv"; 275 275 answerDiv.innerHTML = "<label>Left label</label><input type='text' value='" + left + "' onchange='handleAnswerChange(" + questionNumber + ")' name='q" + questionNumber + "ans1' />" + 276 276 "<label>Right label</label><input type='text' value='" + right + "' onchange='handleAnswerChange(" + questionNumber + ")' name='q" + questionNumber + "ans2' />" + 277 "<label>Scale count</label><input type='text' value='" + incr + "' onchange='handleAnswerChange(" + questionNumber + ")' name='q" + questionNumber + "ans3' />" +277 "<label>Scale count</label><input type='text' class='intBox' value='" + incr + "' onblur='checkInt(this)' onchange='handleAnswerChange(" + questionNumber + ")' name='q" + questionNumber + "ans3' />" + 278 278 "<div id='inputCheckFeedback'" + questionNumber + ""; 279 279 280 280 answersDiv.appendChild(answerDiv); 281 281 } 282 283 282 283 284 284 function addQuestion(title, description) 285 285 { 286 286 var questionsDiv = document.getElementById('questionsDiv'); 287 287 var newQuestion = getNewQuestion(title, description); 288 288 289 289 290 290 newQuestion.prev = document.lastQuestion; … … 294 294 questionCount++; 295 295 } 296 296 297 297 function removeLastQuestion() 298 298 { 299 299 var questionsDiv = document.getElementById('questionsDiv'); 300 300 301 301 if (document.lastQuestion.prev != null) 302 302 { … … 310 310 } 311 311 } 312 312 313 313 function save(surveyID) 314 314 { 315 if (checksPassed()) 316 { 317 var form = document.getElementById('survey'); 318 var questionsDiv = document.getElementById('questionsDiv'); 319 form.action = "surveycreation.php"; 320 321 /* extra time stamp */ 322 var date = new Date(); 323 var minutes = date.getUTCMinutes(); 324 if (minutes < 10) 325 minutes = "0" + minutes; 326 var timeStamp = date.getHours() + ":" + minutes; 327 var timeStampInput = document.createElement("input"); 328 timeStampInput.name = "timeStamp"; 329 timeStampInput.value = timeStamp; 330 timeStampInput.type = "hidden"; 331 332 var surveyIDInput = document.createElement("input"); 333 surveyIDInput.name = "surveyID"; 334 surveyIDInput.value = surveyID; 335 surveyIDInput.type = "hidden"; 336 337 questionsDiv.appendChild(timeStampInput); 338 questionsDiv.appendChild(surveyIDInput); 339 form.submit(); 340 } 341 } 342 343 function selectAll(input) 344 { 345 input.select(); 346 } 347 348 /* --- input checking --- */ 349 function checksPassed() 350 { 315 351 var form = document.getElementById('survey'); 316 var questionsDiv = document.getElementById('questionsDiv'); 317 form.action = "surveycreation.php"; 318 319 /* extra time stamp */ 320 var date = new Date(); 321 var minutes = date.getUTCMinutes(); 322 if (minutes < 10) 323 minutes = "0" + minutes; 324 var timeStamp = date.getHours() + ":" + minutes; 325 var timeStampInput = document.createElement("input"); 326 timeStampInput.name = "timeStamp"; 327 timeStampInput.value = timeStamp; 328 timeStampInput.type = "hidden"; 329 330 var surveyIDInput = document.createElement("input"); 331 surveyIDInput.name = "surveyID"; 332 surveyIDInput.value = surveyID; 333 surveyIDInput.type = "hidden"; 334 335 questionsDiv.appendChild(timeStampInput); 336 questionsDiv.appendChild(surveyIDInput); 337 form.submit(); 338 } 339 340 function selectAll(input) 341 { 342 input.select(); 343 } 344 352 353 for (var i = 0; i < form.length; i++) 354 { 355 if (form.elements[i].checkPassed == 'no') 356 return false; 357 } 358 return true; 359 } 360 361 function checkInt(input) 362 { 363 input.style.borderWidth = '1px' ; 364 var value = input.value; 365 if (isNaN(value)) 366 { 367 input.style.borderColor = 'red'; 368 input.checkPassed = 'no'; 369 } 370 else 371 { 372 input.style.border = '1px solid #abadb3'; 373 input.checkPassed = null; 374 } 375 } 376 377 345 378 </script> 346 379 <?php … … 389 422 <?php 390 423 } 391 424 392 425 private function surveyLink() { 393 if (isset($this->survey)) 394 { 395 $surveyID = $this->survey->id; 396 397 $link = $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . 426 if (isset($this->survey)) { 427 $surveyID = $this->survey->id; 428 429 $link = $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . 398 430 '/survey.php?id=' . $surveyID; 399 ?>400 <input type="text" value="<?php echo $link; ?>" id="surveyLink" onclick="selectAll(this)">401 <?php431 ?> 432 <input type="text" value="<?php echo $link; ?>" id="surveyLink" onclick="selectAll(this)"> 433 <?php 402 434 } 403 435 } … … 419 451 } 420 452 ?> 421 453 422 454 addQuestion('<?php echo $question->title; ?>', '<?php echo $question->description; ?>'); 423 455 424 456 var select = document.getElementById('<?php echo $numQ; ?>'); 425 457 var type = '<?php echo $question->type; ?>'; … … 433 465 } 434 466 } 435 436 467 468 437 469 /* questionID stuff */ 438 470 var questionIDInput = document.createElement("input"); … … 441 473 questionIDInput.value = "<?php echo $question->id; ?>"; 442 474 questionIDInput.type = "hidden"; 443 475 444 476 document.getElementById("questionsDiv").appendChild(questionIDInput); 445 477 -
Dev/trunk/css/style.css
r52 r53 17 17 color: #333; 18 18 text-shadow: #fff 0px 0px 10px; 19 margin: 0 0 0. 5em 0;19 margin: 0 0 0.1em 0; 20 20 } 21 21 … … 272 272 273 273 .centerBoxed { 274 margin: 0auto;274 margin: 1em auto; 275 275 width: 30em; 276 276 text-align: center; 277 277 padding: 0 1em; 278 font-size: small; 278 279 /* border: 1px solid gray;*/ 279 280 } … … 292 293 .intBox { 293 294 width: 5em; 295 margin: 0 .3em; 296 border: 1px solid #abadb3; 294 297 } 295 298
Note: See TracChangeset
for help on using the changeset viewer.