Changeset 152 for Dev/trunk/js/sequencerScripts.js
- Timestamp:
- 11/09/11 17:14:25 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk/js/sequencerScripts.js
r150 r152 29 29 } 30 30 31 32 33 /*34 * Selection code35 *36 */37 38 function checkSelectedStep(number){39 document.sequencer.selectedStep.value = number;40 var step = document.getElementById("seqContent")41 document.refresh();42 }43 44 function highlightSelectedStep() {45 46 }47 48 49 50 51 52 53 54 55 56 57 31 // Class manipulation 58 32 59 33 function hasClass(ele,cls) { 60 34 return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)')); 61 35 } 62 36 63 37 function addClass(ele,cls) { 64 38 if (!this.hasClass(ele,cls)) ele.className += " "+cls; 65 39 } 66 40 67 41 function removeClass(ele,cls) { 68 69 70 71 42 if (hasClass(ele,cls)) { 43 var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)'); 44 ele.className=ele.className.replace(reg,' '); 45 } 72 46 } 73 47 48 //new scripts! 49 //start here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 50 51 function selectStep(uid) { 52 document.getElementById(uid).addClass("selected"); 53 document.sequencer.controls.selectedStep.value = uid; 54 } 55 56 57 /* 58 * ajaxStepRequest gets the markup for displaying a step in the sequencer from returnStep.php 59 * Using ajax principle allows for editing of pipeline without constantly refreshing the page. 60 */ 61 62 function ajaxStepRequest(UID) { 63 var c = "uid="+UID; 64 var u = "returnStep.php"; 65 newAjaxRequest(c, u, function(result) { 66 var newDiv = result.responseText; 67 document.getElementById("seqContent").appendChild(newDiv); 68 }); 69 } 70 71 function ajaxInfoRequest(id, el) { 72 var uid = id; 73 var c = "uid="+uid; 74 var u = "getInfo.php"; 75 newAjaxRequest(c, u, function(result) { 76 el.innerHTML = result.responseText; 77 }); 78 } 79 80 /* 81 * This function allows for simple use of AJAX requests. 82 * Calling format: 83 * 84 * var c[] = "uid=123"; 85 * var c[] = "name=tschipper"; 86 * var u = "getResult.php"; 87 * newAjaxRequest(c, u, function(xml) { 88 * <!--Do something--> 89 * }); 90 * 91 * It is of course also possible to refer to an external function instead of 92 * defining function(xml){} in the call itself, as below: 93 * 94 * newAjaxRequest(c, u, externalFunction(xml)); 95 */ 96 97 function newAjaxRequest(c, u, cb) { 98 99 var xml; 100 var content = c; //an array of strings, in "key=value" format. 101 // assign a compatible request format 102 if (window.XMLHttpRequest) { //Not IE5, IE6 103 xml = new XMLHttpRequest(); 104 } 105 else { //IE5, IE6 106 xml = new ActiveXObject("Microsoft.XMLHTTP"); 107 } 108 // subscribe the callback function to a response event 109 xml.onreadystatechange = function() { 110 if (xml.readyState == 4 && xml.status == 200) { 111 //alert("Received!"); 112 cb(xml); 113 } 114 }; 115 // initialize XMLRequest 116 xml.open("POST", u, true); 117 xml.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 118 var contentString = ""; 119 //iterate through parameters passed in variable c 120 if (typeof(content)=='object'&&(input instanceof Array)) { // parameters were passed as an array of key=value strings 121 for (var i = 0; i < content.length; i++) { 122 contentString += content[i]; 123 if (i != (content.length - 1)) { 124 contentString += "&"; 125 } 126 } 127 } 128 else { // single parameter or string already formatted by calling function 129 contentString = content; 130 } 131 // finally send the formatted request 132 //alert(contentString); 133 xml.send(contentString); 134 } 135 136 137 function drawSteps() { 138 var sequencer = document.getElementById("sequencer"); 139 var seqContent = document.getElementById("seqContent"); 140 141 // first delete all current children of seqContent (to reset the sequencer). 142 while (seqContent.childNodes.length > 0) { 143 var step = seqContent.childNodes[0]; 144 step.parentNode.removeChild(step); 145 } 146 147 // get pipeline contents from hidden form inputs. 148 var pipeline = sequencer.controls.pipeline.value; 149 var pipeline = pipeline.split(", "); 150 151 // then do an xmlhttp request for each step to be added to the sequencer 152 var numberOfSteps = pipeline.length; 153 for (var i = 0; i > numberOfSteps; i++) { 154 ajaxStepRequest(pipeline[i]); 155 } 156 157 } 158
Note: See TracChangeset
for help on using the changeset viewer.