Ignore:
Timestamp:
11/23/11 17:15:20 (13 years ago)
Author:
fpvanagthoven
Message:

Jos, nevermind. Mijn fout, ik heb die creator[0] in SessionConnector:117 weer teruggezet.

  • ToolBox?.php is overgezet naar javascript werking.
  • updateSequencer() werkt.
  • updateDividers() werkt.
  • t_setOutOfDate is in principe niet meer nodig, maar handig voor test purposes. Deze flagget de geselecteerde object voor een refresh.
  • saveSession() werkt! De pipeline editor is nu dus daadwerkelijk bruikbaar! [move/delete/clear/edit nog niet!]
  • Verkeerde calling code voor session->creator aangepast, login systeem werkt nu goed.
  • createObject.php werkt!
File:
1 edited

Legend:

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

    r165 r166  
    2525}
    2626
    27 /*
    28 function SubmitToolbox() {
    29     document.forms['toolbox'].submit();
    30 }
    31 */
     27function removeNL(s){
     28    return s.replace(/[\n\r\t]/g,"");
     29}
     30
    3231function SubmitToolbox(type) {
    3332    var c = "objectToCreate="+type;
     
    3938   
    4039    newAjaxRequest(c, u, function(result){
    41         var resultUid = result.responseText;
    42         console.log(resultUid);
    43         console.log("lol");
    44         console.log(resultUid);
    45         pipeline.value += ","+resultUid;
    46         pipelineType += ","+type;
    47         pipelineUpdated += ",0";
     40        var resultUid = removeNL(result.responseText);
     41        //resultUid.replace("\n","").replace("\r","");
     42       
     43        pipeline.value += resultUid+",";
     44        pipelineType.value += type+",";
     45        pipelineUpdated.value += "0,";
    4846        updateSequencer();
    4947    }, a);
     
    7472    var nodes = document.getElementById("seqContent").childNodes;
    7573    for (var i = 0; i < nodes.length; i++) {     //loop through childNodes. Skip first node (whitespace)
    76         //debugger;
    7774        if (hasClass(nodes[i], "displayStep")) {    //check if current childNode is a displayStep, not divider or text.
    7875            if (nodes[i].id == uid) {
     
    9693}
    9794                                                                           
    98                                                                            
    99 /*
    100  * This function allows for simple use of AJAX requests.
    101  * Calling format:
    102  *
    103  * var c[] = "uid=123";
    104  *  var c[] = "name=tschipper";
    105  *  var u = "getResult.php";
    106  *  newAjaxRequest(c, u, function(xml) {
    107  *      <!--Do something-->
    108  *  });
    109  * 
    110  *  It is of course also possible to refer to an external function instead of
    111  *  defining function(xml){} in the call itself, as below:
    112  * 
    113  *  newAjaxRequest(c, u, externalFunction(xml));
    114  */
    115 
    11695function newAjaxRequest(c, u, cb, async) {
    11796   
     
    145124        }
    146125    }
    147     else {                      // single parameter or string already formatted by calling function
     126    else { // single parameter or string already formatted by calling function
    148127        contentString = content;
    149128    }
    150129    // finally send the formatted request
    151     //alert(contentString);
    152130    xml.send(contentString);
    153131}
     
    183161    var pipeline = document.getElementById("pipelineStringField").value;
    184162    var pipelineTypes = document.getElementById("pipelineTypeField").value;
    185     pipeline = pipeline.replace(/,/g , ",divider,");    //regex search for commas, global (repeat), to represent them with visual dividers.
    186     pipelineTypes = pipelineTypes.replace(/,/g, ",divider,");
    187     ajaxStepRequest(pipeline, pipelineTypes);
     163    var numSteps = document.getElementById("numSteps").value;
     164    if (numSteps > 0) {
     165        pipeline = pipeline.replace(/,/g , ",divider,");    //regex search for commas, global (repeat), to represent them with visual dividers.
     166        pipelineTypes = pipelineTypes.replace(/,/g, ",divider,");
     167        ajaxStepRequest(pipeline, pipelineTypes);
     168    }
    188169}
    189170
     
    192173    var plTypeString = document.getElementById("pipelineTypeField").value;
    193174    var plUpdatedString = document.getElementById("pipelineUpdatedField").value;
    194        
    195     var pl = plString.split(",");
    196     var plType = plTypeString.split(",");
    197     var plUpdated = plUpdatedString.split(",");
    198     //console.log(plUpdated);
    199    
     175   
     176   
     177    var pl = stringToArray(plString, ",");   
     178    var plType = stringToArray(plTypeString, ",");   
     179    var plUpdated = stringToArray(plUpdatedString, ",");
     180   
     181    var count = pl.length;
     182   
     183    document.getElementById("numSteps").value = count;
    200184   
    201185    for (var i = 0; i < pl.length; i++) {   // loop through pipeline contents
     
    204188            var seqContent = document.getElementById("seqContent");
    205189            var element = document.getElementById(pl[i]);
    206             var nextElement = element.nextSibling;
     190            if (element == null) {
     191                element = document.createElement("div");
     192                element.name = "placeholder";
     193                seqContent.appendChild(element);
     194            }
     195            if (element.nextSibling) {
     196                var nextElement = element.nextSibling;
     197            }
     198            else {
     199                var nextElement = document.createElement("div");
     200                nextElement.name = "placeholderNext";
     201                seqContent.appendChild(nextElement);
     202            }
    207203           
    208204            // now request a new step representation and insert it after previousElement
    209205            var holderDiv = document.createElement("div");
    210206            var requestString = "uids="+pl[i];
    211             var resultText;
     207           
     208            if (plType[i]) {
     209                requestString += "&types="+plType[i];
     210            }
     211            // globally declare newDiv so it can be passed to the updateDividers function
     212            var newDiv;
     213           
    212214            newAjaxRequest(requestString, "returnStep.php", function(result) {
    213                 holderDiv.innerHTML = result.responseText;
     215                holderDiv.innerHTML = result.responseText;
     216                newDiv = holderDiv.childNodes[1];           
     217                seqContent.replaceChild(newDiv, element);
     218                if (nextElement.name == "placeholderNext") {
     219                    seqContent.removeChild(nextElement);
     220                }
     221                plUpdated[i] = "1";
    214222            }, false);
    215223           
    216             //debugger;
    217             while (holderDiv.childNodes.length == 1) {
    218             // wait for response
    219             }
    220             var newDiv = holderDiv.childNodes[1];
    221             seqContent.replaceChild(newDiv, element);
    222             plUpdated[i] = "1";
    223         // ALTERNATIVE METHOD TO REPLACECHILD!!!
    224         //seqContent.removeChild(element);
    225         //seqContent.insertBefore(newDiv, nextElement);
    226            
    227            
    228         }
    229         else {
    230            
    231     }
    232     }
    233    
    234     // afterwards, convert the arrays back to strings
    235     var newUpdatedString = "";
    236    
    237     for (var i = 0; i < plUpdated.length; i++) {
    238         newUpdatedString += plUpdated[i]+",";
    239     }
    240    
    241     if (newUpdatedString.substring(newUpdatedString.length - 1) == ",") {   // remove comma at the end of string!
    242         newUpdatedString = newUpdatedString.substring(0, newUpdatedString.length-1);
    243        
    244     }
     224                       
     225            // ALTERNATIVE METHOD TO REPLACECHILD!!!
     226            //seqContent.removeChild(element);
     227            //seqContent.insertBefore(newDiv, nextElement);
     228           
     229            // Now check if dividers are necessary.
     230           
     231            //alert("INSERT CODE FOR UPDATEDIVIDERS HERE!");
     232            updateDividers(newDiv);
     233        }
     234    }
     235   
     236    // afterwards, convert the arrays back to strings and set to appropriate fields
     237    var newUpdatedString = arrayToString(plUpdated, ",");
    245238    document.getElementById("pipelineUpdatedField").value = newUpdatedString;
    246239   
    247240}
     241
     242
     243
     244
     245
     246
     247function updateDividers (element) {
     248    var seqContent = document.getElementById("seqContent");
     249   
     250    if (element.nextSibling){
     251        var nextElement = element.nextSibling;
     252    }
     253    if (element.previousSibling) {
     254        var previousElement = element.previousSibling;
     255    }
     256   
     257    if (nextElement){
     258        if (!hasClass(nextElement, "divider")) {
     259            var holderDiv = document.createElement("div");
     260            newAjaxRequest("uids=divider&types=divider", "returnStep.php", function(result) {
     261                holderDiv.innerHTML = result.responseText;
     262                var newDivider = holderDiv.childNodes[1];
     263                seqContent.insertBefore(newDivider, nextElement);
     264            }, false);
     265        }
     266    }
     267   
     268    if (previousElement){
     269        if (!hasClass(previousElement, "divider")) {
     270            var holderDiv = document.createElement("div");
     271            newAjaxRequest("uids=divider&types=divider", "returnStep.php", function(result) {
     272                holderDiv.innerHTML = result.responseText;
     273                var newDivider = holderDiv.childNodes[1];
     274                seqContent.insertBefore(newDivider, element);
     275            }, false);
     276        }
     277    }
     278   
     279}
     280
     281
     282
     283
     284
    248285
    249286function savePipeline() {
    250287    var answer = confirm("Save changes to pipeline?");
    251288    if (answer) {
    252         newAjaxRequest("", "savesession.php", function(){}, false);
    253         alert("Saved!");
     289        var pipeline = document.getElementById("pipelineStringField").value;
     290        pipeline = pipeline.slice(0, pipeline.length - 1);
     291        var types = document.getElementById("pipelineTypeField").value;
     292        types = types.slice(0, types.length - 1);
     293        var session = document.getElementById("sessionField").value;
     294        var requestString = "uids="+pipeline+"&types="+types+"&sessionUid="+session;
     295        //console.log(requestString);
     296       
     297       
     298        var success;
     299        newAjaxRequest(requestString, "savesession.php", function(result){
     300            success = result.responseText;
     301        }, false);
     302        console.log(success);
    254303    }
    255304}
     
    268317    var plUpdatedString = document.getElementById("pipelineUpdatedField").value;
    269318   
    270     var pl = plString.split(",");
    271     var plType = plTypeString.split(",");
    272     var plUpdated = plUpdatedString.split(",");
    273    
    274    
     319   
     320    var pl = stringToArray(plString, ",");   
     321    var plType = stringToArray(plTypeString, ",");   
     322    var plUpdated = stringToArray(plUpdatedString, ",");   
    275323   
    276324    // set the targeted element's tag for "Needs updating"
    277     for (var i = 0; i < pl.length; i++) {
    278         if (pl[i] == uid) {
    279             plUpdated[i] = 0;
    280         }
    281     }
     325    plUpdated[pl.indexOf(uid)] = "0";
    282326   
    283327    // then rewrite the content strings and set them to the appropriate fields
    284    
    285     var newUpdatedString = "";
    286     for (var i = 0; i < pl.length; i++) {
    287         newUpdatedString += plUpdated[i]+",";
    288     }
    289     if (newUpdatedString.substring(newUpdatedString.length-1) == ",") {
    290         newUpdatedString = newUpdatedString.substring(0, newUpdatedString.length-1);
    291     }
    292    
    293    
     328    var newUpdatedString = arrayToString(plUpdated, ",");
    294329    document.getElementById("pipelineUpdatedField").value = newUpdatedString;
    295 //alert("OOD set");
    296 }
     330}
     331
     332function stringToArray(s, c) {
     333    var a = s.split(c);
     334    for (var i = 0; i < a.length; i++) {    // remove empty items
     335        if (a[i] == "") {
     336            a.splice(i, 1);
     337            i--;
     338        }
     339    }
     340    return a;
     341}
     342
     343function arrayToString(a, c) {
     344    var s = "";
     345    for (var i = 0; i < a.length; i++) {
     346        if (a[i] != "") {
     347            s += a[i]+c;
     348        }
     349    }
     350    return s;
     351}
Note: See TracChangeset for help on using the changeset viewer.