Changeset 166 for Dev/trunk/js
- Timestamp:
- 11/23/11 17:15:20 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk/js/sequencerScripts.js
r165 r166 25 25 } 26 26 27 /* 28 function SubmitToolbox() { 29 document.forms['toolbox'].submit(); 30 } 31 */ 27 function removeNL(s){ 28 return s.replace(/[\n\r\t]/g,""); 29 } 30 32 31 function SubmitToolbox(type) { 33 32 var c = "objectToCreate="+type; … … 39 38 40 39 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,"; 48 46 updateSequencer(); 49 47 }, a); … … 74 72 var nodes = document.getElementById("seqContent").childNodes; 75 73 for (var i = 0; i < nodes.length; i++) { //loop through childNodes. Skip first node (whitespace) 76 //debugger;77 74 if (hasClass(nodes[i], "displayStep")) { //check if current childNode is a displayStep, not divider or text. 78 75 if (nodes[i].id == uid) { … … 96 93 } 97 94 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 of111 * defining function(xml){} in the call itself, as below:112 *113 * newAjaxRequest(c, u, externalFunction(xml));114 */115 116 95 function newAjaxRequest(c, u, cb, async) { 117 96 … … 145 124 } 146 125 } 147 else { 126 else { // single parameter or string already formatted by calling function 148 127 contentString = content; 149 128 } 150 129 // finally send the formatted request 151 //alert(contentString);152 130 xml.send(contentString); 153 131 } … … 183 161 var pipeline = document.getElementById("pipelineStringField").value; 184 162 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 } 188 169 } 189 170 … … 192 173 var plTypeString = document.getElementById("pipelineTypeField").value; 193 174 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; 200 184 201 185 for (var i = 0; i < pl.length; i++) { // loop through pipeline contents … … 204 188 var seqContent = document.getElementById("seqContent"); 205 189 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 } 207 203 208 204 // now request a new step representation and insert it after previousElement 209 205 var holderDiv = document.createElement("div"); 210 206 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 212 214 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"; 214 222 }, false); 215 223 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, ","); 245 238 document.getElementById("pipelineUpdatedField").value = newUpdatedString; 246 239 247 240 } 241 242 243 244 245 246 247 function 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 248 285 249 286 function savePipeline() { 250 287 var answer = confirm("Save changes to pipeline?"); 251 288 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); 254 303 } 255 304 } … … 268 317 var plUpdatedString = document.getElementById("pipelineUpdatedField").value; 269 318 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, ","); 275 323 276 324 // 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"; 282 326 283 327 // 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, ","); 294 329 document.getElementById("pipelineUpdatedField").value = newUpdatedString; 295 //alert("OOD set"); 296 } 330 } 331 332 function 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 343 function 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.