Ignore:
Timestamp:
01/17/12 18:17:51 (13 years ago)
Author:
fpvanagthoven
Message:
  • Faal met perongeluk de database committen-_- Maar is weer deleted, zou nu weer moeten werken.
  • QuestionEditor? werkt nu grotendeels, paar kleine afwerkingsfoutjes (en data die nog niet in de DB passen)
  • selectQuestion scherm gemaakt, is nog niet zo multifunctioneel als je zou hopen. Ideaal gezien zou dit ipv een statische PHP pagina, een JS driven widget worden die je bijvoorbeeld kan gebruiken voor "Add existing question" in de surveyEditor.
  • Zelfde voor selectApplication.php en selectSurvey.php.
  • objectSelectionWidget class maken voor dit doeleind? (Na demo!)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/branches/jos-branch/js/questionEditorScripts.js

    r236 r237  
    2121}
    2222
    23 function updateIdentifier() {
    24     var identField = document.getElementById("questionIdentifierField");
    25     if (identField.value == undefined && identField.value == "") {
    26         return;
    27     }
    28     var headerField = document.getElementById("header_identifier");
    29     headerField.innerHTML = identField.value;
    30 }
    31 
    32 
    33 //////////////////////////////////////////
    34 /* QUESTION EDITOR CLASS BASED APPROACH */
    35 //////////////////////////////////////////
    36 
    3723function QuestionEditor() {
    3824    // Properties   
     
    4733    // Basic functionality
    4834    this.setValues = function(arguments) {
    49         var question = JSON.parse(arguments);       
     35        debugger;
     36        var question = JSON.parse(arguments)[0];
     37        var qeTypeField = ge("qeTypeField");
     38        ge("qeCodeField").value = question.code;
     39        ge("qeBodyTextField").value = question.description;
     40        switch (question.type.toLowerCase()) {
     41            case "int":
     42                // First make sure all the necessary fields are present
     43                me.type_Integer();
     44                // Then fill them in using the available data
     45                qeTypeField.value = "int";
     46                ge("qeMinValueField").value = question.minValue;
     47                ge("qeMaxValueField").value = question.maxValue;
     48                break;
     49            case "scale":
     50                me.type_Scale();
     51                qeTypeField.value = "scale";
     52                ge("qeNumChoicesField").value = question.numChoices;
     53                ge("qeLegendsEnabledField").checked = question.legendsEnabled;
     54                ge("qeLowerLegendField").value = question.lowerLegend;
     55                ge("qeUpperLegendField").value = question.upperLegend;
     56                break;
     57            case "choice":
     58                me.type_Choice();
     59                qeTypeField.value = "choice";
     60                ge("qeNumOptionsFIeld").value = question.numOptions;
     61                ge("qeMultipleAnswersField").value = question.multipleAnswers;
     62                // then some more to add textboxes (qeParamAnswerGroup) for all the possble choices.
     63                // Maybe a central version that appends these groups/textinputs? Maybe not, though. Don't want stuff too abstracted...
     64                break;
     65            case "text":
     66                me.type_Text();
     67                qeTypeField.value = "text";
     68                ge("qeTextMaxLengthField").value = question.maxTextLength;
     69                break;
     70               
     71        }
    5072    }
    5173    this.init = function() {
     
    150172    this.save = function() {
    151173        var request = {
    152             "title": ge("qeTitleField").value,
    153             "type": ge("qeTypeField").value
     174            "title": ge("qeTitleField").innerHTML,
     175            "code": ge("qeCodeField").value,
     176            "description": ge("qeBodyTextField").value
    154177        }
    155178       
     
    158181                request.answerType = "int";
    159182                request.minValue = parseInt(ge("qeMinValueField").value);
     183                if (request.minValue == "NaN") request.minValue = -1;   // Is this the correct way to do this?
    160184                request.maxValue = parseInt(ge("qeMaxValueField").value);
     185                if (request.maxValue == "NaN") request.maxValue = -1;
     186                // Include error checking and form validation!!
    161187                break;
    162188            case "scale":
     
    166192                request.lowerLegend = ge("qeLowerLegendField").value;
    167193                request.upperLegend = ge("qeUpperLegendField").value;
     194                // Include error checking and form validation!!
    168195                break;
    169196            case "choice":
    170197                request.answerType = "choice";
     198                request.multipleAnswers = ge("qeMultipleAnswersField").checked;
     199                request.possibleAnswers = array();
     200                var answerFieldset = ge("qeParamsAnswerFieldset");
     201                var count = ge("qeNumOptionsField").value;
     202               
     203                for (var i = 0; i < count; i++) {
     204                    var el = ge("qeAnswerField"+i);
     205                    request.possibleAnswers.push(el.value);
     206                }
     207                // Include error checking and form validation!!
    171208                break;
    172209            case "text":
    173210                request.answerType = "text";
    174                 break;
    175         }
    176        
    177         newAjaxRequest(requestString, "createObject.php", function(result){
    178             // Display a success message, or throw an error.
    179             }, true);
     211                request.maxTextLength = ge("qeTextMaxLength").value;
     212                // Include error checking and form validation!!
     213                break;
     214        }
     215       
     216        requestString = "args="+JSON.stringify(request);
     217       
     218        newAjaxRequest(requestString, "setQuestion.php", function(result){
     219            // Then add the returned uid, if existing, to the sequencer.survey.questions array and set it for update
     220            debugger;
     221            var response = JSON.parse(result.responseText);
     222            console.log(response);
     223            if (response.created == true) {
     224                if (response.uid) {
     225                    // Created a new question, add it to the sequencer content array and set it for an update
     226                    sequencer.survey.questions.uids.push(response.uid);
     227                    sequencer.survey.questions.upToDate.push(false);
     228                }
     229                else {
     230                    alert("ERROR!");
     231                }
     232            } else {
     233                if (response.uid){
     234                    // Edited an existing question that was already in the sequencer content. Set it for an update
     235                    sequencer.survey.questions.upToDate[sequencer.survey.questions.uids.indexOf(response.uid)] = false;
     236                }
     237                else {
     238                    alert("ERROR!");
     239                }
     240            }
     241           
     242           
     243            // Then remove the editor from the sequencer content, so that it can be replaced with the correct question view.
     244            me.element.parentNode.removeChild(me.element);
     245            sequencer.state.editing = false;
     246            updateSequencer();
     247        }, true);
     248    }
     249    this.discard = function() {
     250        me.element.parentNode.removeChild(me.element);
     251        me.init();
     252        sequencer.state.loaded = true;
     253        sequencer.state.editing = false;
    180254    }
    181255    this.reset = function() {
     
    340414    }
    341415    this.type_Choice_CheckAnswerFields = function() {
    342         debugger;
    343416        var container = ge("qeParamsAnswerFieldset");
    344417        var numAnswers = parseInt(document.getElementById("qeNumOptionsField").value, 10);
     
    358431            // Extra inputs need to be added
    359432            var n = numAnswers - numAnswerFields;
    360             for (var x = 0; x < n; x++) {
     433            for (var x = 1; x < n+1; x++) {
    361434                var group = ce("div");
    362435                group.className = "qeChoiceAnswerGroup";
     
    387460    // Editing
    388461    this.editQuestion = function(uid) {
     462        debugger;
    389463        if (sequencer.state.editing == true) return;
    390464        if (sequencer.state.loaded == false) return;
    391465        sequencer.state.editing = true;
    392        
    393         var request = {
    394             "type": "Question",
    395             "uid": uid
    396         }
    397        
     466        sequencer.state.loaded = false;
     467       
     468        var request = new Array({
     469            type: "Question",
     470            uid: uid
     471        });
     472        me.init();
     473        var oldElement = ge(uid);
     474        if (oldElement) {
     475            // There really should be.... I don't know why I am doing this check...
     476            oldElement.parentNode.replaceChild(me.element, oldElement);
     477        }
    398478        var requestString = "args="+JSON.stringify(request);
    399         sequencer.state.loaded = false;
    400         newAjaxRequest(requestString, getObject.php, function(result){
     479        newAjaxRequest(requestString, "getObject.php", function(result){
    401480            // Once results are in
    402             questionEditor.setValues(result.responseText);
     481            me.setValues(result.responseText);
    403482            sequencer.state.loaded = true;
    404483        }, true);
     
    406485    this.createNewQuestion = function() {
    407486        if (sequencer.state.editing == true) return;
    408         if (sequencer.state.loading == true) return;
     487        if (sequencer.state.loading == false) return;
    409488        sequencer.state.editing = true;
    410489   
     
    414493    }
    415494}
     495
     496// IT LIIIIIIVESSSSS
     497// TODO: Add database fields for all the necessary question parameters. Maybe only one question parameter property that holds all the settings, then read it out in javascript?
     498// Why have a question Description? Is this even necessary?
     499// Needed properties:
     500// Also not exactly sure what "question->category" is for. Is this one of those questionSet things that Julia was talking about?
     501//
Note: See TracChangeset for help on using the changeset viewer.