Changeset 182


Ignore:
Timestamp:
12/12/11 10:49:25 (13 years ago)
Author:
fpvanagthoven
Message:

Verder gewerkt aan alle scripts. Met uitzondering van:

  • savePipeline().js loopt nog vast
  • loadSession->updateSequencer->updateDividers() gaat niet goed als er geen steps in de pipeline zitten (bijvoorbeeld bij het maken van een nieuwe sessie). Nog check toevoegen of er ook echt wel steps zijn voordat de functie verder gaat naar het maken van een requestString en AJAX calls.
Location:
Dev/trunk
Files:
5 edited

Legend:

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

    r178 r182  
    4848            <div id="surveyEditorContent" class="innerLargeFrame">
    4949
     50                <!--
    5051                <div id="questionUID" class="smallFrame">
    5152                    <div class="smallTitle"><div class="listNumber">1</div>#QUESTION-IDENT-NO</div>
     
    6364                    </div>
    6465                </div>
    65 
     66                -->
    6667
    6768            </div>
  • Dev/trunk/css/visualeditors.css

    r181 r182  
    180180    -moz-border-radius: 0.25em;
    181181    background-color: transparent;
     182    -webkit-user-select: none;
     183    -khtml-user-select: none;
     184    -moz-user-select: none;
     185    -o-user-select: none;
     186    user-select: none;
    182187}
    183188
     
    204209    -moz-border-radius: 0,25em;
    205210    background-color: transparent;
     211    -webkit-user-select: none;
     212    -khtml-user-select: none;
     213    -moz-user-select: none;
     214    -o-user-select: none;
     215    user-select: none;
    206216}
    207217
  • Dev/trunk/js/sequencerScripts.js

    r181 r182  
    1616    },
    1717    state: {                // Operating state of the sequencer
     18        editing: false,         // Whether or not one of the contained child objects is currently being edited or in edit mode. Which one can be determined from the selectedStep property.
    1819        numSteps: 0,            // Number of steps currently drawn in the editor (not necessarily same as number of steps in pipeline!) (INTEGER)
    1920        loaded: false,          // Whether or not the sequencer content has been updated for the first time (BOOL)
     
    2526    settings: {             // Various settings to determine the workings of the sequencer
    2627        content: {              // Properties related to the content view of the sequencer
     28            contentType: "session", // Type of the loaded parent object
    2729            width: null,            // Width of the viewing area (INTEGER)
    2830            height: null,           // Height of the viewing area (INTEGER)
     
    167169                sequencer.session.pipeline.upToDate.length[i] = true;
    168170            }
     171            if (content.childNodes[0].nodeType == 3) content.removeChild(content.childNodes[0]);
    169172        }, true);
    170173    }
     
    173176        debugger;
    174177        var needsUpdating = new Array();
    175        
    176         // DIT IS FOUT.
    177         // BASIC IDEE, IK LOOP NU DOOR DE CHILNODES HEEN, EN NIET DOOR DE PIPELINE ARRAY. HIERDOOR KAN JE NOOIT EEN NIEUWE OBJECT DRAWEN, WANT DAAR IS IN DE SEQUENCER NOG GEEN DIV VOOR.
    178         // OPLOSSING:
    179         // LOOP DOOR SEQUENCER EN HAAL ALLES WEG DAT ER NIET HOORT (CROSSCHECK DISPLAYSTEP UID MET ARRAY)
    180         // LOOP DAARNA DOOR DE PIPELINE EDITOR, CHECK OF ER ELEMENTS VOOR ZIJN. ZO NIET, VOEG TOE AAN DE EDITOR!
    181        
     178        // Add steps that need updating to the needsUpdating array (index, uid, type).
    182179        for (var i = 0; i < sequencer.session.pipeline.uids.length; i++) {
    183            
    184         }
    185        
    186         for (var i = 0; i < content.childNodes.length; i++) {
    187             // If this childNode is not a displayStep, continue to the next childNode
    188             if (!hasClass(content.childNodes[i], "displayStep")) continue;
    189             // If this step is up to date, continue
    190             // pseudo: the upToDate entry on the index where childNodes[i].id is stored in uids
    191             if (sequencer.session.pipeline.upToDate[sequencer.session.pipeline.uids.indexOf(content.childNodes[i].id)] == true) continue;
    192            
    193             // So now we know that we are looking at a displayStep and it needs to be refreshed.
    194             // We store the current childNodes index, the uid of the proper displayStep and the type of the proper displayStep in needsUpdating array.
     180            if (sequencer.session.pipeline.upToDate[i] == true) continue;
    195181            needsUpdating.push(new Array(i, sequencer.session.pipeline.uids[i], sequencer.session.pipeline.types[i]));
    196182        }
    197        
    198183        // Now that we have an array of the steps that need to be refreshed, we compose a requestString.
    199         requestString = "uids=";
     184        var requestString = "uids=";
    200185        for (var i = 0; i < needsUpdating.length; i++) {
    201             requestString += needsUpdating[i][1]+",";   // comma separated, of course
    202         }
    203         requestString = requestString.slice(0, requestString.length - 1);   // remove trailing commas
     186            requestString += needsUpdating[i][1]+",";
     187        }
     188        if (requestString.slice(-1) == ",") requestString = requestString.slice(0, requestString.length - 1);   // remove trailing commas
    204189        requestString += "&types=";
    205         for (var i = 0; i< needsUpdating.length; i++) {
    206             requestString += needsUpdating[i][2]+",";
    207         }
    208         requestString = requestString.slice(0, requestString.length - 1);   // remove trailing commas
    209        
    210         // Now it is time to send this string to returnStep.php (Soon to be returnStepDisplay.php!).
    211        
    212         alert(requestString);
     190        for (var i = 0; i < needsUpdating.length; i++) {
     191            requestString += needsUpdating[i][2];
     192        }
     193        if (requestString.slice(-1) == ",") requestString = requestString.slice(0, requestString.length - 1);   // remove trailing commas
     194       
     195        // perform the AJAX request
    213196        newAjaxRequest(requestString, "returnStep.php", function(result) {
    214             //alert(result.responseText);
    215             insertNewSteps(responseText);
     197            insertNewSteps(result.responseText, needsUpdating);
    216198        }, true);
    217199    }
     
    263245}
    264246
    265 function insertNewSteps(responseText) {
     247function insertNewSteps(responseText, needsUpdating) {
    266248    debugger;
    267249    var content = document.getElementById("seqContentWrapper");
     
    271253    // tempDiv will serve to
    272254    var tempDiv;
     255    if (holderDiv.firstChild.nodeType == "3") holderDiv.removeChild(holderDiv.firstChild);
    273256    // Loop through
    274     for (var i = 0; i < content.childNodes.length; i++) {
    275         // Once again, skip if not a displayStep or the given displayStep is already up to date.
    276         if (!hasClass(content.childNodes[i], "displayStep")) continue;
    277         if (sequencer.session.pipeline.upToDate[sequencer.session.pipeline.uids.indexOf(content.childNodes[i].id)] == true) continue;
     257    for (var i = 0; i < needsUpdating.length; i++) {
    278258        tempDiv = holderDiv.firstChild;
    279259        holderDiv.removeChild(holderDiv.firstChild);
    280         content.replaceChild(tempDiv, content.childNodes[i]);
    281         // Exit the loop if there is no more responsetext
    282         if (!holderDiv.firstChild) break;
     260        if (needsUpdating[i][0] > sequencer.state.numSteps-1) {
     261            // this step comes at the end of the pipeline
     262            content.appendChild(tempDiv);
     263            sequencer.state.numSteps++;
     264        }
     265        else {
     266            content.replaceChild(tempDiv, content.childNodes[needsUpdating[i][0]*2]);
     267        }
     268        // The element is now updated, therefore set this flag in the global var
     269        sequencer.session.pipeline.upToDate[needsUpdating[i][0]] = true;
     270    }
     271   
     272    // Then add or adjust dividers as needed!
     273    updateDividers();
     274}
     275
     276function insertNewQuestion(responseText, needsUpdating) {
     277    /*
     278     * This is a test function displaying how to handle the visual object representation in solely javascript.
     279     * Communication of relevant variables between PHP and JS happens in JSON format.
     280     * PHP returns a JSON array of objects to be created by JS
     281     * JS then loops through this array and creates DIVS to be inserted into the sequencer.
     282     * These are inserted at the position needsUpdating gives us.
     283     */
     284   
     285    var content = document.getElementById("seqContent");
     286    var response = eval(responseText);
     287   
     288    for (var i = 0; i < response.length; i++) {
     289        var tempDiv = document.createElement("div");
     290        tempDiv.id = response.id;
     291        tempDiv.className = "displayStep";
     292        var divImage = document.createElement("img");
     293        divImage.src = "./images/displayStep.png";
     294        divImage.addEventListener("Click", function(e){
     295            selectStep(this.id);
     296        }, false);
     297        tempDiv.appendChild(divImage);
     298        var divLabel = document.createElement("p");
     299        divLabel.innerHTML = response.title;
     300        tempDiv.appendChild(divLabel);
     301       
     302        // This for needs to loop backwards so that the steps at the end of the pipeline are added or changed first. This keeps the childNodes index for all further steps intact.
     303        for (var j = needsUpdating.length; j >= 0; j--) {
     304            if (needsUpdating[j][1] != response.id) continue;
     305            if (needsUpdating[j][0] > sequencer.state.numSteps-1) {
     306                content.appendChild(tempDiv);
     307            }
     308            else {
     309                content.replaceChild(tempDiv, content.childNodes[j][0]*2);
     310            }
     311        }
    283312    }
    284313}
     
    315344
    316345function savePipeline (confirmSave) {
    317     if (confirmSave==true) {
    318         var answer = confirm("Save changes to pipeline?");
     346    var answer;
     347    if (confirmSave == true) {
     348        answer = confirm("Save changes to pipeline?");
    319349    }
    320350    else {
    321         var answer = true;
    322     }
    323    
    324    
    325     if (answer) {
    326         var pipeline = document.getElementById("pipelineStringField").value;
    327         pipeline = pipeline.slice(0, pipeline.length - 1);
    328         var types = document.getElementById("pipelineTypeField").value;
    329         types = types.slice(0, types.length - 1);
    330         var session = document.getElementById("sessionField").value;
    331         var requestString = "uids="+pipeline+"&types="+types+"&sessionUid="+session;
    332         console.log(requestString);
    333        
    334        
    335         var success;
    336         newAjaxRequest(requestString, "savesession.php", function(result){
    337             success = result.responseText;
    338         }, true);
    339         console.log(success);
    340     }
     351        answer = true;
     352    }
     353    if (answer == false) return;
     354   
     355    var requestString = "uids=";
     356    requestString += arrayToString(sequencer.session.pipeline.uids, ",");
     357    requestString += "&types=";
     358    requestString += arrayToString(sequencer.session.pipeline.types, ",");
     359    requestString += "&sessionUid=";
     360    requestString += sequencer.session.uid;
     361    newAjaxRequest(requestString, "savePipeline.php", function(result){
     362        console.log(result.responseText);
     363    }, true);
    341364}
    342365
  • Dev/trunk/js/surveyEditorScripts.js

    r181 r182  
    1515}
    1616
    17 // Deze scripts worden gedeeld door bijna alle editors, en deze moeten dan ook in een common scripts
    18 // file komen te staan in plaats van in elk document weer opnieuw invoeren.
    19 // Dit gaat ongetwijfeld conflicten opleveren als er in een van de functies iets veranderd moet worden.
    2017
    21 function stringToArray(s, c) {
    22     var a = s.split(c);
    23     for (var i = 0; i < a.length; i++) {    // remove empty items
    24         if (a[i] == "") {
    25             a.splice(i, 1);
    26             i--;
    27         }
    28     }
    29     return a;
    30 }
    31 
    32 function arrayToString(a, c) {
    33     var s = "";
    34     for (var i = 0; i < a.length; i++) {
    35         if (a[i] != "") {
    36             s += a[i]+c;
    37         }
    38     }
    39     return s;
    40 }
    4118
    4219function loadSurvey() {
  • Dev/trunk/returnQuestionDisplay.php

    r178 r182  
    1616    $results = $dbi->get("Question", array("uid" => $uid));
    1717    (is_array($results)) ? $result = $results[0] : $result = $results;  //ternary operation!
    18     $output += "HTML CODE HERE!";
     18    $output += '
     19<div id="questionUID" class="smallFrame">
     20                    <div class="smallTitle"><div class="listNumber">1</div>#QUESTION-IDENT-NO</div>
     21                    <div class="content">
     22                        <p class="questionBody">
     23                            This is the question body text. This is what the user will read when he/she is answering the survey.This is the question body text. This is what the user will read when he is answering the survey.This is the question body text. This is what the user will read when he is answering the survey.
     24                        </p>
     25                        <div class="questionParamsView">
     26                            PARAMETERS GO HERE, probably in one line (Only answer type and identifier?) Tags?
     27                        </div>
     28                    </div>
     29                    <div id="questionDisplayControls" class="controls">
     30                        <input type="button" value="Edit" onClick="javascript:alert(\'editing not yet supported\');" class =" smallButton"/>
     31                        <input type="button" value="Remove" onClick="javascript:alert(\'removing not yet supported\');" class =" smallButton"/>
     32                    </div>
     33                </div>
     34';
    1935}
    2036
Note: See TracChangeset for help on using the changeset viewer.