- Timestamp:
- 07/21/11 14:51:50 (14 years ago)
- Location:
- Dev/trunk
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk/classes/SurveyCreationTool.php
r25 r29 9 9 class SurveyCreationTool { 10 10 11 private $survey; 12 private $timeStamp; 13 11 14 public function __construct($survey = null, $timeStamp = null) { 15 $this->survey = $survey; 16 $this->timeStamp = $timeStamp; 17 12 18 SurveyCreationTool::javascript(); 13 19 ?> … … 15 21 <div id="surveyCreation"><form id="survey" action="submitsurvey.php" method="post"> 16 22 <?php 17 SurveyCreationTool::surveyHead($timeStamp);18 SurveyCreationTool::questionCreationForm();23 $this->surveyHead(); 24 $this->questionCreationForm(); 19 25 SurveyCreationTool::addQuestionButton(); 20 26 SurveyCreationTool::removeLastQuestionButton(); … … 29 35 /* autosave every 3 minutes */ 30 36 setTimeout("save()", 180000); 31 37 32 38 var questionCount = 1; 33 39 34 40 function getNewQuestion() 35 41 { 42 36 43 var questionDiv = document.createElement("div"); 37 44 var htmlStr = … … 40 47 "<th>Question " + questionCount + "</th>" + 41 48 "<tr><td><label for='questionTitle'>Title</label></td>" + 42 "<td><input type='text' class='questionTitle' name='questionTitle" + questionCount + "' onfocus='handleFocus(this)' size='30' value=' Untitled Question' /></td></tr>" +49 "<td><input type='text' class='questionTitle' name='questionTitle" + questionCount + "' onfocus='handleFocus(this)' size='30' value='' /></td></tr>" + 43 50 "<tr><td><label for='questionDescription'>Description</label></td>" + 44 51 "<td><input type='text' class='questionDescription' name='questionDescription" + questionCount + "' onfocus='handleFocus(this)' size='60' value='Write a question description here.' /></td>" + … … 54 61 "<div id='answersDiv" + questionCount + "' class='answersDiv'></div>" + 55 62 "</div>"; 56 63 57 64 questionDiv.innerHTML = htmlStr; 58 65 59 66 return questionDiv; 60 67 } 61 68 62 69 function handleFocus(input) 63 70 { … … 69 76 } 70 77 } 71 78 72 79 function handleBlur(input) 73 80 { 74 81 var surveyTitle = document.getElementById('surveyTitle'); 75 82 var surveyDescription = document.getElementById('surveyDescription'); 76 83 77 84 if (input.value == "") 78 85 { 79 86 input.style.color = "gray"; 80 87 input.clicked = null; 81 88 82 89 if (input == surveyTitle) 83 90 { … … 90 97 } 91 98 } 92 99 93 100 function handleType(select) 94 101 { … … 97 104 answersDiv.answerCount = 1; 98 105 answersDiv.clicked = null; 99 106 100 107 switch (type) { 101 108 case 'mc': 102 109 answersDiv.innerHTML = ""; 103 110 addOption(select.id); 104 111 105 112 break; 106 113 case 'text': … … 126 133 127 134 } 128 129 135 136 130 137 function addOption(questionNumber) 131 138 { … … 134 141 var answerDiv = document.createElement("div"); 135 142 answerDiv.className = "answerDiv"; 136 143 137 144 var htmlStr = "<input type='text' name='q" + 138 145 questionNumber + "ans" + answerCount + "' value='Option " + answerCount + "' />"; 139 146 140 147 if (answersDiv.clicked == null) 141 148 { … … 143 150 + " class='surveyButton' onclick='addOption(" + questionNumber + ")' value='Add Option' />" + 144 151 "<input type='button' class='surveyButton' onclick='removeOption(" + questionNumber + ")' value='x' />"; 145 152 146 153 answersDiv.clicked = true; 147 154 } 148 155 149 156 answerDiv.innerHTML = htmlStr; 150 157 151 158 answerDiv.prev = answersDiv.lastAnswer; //singly linked list 152 159 answersDiv.lastAnswer = answerDiv; 153 160 154 161 answersDiv.appendChild(answerDiv); 155 162 answersDiv.answerCount++; 156 163 } 157 164 158 165 function removeOption(questionNumber) 159 166 { 160 167 var answersDiv = document.getElementById("answersDiv" + questionNumber); 161 168 162 169 if (answersDiv.lastAnswer.prev != null) 163 170 { … … 167 174 } 168 175 } 169 176 170 177 function minMax(questionNumber) 171 178 { 172 179 var answersDiv = document.getElementById("answersDiv" + questionNumber); 173 180 174 181 var answerDiv = document.createElement("div"); 175 182 176 183 answerDiv.className = "answerDiv"; 177 184 answerDiv.innerHTML = "<label for='min'>Min</label><input type='text' name='q" + questionNumber + "ans1' />" + 178 185 "<label for='max'>Max</label><input type='text' name='q" + questionNumber + "ans2' />"; 179 186 180 187 answersDiv.appendChild(answerDiv); 181 188 } 182 189 183 190 function minMaxIncr(questionNumber) 184 191 { 185 192 var answersDiv = document.getElementById("answersDiv" + questionNumber); 186 193 187 194 var answerDiv = document.createElement("div"); 188 195 answerDiv.className = "answerDiv"; 189 196 answerDiv.innerHTML = "<label>Left label</label><input type='text' name='q" + questionNumber + "ans1' />" + 190 197 "<label>Right label</label><input type='text' name='q" + questionNumber + "ans2' />" + 191 "<label>Scale count</label><input type='text' name='q" + questionNumber + "ans3' />"; 192 198 "<label>Scale count</label><input type='text' name='q" + questionNumber + "ans3' />" + 199 "<div id='inputCheckFeedback'" + questionNumber + ""; 200 193 201 answersDiv.appendChild(answerDiv); 194 202 } 195 196 197 function addQuestion( )203 204 205 function addQuestion(title, description) 198 206 { 199 207 var questionsDiv = document.getElementById('questionsDiv'); 200 var newQuestion = getNewQuestion( );201 208 var newQuestion = getNewQuestion(title, description); 209 202 210 203 211 newQuestion.prev = document.lastQuestion; … … 207 215 questionCount++; 208 216 } 209 217 210 218 function removeLastQuestion() 211 219 { 212 220 var questionsDiv = document.getElementById('questionsDiv'); 213 221 214 222 if (document.lastQuestion.prev != null) 215 223 { … … 223 231 } 224 232 } 225 226 function save( )233 234 function save(surveyID) 227 235 { 228 236 var form = document.getElementById('survey'); 229 237 var questionsDiv = document.getElementById('questionsDiv'); 230 238 form.action = "surveycreation.php"; 231 239 232 240 /* extra time stamp */ 233 241 var date = new Date(); … … 240 248 timeStampInput.value = timeStamp; 241 249 timeStampInput.type = "hidden"; 242 250 251 var surveyIDInput = document.createElement("input"); 252 surveyIDInput.name = "surveyID"; 253 surveyIDInput.value = surveyID; 254 surveyIDInput.type = "hidden"; 255 243 256 questionsDiv.appendChild(timeStampInput); 257 questionsDiv.appendChild(surveyIDInput); 244 258 form.submit(); 245 259 } 246 247 260 261 248 262 </script> 249 263 <?php 250 264 } 251 265 252 private static function surveyHead($timeStamp = null) {266 private function surveyHead() { 253 267 ?><div id="surveyHead"> 254 268 <?php 255 SurveyCreationTool::titleBox();256 SurveyCreationTool::saveSurvey($timeStamp);257 SurveyCreationTool::descriptionBox();269 $this->titleBox(); 270 $this->saveSurvey(); 271 $this->descriptionBox(); 258 272 ?></div> 259 273 <?php 260 274 } 261 275 262 private static function titleBox() { 263 ?> 264 <input type="text" id="surveyTitle" name="surveyTitle" value="Untitled Survey" onblur="handleBlur(this)" onfocus="handleFocus(this)" /> 265 <?php 266 } 267 268 private static function saveSurvey($timeStamp = null) { 269 if (isset($timeStamp)) 270 echo "<div id='timeStamp'>Last saved " . $timeStamp . '</div>'; 271 ?> 272 <input id="surveySaveButton" type="button" onclick="save()" class='surveyButton' value='Save' /> 273 <?php 274 } 275 276 private static function descriptionBox() { 277 ?> 278 <textarea id="surveyDescription" name="surveyDescription" onblur="handleBlur(this)" onfocus="handleFocus(this)">Write a helpful description for this survey here.</textarea> 279 <?php 280 } 281 282 private static function questionCreationForm() { 276 private function titleBox() { 277 if (isset($this->survey->title)) 278 $value = $this->survey->title; 279 else 280 $value = 'Untitled Survey'; 281 ?> 282 <input type="text" id="surveyTitle" name="surveyTitle" value="<?php echo $value ?>" onblur="handleBlur(this)" onfocus="handleFocus(this)" /> 283 <?php 284 } 285 286 private function saveSurvey() { 287 if (isset($this->timeStamp)) 288 echo "<div id='timeStamp'>Last saved " . $this->timeStamp . '</div>'; 289 if (isset($this->survey->id)) 290 $id = $this->survey->id; 291 else 292 $id = null; 293 ?> 294 <input id="surveySaveButton" type="button" onclick="save('<?php echo $id; ?>')" class='surveyButton' value='Save' /> 295 <?php 296 } 297 298 private function descriptionBox() { 299 if (isset($this->survey->description)) 300 $value = $this->survey->description; 301 else 302 $value = 'Write a helpful description for this survey here.'; 303 ?> 304 <textarea id="surveyDescription" name="surveyDescription" onblur="handleBlur(this)" onfocus="handleFocus(this)"><?php echo $value; ?></textarea> 305 <?php 306 } 307 308 private function questionCreationForm() { 283 309 ?> 284 310 <div id='questionsDiv'> 285 311 </div> 312 286 313 <script type="text/javascript"> addQuestion(); </script> 287 314 <?php -
Dev/trunk/css/style.css
r25 r29 147 147 148 148 .surveyButton { 149 150 149 color: #888; 151 150 font-weight: bold; 152 151 background-color: #fff; 153 152 border: 2px solid #aaa; 154 -moz-border-radius: 8px;155 border-radius: 8px;153 -moz-border-radius: 6px; 154 border-radius: 6px; 156 155 } 157 156 -
Dev/trunk/surveycreation.php
r28 r29 1 <?php require 'classes/master.php'; 1 <?php 2 require 'classes/master.php'; 3 4 $savedSurvey = null; 2 5 3 6 if (isset($_POST['timeStamp'])) … … 12 15 echo '<br/><br/>'; 13 16 var_dump($info); 17 18 $savedSurvey = Survey::getSurvey($info); 14 19 } 15 20 else { 16 21 $timeStamp = null; 17 22 } 18 19 23 20 24 ?> … … 31 35 <body> 32 36 <div id="header"> 33 34 37 <div id="logo">CPSFacilitator Tool </div> 38 </div> 35 39 <div id="wrapper"> 36 40 37 41 <div id="content"> 38 42 <?php 39 new SurveyCreationTool(null, $timeStamp); 43 44 new SurveyCreationTool($savedSurvey, $timeStamp); 40 45 ?> 41 46 </div>
Note: See TracChangeset
for help on using the changeset viewer.