Changeset 19 for Dev/trunk/classes


Ignore:
Timestamp:
07/18/11 17:16:31 (14 years ago)
Author:
fpvanagthoven
Message:

Now able to delete last question. Scale implemented with incr.

File:
1 edited

Legend:

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

    r18 r19  
    1919                SurveyCreationTool::questionCreationForm();
    2020                SurveyCreationTool::addQuestionButton();
     21                SurveyCreationTool::removeLastQuestionButton();
    2122                SurveyCreationTool::submitButton();
    2223                ?></form></div>
     
    2829        <script type="text/javascript">
    2930            var questionCount = 1;           
    30                                                                                    
     31                                                                                                           
    3132            function getNewQuestion()
    3233            {
     
    5152                    "<div id='answersDiv" + questionCount + "'></div>" +
    5253                    "</div>";
    53                                                                                
     54                                                                                                       
    5455                questionDiv.innerHTML = htmlStr;
    55                                                                                
     56                                                                                                       
    5657                return questionDiv;
    5758            }
    58                                                                                    
     59                                                                                                           
    5960            function handleFocus(input)
    6061            {
     
    6667                }
    6768            }
    68                                                                                                                    
     69                                                                                                                                           
    6970            function handleBlur(input)
    7071            {       
    7172                var surveyTitle = document.getElementById('surveyTitle');
    7273                var surveyDescription = document.getElementById('surveyDescription');
    73                                                                                                    
     74                                                                                                                           
    7475                if (input.value == "")
    7576                {
    7677                    input.style.color = "gray";
    7778                    input.clicked = null;
    78                                                                                                                            
     79                                                                                                                                                   
    7980                    if (input == surveyTitle)
    8081                    {
     
    8788                }                           
    8889            }
    89                                                                    
     90                                                                                           
    9091            function handleType(select)
    9192            {
     
    9495                answersDiv.answerCount = 1;
    9596                answersDiv.clicked = null;
    96                        
     97                                               
    9798                switch (type) {
    9899                    case 'mc':
    99100                        answersDiv.innerHTML = "";
    100101                        addOption(select.id);
    101                                                        
     102                                                                               
    102103                        break;
    103104                    case 'text':
     
    116117                        answersDiv.innerHTML = "";
    117118                        //what scale (min max incr)
     119                        minMaxIncr(select.id);
    118120                        break;
    119121                    default:
     
    122124
    123125            }
    124                                                    
    125                                            
     126                                                                           
     127                                                                   
    126128            function addOption(questionNumber)
    127129            {       
     
    130132                var answerDiv = document.createElement("div");
    131133                answerDiv.className = "answerDiv";
    132                                                
     134                                                                       
    133135                var htmlStr = "<input type='text' name='q" +
    134136                    questionNumber + "ans" + answerCount + "' value='Option " + answerCount + "' />";
    135                        
     137                                               
    136138                if (answersDiv.clicked == null)
    137139                {
     
    140142                    answersDiv.clicked = true;
    141143                }
    142                                                        
     144                                                                              
    143145                answerDiv.innerHTML = htmlStr;
    144                                                        
     146                                                                              
    145147                answersDiv.appendChild(answerDiv);
    146148                answersDiv.answerCount++;
    147149            }
    148            
     150                                   
    149151            function minMax(questionNumber)
    150152            {
    151                var answersDiv = document.getElementById("answersDiv" + questionNumber);
    152                
    153                var answerDiv = document.createElement("div");
    154                answerDiv.className = "answerDiv";
    155                answerDiv.innerHTML = "<label for='min'>Min</label><input type='text' name='min" + questionNumber + "' />" +
    156                "<label for='max'>Max</label><input type='text' name='max" + questionNumber + "' />";
    157            
     153                var answersDiv = document.getElementById("answersDiv" + questionNumber);
     154                                      
     155                var answerDiv = document.createElement("div");
     156                answerDiv.className = "answerDiv";
     157                answerDiv.innerHTML = "<label for='min'>Min</label><input type='text' name='min" + questionNumber + "' />" +
     158                    "<label for='max'>Max</label><input type='text' name='max" + questionNumber + "' />";
     159                                  
    158160                answersDiv.appendChild(answerDiv);
    159             }           
    160                                                                  
     161            } 
     162                                   
     163            function minMaxIncr(questionNumber)
     164            {
     165                minMax(questionNumber);
     166                var answersDiv = document.getElementById("answersDiv" + questionNumber);
     167                                       
     168                var answerDiv = document.createElement("div");
     169                answerDiv.className = "answerDiv";
     170                answerDiv.innerHTML = "<label for='incr'>Increment by</label><input type='text' name='incr" + questionNumber + "' />";
     171                                   
     172                answersDiv.appendChild(answerDiv);
     173            }         
     174                                                                                         
     175                                                                                                 
    161176            function addQuestion()
    162177            {
    163178                var questionsDiv = document.getElementById('questionsDiv');
    164179                var newQuestion = getNewQuestion();
    165                                                                                
     180                               
     181
     182                newQuestion.prev = document.lastQuestion;
     183                document.lastQuestion = newQuestion;
     184
    166185                questionsDiv.appendChild(newQuestion);
    167186                questionCount++;
    168187            }
    169            
    170                                                                                                                                                                                            
     188                           
     189            function removeLastQuestion()
     190            {
     191                var questionsDiv = document.getElementById('questionsDiv');
     192                               
     193                if (document.lastQuestion.prev != null)
     194                {
     195                    questionsDiv.removeChild(document.lastQuestion);
     196                    document.lastQuestion = document.lastQuestion.prev;
     197                    questionCount--; 
     198                }
     199                else
     200                {
     201                    // do nothing
     202                }               
     203            }
     204                         
     205                                   
     206                                                                                                                                                                                                                   
    171207        </script>
    172208        <?php
     
    199235    }
    200236
     237    private static function removeLastQuestionButton() {
     238        ?>
     239        <input type="button" onclick="removeLastQuestion()" value="x" class="surveyButton" />
     240        <?php
     241    }
     242
    201243    private static function submitbutton() {
    202244        ?>
Note: See TracChangeset for help on using the changeset viewer.