Changeset 168 for Dev/trunk/js


Ignore:
Timestamp:
11/29/11 17:26:07 (13 years ago)
Author:
fpvanagthoven
Message:
  • moveStep() [js] werkt weer, editor is nu op delete/clear na helemaal functioneel
  • Zit nog steeds een creator bug in savesession.php en selectSession.php
  • getInfo.php is nu aangepast om voor meerdere objecttypes te werken en relevante informatie terug te geven, geformatteerd als table. De styling hiervan moet wel nog beter geregeld worden.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/js/sequencerScripts.js

    r167 r168  
    33 * and open the template in the editor.
    44 */
     5var timeDiff  =  {
     6    setStartTime:function (){
     7        d = new Date();
     8        time  = d.getTime();
     9    },
     10
     11    getDiff:function (){
     12        d = new Date();
     13        return (d.getTime()-time);
     14    }
     15}
     16
     17
     18
     19
    520
    621function IsItemSelected(check, target) {
     
    3651    var pipelineType = document.getElementById("pipelineTypeField");
    3752    var pipelineUpdated = document.getElementById("pipelineUpdatedField");
     53    document.getElementById("numSteps").value++;
    3854   
    3955    newAjaxRequest(c, u, function(result){
     
    7086
    7187function selectStep(uid) {
     88    /*
     89   
    7290    var nodes = document.getElementById("seqContentWrapper").childNodes;
    7391    for (var i = 0; i < nodes.length; i++) {     //loop through childNodes. Skip first node (whitespace)
     
    86104        }
    87105    }
    88    
    89     // Update selected step field with uid of currently selected step.
     106    */
     107    // Hier is een snellere manier voor!
     108    var element = document.getElementById(uid);
     109    var prevElement = document.getElementById(document.getElementById("selectedStepField").value);
     110   
     111    if (!element || !hasClass(element, "displayStep")) {
     112        return;
     113    }
     114    // misschien nog checks inbouwen of het echt wel een element is?
    90115    var selectedStepField = document.getElementById("selectedStepField");
    91     selectedStepField.value = uid;
    92    
     116    if (!hasClass(element, "selected")) {
     117        if (prevElement) {
     118            removeClass(prevElement, "selected");
     119        }
     120        addClass(element, "selected");
     121        selectedStepField.value = uid;
     122       
     123        var pl = stringToArray(document.getElementById("pipelineStringField").value, ",");
     124        var plType = stringToArray(document.getElementById("pipelineTypeField").value, ",");
     125        var type = plType[pl.indexOf(uid)];
     126        ajaxInfoRequest(uid, document.getElementById("infoPanelContent"), type);
     127       
     128       
     129    }
     130    else {
     131        deselectStep(uid);
     132    }
     133   
     134   
     135// Update selected step field with uid of currently selected step.
     136   
     137   
     138}
     139
     140function deselectStep(uid) {
     141    var field = document.getElementById("selectedStepField");
     142    field.value = "";
     143    var element = document.getElementById(uid);
     144    removeClass(element, "selected");
     145    document.getElementById("infoPanelContent").innerHTML = "";
    93146}
    94147                                                                           
     
    148201}
    149202
    150 function ajaxInfoRequest(id, el) {
    151     var uid = id;
     203function ajaxInfoRequest(uid, el, type) {
    152204    var c = "uid="+uid;
     205    c += "&type="+type;
    153206    var u = "getInfo.php";
    154207    newAjaxRequest(c, u, function(result) {
     
    169222}
    170223
    171 function drawSteps() {
    172    
    173 }
    174 
    175 function updateSequencer() {
     224
     225function updateSequencer(firstLoad) {
     226    // Load hidden field values
    176227    var plString = document.getElementById("pipelineStringField").value;
    177228    var plTypeString = document.getElementById("pipelineTypeField").value;
    178229    var plUpdatedString = document.getElementById("pipelineUpdatedField").value;
    179    
    180    
    181     var pl = stringToArray(plString, ",");   
    182     var plType = stringToArray(plTypeString, ",");   
    183     var plUpdated = stringToArray(plUpdatedString, ",");
    184    
    185     var count = pl.length;
    186    
    187     document.getElementById("numSteps").value = count;
    188    
    189     for (var i = 0; i < pl.length; i++) {   // loop through pipeline contents
    190         if (plUpdated[i] == "0") {   // if the element is not up to date
    191             // first remove the step representation from the sequencer
     230    var count = document.getElementById("numSteps").value;
     231   
     232    if (count < 1) {
     233        return;
     234    }
     235    // If this is on page-load time
     236    if (firstLoad == true) {
     237        requestString = plString.slice(0, -1);
     238        requestString = requestString.replace(/,/g, ",divider,");
     239        newAjaxRequest("uids="+requestString, "returnStep.php", function(result) {
    192240            var seqContent = document.getElementById("seqContentWrapper");
    193             var element = document.getElementById(pl[i]);
    194             if (element == null) {
    195                 element = document.createElement("div");
    196                 element.name = "placeholder";
    197                 seqContent.appendChild(element);
     241            seqContent.innerHTML = result.responseText;
     242        }, true);
     243       
     244        plUpdatedString = "";
     245        for (var i = 0; i < plString.split(",").length-1; i++) {
     246            plUpdatedString += "1,";
     247        }
     248       
     249        document.getElementById("pipelineUpdatedField").value = plUpdatedString;
     250    }
     251    else {      // if not
     252        var pl = stringToArray(plString, ",");   
     253        var plType = stringToArray(plTypeString, ",");   
     254        var plUpdated = stringToArray(plUpdatedString, ",");
     255   
     256        var count = pl.length;
     257   
     258        document.getElementById("numSteps").value = count;
     259        var seqContent = document.getElementById("seqContentWrapper");
     260        if (seqContent.childNodes.length > (2*count)-1) {
     261            seqContent.removeChild(seqContent.childNodes[0]);
     262           
     263        }
     264       
     265       
     266        for (var i = 0; i < pl.length; i++) {   // loop through pipeline contents
     267            if (plUpdated[i] == "0") {   // if the element is not up to date
     268                // first remove the step representation from the sequencer
     269                //timeDiff.setStartTime();
     270               
     271           
     272                // IMPROVISE !!!!!!!!!!
     273                var elementByIndex = seqContent.childNodes[2*i];    // works with moved steps
     274                var elementById = document.getElementById(pl[i]);   // works with ???, not moved steps though... Keeping this in here for future bugfixing. This value is not currently used.
     275                var element = elementByIndex;
     276           
     277           
     278                // END IMPROVISE !!!!!!!!!!!!
     279                if (element == null) {
     280                    element = document.createElement("div");
     281                    element.name = "placeholder";
     282                    seqContent.appendChild(element);
     283                }
     284                if (element.nextSibling) {
     285                    var nextElement = element.nextSibling;
     286                }
     287                else {
     288                    var nextElement = document.createElement("div");
     289                    nextElement.name = "placeholderNext";
     290                    seqContent.appendChild(nextElement);
     291                }
     292           
     293                // now request a new step representation and insert it after previousElement
     294                var holderDiv = document.createElement("div");
     295                var requestString = "uids="+pl[i];
     296           
     297                if (plType[i]) {
     298                    requestString += "&types="+plType[i];
     299                }
     300                // globally declare newDiv so it can be passed to the updateDividers function
     301                var newDiv;
     302           
     303                newAjaxRequest(requestString, "returnStep.php", function(result) {
     304                    holderDiv.innerHTML = result.responseText;
     305                    newDiv = holderDiv.childNodes[1];           
     306                    seqContent.replaceChild(newDiv, element);
     307                    if (nextElement.name == "placeholderNext") {
     308                        seqContent.removeChild(nextElement);
     309                    }
     310                    plUpdated[i] = "1";
     311                }, false);
     312           
     313                       
     314                // ALTERNATIVE METHOD TO REPLACECHILD!!!
     315                //seqContent.removeChild(element);
     316                //seqContent.insertBefore(newDiv, nextElement);
     317           
     318                // Now check if dividers are necessary.
     319           
     320                //alert("INSERT CODE FOR UPDATEDIVIDERS HERE!");
     321                //alert(timeDiff.getDiff());
     322                updateDividers(newDiv);
    198323            }
    199             if (element.nextSibling) {
    200                 var nextElement = element.nextSibling;
    201             }
    202             else {
    203                 var nextElement = document.createElement("div");
    204                 nextElement.name = "placeholderNext";
    205                 seqContent.appendChild(nextElement);
    206             }
    207            
    208             // now request a new step representation and insert it after previousElement
    209             var holderDiv = document.createElement("div");
    210             var requestString = "uids="+pl[i];
    211            
    212             if (plType[i]) {
    213                 requestString += "&types="+plType[i];
    214             }
    215             // globally declare newDiv so it can be passed to the updateDividers function
    216             var newDiv;
    217            
    218             newAjaxRequest(requestString, "returnStep.php", function(result) {
    219                 holderDiv.innerHTML = result.responseText;
    220                 newDiv = holderDiv.childNodes[1];           
    221                 seqContent.replaceChild(newDiv, element);
    222                 if (nextElement.name == "placeholderNext") {
    223                     seqContent.removeChild(nextElement);
    224                 }
    225                 plUpdated[i] = "1";
    226             }, false);
    227            
    228                        
    229             // ALTERNATIVE METHOD TO REPLACECHILD!!!
    230             //seqContent.removeChild(element);
    231             //seqContent.insertBefore(newDiv, nextElement);
    232            
    233             // Now check if dividers are necessary.
    234            
    235             //alert("INSERT CODE FOR UPDATEDIVIDERS HERE!");
    236             updateDividers(newDiv);
    237         }
    238     }
    239    
    240     // afterwards, convert the arrays back to strings and set to appropriate fields
    241     var newUpdatedString = arrayToString(plUpdated, ",");
    242     document.getElementById("pipelineUpdatedField").value = newUpdatedString;
    243    
     324        }
     325   
     326        // afterwards, convert the arrays back to strings and set to appropriate fields
     327        var newUpdatedString = arrayToString(plUpdated, ",");
     328        document.getElementById("pipelineUpdatedField").value = newUpdatedString;
     329    }
    244330}
    245331
     
    366452    // eerst saven, dan de object type zoeken in de typelist, dan redirecten naar de goede pagina
    367453    savePipeline(false);
    368     debugger;
     454   
    369455    var pipeline = document.getElementById("pipelineStringField").value;
    370456    var pipelineTypes = document.getElementById("pipelineTypeField").value;
     
    375461   
    376462    var postForm = document.createElement("form");
    377     postForm.action = stepType.toLowerCase()+"Editor.php";
     463    postForm.action = stepType.toLowerCase()+"Editor.php";      //redirect to "type"editor.php
    378464    postForm.method = "POST";
    379465    var objectUid = document.createElement("input");
     
    388474function moveStep (direction) {
    389475    // misschien maar eens een loadhiddenfields functie maken voor deze meuk?
    390     debugger;
     476   
    391477    var selectedStep = document.getElementById("selectedStepField").value;
    392478   
     
    402488   
    403489    var id = pipeline.indexOf(selectedStep);
    404     // Dit werkt niet, hij replaced dingen de verkeerde kant op. Lelijke versie met placeholder variables maar weer doen?
    405     pipeline[id] = pipeline.splice(pipeline[id+direction], 1, pipeline[id])[0];
    406     pipelineTypes[id] = pipelineTypes.splice(pipelineTypes[id+direction], 1, pipelineTypes[id])[0];
     490    if ((id == 0 && direction == -1) || (id == pipeline.length-1 && direction == 1)){
     491        alert("Cannot move out of bounds!");
     492        return;
     493    }
     494    var tempString = pipeline[id], tempType = pipelineTypes[id];
     495   
     496    pipeline[id] = pipeline[id+direction];
     497    pipelineTypes[id] = pipelineTypes[id+direction];
     498    pipeline[id+direction] = tempString;
     499    pipelineTypes[id+direction] = tempType;
    407500    updated[id] = "0";
    408501    updated[id+direction] = "0";
     
    417510    updateSequencer();
    418511   
    419    
    420    
    421 }
     512    // Then reselect the previously selected step
     513    addClass(document.getElementById(selectedStep), "selected");
     514}
Note: See TracChangeset for help on using the changeset viewer.