/* * To change this template, choose Tools | Templates * and open the template in the editor. */ function IsItemSelected(check, target) { if (check.value) { target.disabled = false; } else { target.disabled = true; } } function IsCheckEnabled(check, target) { if (check.checked) { target.disabled = false; this.removeClass(target, "dis"); } else { target.disabled = true; this.addClass(target, "dis"); } } function SubmitToolbox() { document.forms['toolbox'].submit(); } // Class manipulation function hasClass(ele,cls) { if (ele.className) return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)')); } function addClass(ele,cls) { if (!this.hasClass(ele,cls)) ele.className += " "+cls; } function removeClass(ele,cls) { if (hasClass(ele,cls)) { var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)'); ele.className=ele.className.replace(reg,' '); } } //new scripts! //start here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! function selectStep(uid) { var nodes = document.getElementById("seqContent").childNodes; for (var i = 0; i < nodes.length; i++) { //loop through childNodes. Skip first node (whitespace) //debugger; if (hasClass(nodes[i], "displayStep")) { //check if current childNode is a displayStep, not divider or text. if (nodes[i].id == uid) { if (hasClass(nodes[i], "selected")) { removeClass(nodes[i], "selected"); } else { addClass(nodes[i], "selected"); } } else { removeClass(nodes[i], "selected"); } } } // Update selected step field with uid of currently selected step. var selectedStepField = document.getElementById("selectedStepField"); selectedStepField.value = uid; } /* * This function allows for simple use of AJAX requests. * Calling format: * * var c[] = "uid=123"; * var c[] = "name=tschipper"; * var u = "getResult.php"; * newAjaxRequest(c, u, function(xml) { * * }); * * It is of course also possible to refer to an external function instead of * defining function(xml){} in the call itself, as below: * * newAjaxRequest(c, u, externalFunction(xml)); */ function newAjaxRequest(c, u, cb, async) { var xml; var content = c; //an array of strings, in "key=value" format. // assign a compatible request format if (window.XMLHttpRequest) { //Not IE5, IE6 xml = new XMLHttpRequest(); } else { //IE5, IE6 xml = new ActiveXObject("Microsoft.XMLHTTP"); } // subscribe the callback function to a response event xml.onreadystatechange = function() { xml.responseText = "Processing..."; if (xml.readyState == 4 && xml.status == 200) { cb(xml); } }; // initialize XMLRequest xml.open("POST", u, async); xml.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); var contentString = ""; //iterate through parameters passed in variable c if (typeof(content)=='object'&&(input instanceof Array)) { // parameters were passed as an array of key=value strings for (var i = 0; i < content.length; i++) { contentString += content[i]; if (i != (content.length - 1)) { contentString += "&"; } } } else { // single parameter or string already formatted by calling function contentString = content; } // finally send the formatted request //alert(contentString); xml.send(contentString); } /* * ajaxStepRequest gets the markup for displaying a step in the sequencer from returnStep.php * Using ajax principle allows for editing of pipeline without constantly refreshing the page. */ function ajaxStepRequest(UIDS) { var c = "uids="+UIDS; var u = "returnStep.php"; newAjaxRequest(c, u, function(result) { document.getElementById("seqContent").innerHTML = result.responseText; }, true); } function ajaxInfoRequest(id, el) { var uid = id; var c = "uid="+uid; var u = "getInfo.php"; newAjaxRequest(c, u, function(result) { el.innerHTML = result.responseText; }, true); } function drawSteps() { var content = document.getElementById("seqContent"); var pipeline = document.getElementById("pipelineStringField").value; pipeline = pipeline.replace(/,/g , ",divider,"); //regex search for commas, global (repeat), to represent them with visual dividers. ajaxStepRequest(pipeline); } function updateSequencer() { var plString = document.getElementById("pipelineStringField").value; var plTypeString = document.getElementById("pipelineTypeField").value; var plUpdatedString = document.getElementById("pipelineUpdatedField").value; var pl = plString.split(","); var plType = plTypeString.split(","); var plUpdated = plUpdatedString.split(","); //console.log(plUpdated); for (var i = 0; i < pl.length; i++) { // loop through pipeline contents if (plUpdated[i] == "0") { // if the element is not up to date // first remove the step representation from the sequencer var seqContent = document.getElementById("seqContent"); var element = document.getElementById(pl[i]); var nextElement = element.nextSibling; // now request a new step representation and insert it after previousElement var holderDiv = document.createElement("div"); var requestString = "uids="+pl[i]; var resultText; newAjaxRequest(requestString, "returnStep.php", function(result) { holderDiv.innerHTML = result.responseText; }, false); //debugger; while (holderDiv.childNodes.length == 1) { // wait for response } var newDiv = holderDiv.childNodes[1]; seqContent.replaceChild(newDiv, element); plUpdated[i] = "1"; // ALTERNATIVE METHOD TO REPLACECHILD!!! //seqContent.removeChild(element); //seqContent.insertBefore(newDiv, nextElement); } else { } } // afterwards, convert the arrays back to strings var newUpdatedString = ""; for (var i = 0; i < plUpdated.length; i++) { newUpdatedString += plUpdated[i]+","; } if (newUpdatedString.substring(newUpdatedString.length - 1) == ",") { // remove comma at the end of string! newUpdatedString = newUpdatedString.substring(0, newUpdatedString.length-1); } document.getElementById("pipelineUpdatedField").value = newUpdatedString; } function savePipeline() { var answer = confirm("Save changes to pipeline?"); if (answer) { newAjaxRequest("", "savesession.php", function(){}, false); alert("Saved!"); } } function t_setOutOfDate() { // if a step is currently selected var uid = document.getElementById("selectedStepField").value; if (uid == "") { alert("No step selected!"); return; } // convert to arrays for looping var plString = document.getElementById("pipelineStringField").value; var plTypeString = document.getElementById("pipelineTypeField").value; var plUpdatedString = document.getElementById("pipelineUpdatedField").value; var pl = plString.split(","); var plType = plTypeString.split(","); var plUpdated = plUpdatedString.split(","); // set the targeted element's tag for "Needs updating" for (var i = 0; i < pl.length; i++) { if (pl[i] == uid) { plUpdated[i] = 0; } } // then rewrite the content strings and set them to the appropriate fields var newUpdatedString = ""; for (var i = 0; i < pl.length; i++) { newUpdatedString += plUpdated[i]+","; } alert(newUpdatedString+": OLD"); if (newUpdatedString.substring(newUpdatedString.length-1) == ",") { newUpdatedString = newUpdatedString.substring(0, newUpdatedString.length-1); } alert(newUpdatedString+": NEW!"); document.getElementById("pipelineUpdatedField").value = newUpdatedString; //alert("OOD set"); }