Changeset 115 for Dev


Ignore:
Timestamp:
09/28/11 10:59:33 (14 years ago)
Author:
fpvanagthoven
Message:

The existing categories are now selectable

Location:
Dev/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/classes/QuestionCreationTool.php

    r114 r115  
    77 */
    88class QuestionCreationTool {
     9
    910    private $questions;
    10     private $questionEditPanel;
    1111
    1212    public function __construct($questions) {
     
    2424                var type = select.valueOf().value;
    2525                clearSpecifications();
    26                                                                        
     26                                                                               
    2727                /* set answerCount for options */
    2828                document.getElementById("answerSpecifications").answerCount = 1;
    29                                                                        
     29                                                                               
    3030                switch (type) {
    3131                    case "text":
     
    4444                        break;
    4545                    default:
    46                                                                                
     46                                                                                       
    4747                        break;
    4848                }
    4949
    5050            }
    51                                                                    
     51                                                                           
    5252            function clearSpecifications()
    5353            {
     
    5656                specs.clicked = null;
    5757                specs.lastAnswer = null;
    58                                                        
     58                                                               
    5959                var questionType = document.getElementById("questionType");
    6060                var buttons = document.getElementById("questionButtons");
     
    6262                    questionType.removeChild(buttons);
    6363            }
    64                                                                    
     64                                                                           
    6565            function addOption()
    6666            {                       
    6767                var specs = document.getElementById("answerSpecifications");
    68                                                                        
     68                                                                               
    6969                addAddRemoveOptionButtonsOnce(specs);
    7070                addAnswerInput(specs);
    71                                                                        
    72             }
    73                                                                    
     71                                                                               
     72            }
     73                                                                           
    7474            function removeOption()
    7575            {
    7676                var specs = document.getElementById("answerSpecifications");
    77                                                                        
     77                                                                               
    7878                if(specs.lastAnswer.prev != null)
    7979                {
     
    8383                }
    8484            }
    85                                                                    
     85                                                                           
    8686            function addAnswerInput(specs)
    8787            {
    8888                var answerCount = specs.answerCount;
    89                                                                        
     89                                                                               
    9090                /* set value for option textbox */
    9191                var optionStr = "Option " + answerCount;
    92                                                                        
     92                                                                               
    9393                /* the input textbox */
    9494                var answerInput = document.createElement("input");
     
    9797                answerInput.setAttribute("value", optionStr);
    9898                answerInput.className = "answerInput";
    99                                                                        
     99                                                                               
    100100                specs.appendChild(answerInput);
    101                                                                        
     101                                                                               
    102102                /* Singly linked list */
    103103                answerInput.prev = specs.lastAnswer; // remember last one
    104104                specs.lastAnswer = answerInput; // new lastAnswer
    105                                                                        
     105                                                                               
    106106                specs.answerCount++;               
    107107            }
    108                                                                    
     108                                                                           
    109109            function addAddRemoveOptionButtonsOnce(specs)
    110110            {
     
    116116                    var typeBox = document.getElementById("questionType");
    117117                    typeBox.appendChild(buttonsDiv);
    118                                                            
     118                                                                   
    119119                    addAddOptionButton(buttonsDiv);                                 
    120120                    addRemoveOptionButton(buttonsDiv);
    121                                                                            
     121                                                                                   
    122122                    specs.clicked = true;
    123123                }
    124124            }
    125                                                                    
     125                                                                           
    126126            function addAddOptionButton(buttonsDiv)
    127127            {   
     
    134134                buttonsDiv.appendChild(addOpt);                                 
    135135            }
    136                                                                    
     136                                                                           
    137137            function addRemoveOptionButton(buttonsDiv)
    138138            {
     
    144144                buttonsDiv.appendChild(removeOpt);
    145145            }
    146                                                                    
     146                                                                          
    147147            function minMax(min, max)
    148148            {
     
    151151                if (max == null)
    152152                    var max = '';
    153                                                                                                                                                                                                                                                                                                
     153                                                                                                                                                                                                                                                                                                       
    154154                var specs = document.getElementById("answerSpecifications");
    155                                                                                                                                                                                                                                                                                                                                                                                                                                        
     155                                                                                                                                                                                                                                                                                                                                                                                                                                              
    156156                var answerDiv = document.createElement("div");
    157                                                                                                                                                                                                                                                                                                                                                                                                        
     157                                                                                                                                                                                                                                                                                                                                                                                                               
    158158                answerDiv.className = "answerDiv";
    159159                answerDiv.innerHTML = "<label for='min'>Min</label><input type='text' class='intBox' onchange='checkInt(this)' value='" + min + "' name='ans1' />" +
    160160                    "<label for='max'>Max</label><input type='text' class='intBox' onchange='checkInt(this)' value='" + max + "' name='ans2' />";
    161                                                                                                                                                                                                                                                                                                                                                                                                                                    
     161                                                                                                                                                                                                                                                                                                                                                                                                                                          
    162162                specs.appendChild(answerDiv);
    163163            }     
    164                                            
     164                                                   
    165165            function checkInt(input)
    166166            {
     
    178178                }
    179179            }
    180                            
     180                                   
    181181            function minMaxIncr(left, right, incr)
    182182            {
     
    191191                if (incr == null)
    192192                    var incr = '';
    193                                                                                                                                                                                                                        
     193                                                                                                                                                                                                                               
    194194                var specs = document.getElementById("answerSpecifications");
    195                                                                                                                                                                                                                                                                                                                                                                                                                
     195                                                                                                                                                                                                                                                                                                                                                                                                                      
    196196                var answerDiv = document.createElement("div");
    197197                answerDiv.className = "answerDiv";
    198                                                                                                                                                
     198                                                                                                                                                      
    199199                var leftLabel = document.createElement("label");
    200200                var rightLabel = document.createElement("label");
     
    203203                rightLabel.innerHTML = "Right label";
    204204                scaleLabel.innerHTML = "Scale count";
    205                                                                                                                                                
     205                                                                                                                                                       
    206206                var leftInput = document.createElement("input");
    207207                leftInput.type = "text";
     
    209209                leftInput.name= "ans1";
    210210                leftInput.setAttribute("onchange", "handleAnswerChange()");
    211                                                                                                                                                
     211                                                                                                                                                       
    212212                var rightInput = document.createElement("input");
    213213                rightInput.type = "text";
     
    215215                rightInput.name = "ans2";
    216216                rightInput.setAttribute("onchange", "handleAnswerChange()");
    217                                                                                                                                                
     217                                                                                                                                                       
    218218                var scaleInput = document.createElement("input");
    219219                scaleInput.type = "text";
     
    223223                scaleInput.setAttribute("onchange", "");
    224224                scaleInput.name = "ans3";
    225                                                                                                                                                
     225                                                                                                                                                       
    226226                answerDiv.appendChild(leftLabel);
    227227                answerDiv.appendChild(leftInput);
     
    230230                answerDiv.appendChild(scaleLabel);
    231231                answerDiv.appendChild(scaleInput);
    232                                                                                                                                                                                                                                                                                                                                                                                            
     232                                                                                                                                                                                                                                                                                                                                                                                                  
    233233                specs.appendChild(answerDiv);
    234234            }   
    235            
     235                   
    236236            function newCategory()
    237237            {
    238238                var categoryBox = document.getElementById("categoryBox");
    239239                categoryBox.innerHTML = "";
    240                
     240                       
    241241                var categoryInput = document.createElement("input");
    242242                categoryInput.name = "questionCategory";
    243                
     243                       
    244244                categoryBox.appendChild(categoryInput);
    245245            }
    246                        
     246                              
    247247            function clearFields()
    248248            {
     
    253253                clearType();
    254254            }
    255            
     255                   
    256256            function clearCategory()
    257257            {
    258258                var categoryBox = document.getElementById("categoryBox");
    259259                categoryBox.innerHTML = "";
    260                
     260                       
    261261                var questionCategorySelect = document.createElement("select");
    262262                questionCategorySelect.setAttribute("name", "questionCategory");
    263263                questionCategorySelect.id = "questionCategorySelect";
    264                
     264                       
    265265                var newCategoryButton = document.createElement("input");
    266266                newCategoryButton.setAttribute("type", "button");
     
    268268                newCategoryButton.setAttribute("value", "New Category");
    269269                newCategoryButton.className = "surveyButton";
    270                
     270                       
    271271                categoryBox.appendChild(questionCategorySelect);
    272272                categoryBox.appendChild(newCategoryButton);
    273273            }
    274            
     274                   
    275275            function clearCode()
    276276            {
     
    278278                codeInput.value = "";
    279279            }
    280            
     280                   
    281281            function clearTitle()
    282282            {
     
    284284                titleInput.value ="";
    285285            }
    286            
     286                   
    287287            function clearDescription()
    288288            {
     
    290290                descriptionInput.value = "";
    291291            }
    292            
     292                   
    293293            function clearType()
    294294            {
     
    297297                clearSpecifications();
    298298            }
    299            
     299                   
    300300        </script>
    301301        <?php
     
    306306        <div id="questionListWrapper">
    307307            <select id="questionsList" size="9999">
    308                 <?php $this->populateList(); ?>
     308        <?php $this->populateList(); ?>
    309309            </select>
    310310        </div>
     
    315315        ?>
    316316        <div id="questionCreation" class="floatLeft">
    317             <?php $this->displayForm(); ?>
     317        <?php $this->displayForm(); ?>
    318318        </div>
    319319        <?php
     
    327327                    <td><label for="questionCategory">Category</label></td>
    328328                    <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(); ?>
    334330                    </td>
    335331                </tr>
     
    365361        <?php
    366362    }
     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    }
    367374   
    368     private function populateList()
     375    private function generateCategoryOptions()
    369376    {
    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) {
    372389            ?>
    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>
    376391        <?php
    377392        }
    378393    }
    379394
    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    ?>
  • Dev/trunk/questioncreation.php

    r114 r115  
    99
    1010$questions = Loader::loadFullQuestions();
    11 var_dump($questions);
    1211?>
    1312<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
Note: See TracChangeset for help on using the changeset viewer.