[146] | 1 | /* |
---|
| 2 | * To change this template, choose Tools | Templates |
---|
| 3 | * and open the template in the editor. |
---|
| 4 | */ |
---|
[168] | 5 | var timeDiff = { |
---|
| 6 | setStartTime:function (){ |
---|
| 7 | d = new Date(); |
---|
| 8 | time = d.getTime(); |
---|
| 9 | }, |
---|
[146] | 10 | |
---|
[168] | 11 | getDiff:function (){ |
---|
| 12 | d = new Date(); |
---|
| 13 | return (d.getTime()-time); |
---|
| 14 | } |
---|
| 15 | } |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | |
---|
[146] | 21 | function IsItemSelected(check, target) { |
---|
| 22 | if (check.value) { |
---|
| 23 | target.disabled = false; |
---|
| 24 | } |
---|
| 25 | else { |
---|
| 26 | target.disabled = true; |
---|
| 27 | } |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | function IsCheckEnabled(check, target) { |
---|
| 31 | if (check.checked) { |
---|
| 32 | target.disabled = false; |
---|
| 33 | this.removeClass(target, "dis"); |
---|
| 34 | |
---|
| 35 | } |
---|
| 36 | else { |
---|
| 37 | target.disabled = true; |
---|
| 38 | this.addClass(target, "dis"); |
---|
| 39 | } |
---|
| 40 | } |
---|
| 41 | |
---|
[166] | 42 | function removeNL(s){ |
---|
| 43 | return s.replace(/[\n\r\t]/g,""); |
---|
[146] | 44 | } |
---|
[166] | 45 | |
---|
[165] | 46 | function SubmitToolbox(type) { |
---|
| 47 | var c = "objectToCreate="+type; |
---|
| 48 | var u = "createObject.php"; |
---|
| 49 | var a = true; |
---|
| 50 | var pipeline = document.getElementById("pipelineStringField"); |
---|
| 51 | var pipelineType = document.getElementById("pipelineTypeField"); |
---|
| 52 | var pipelineUpdated = document.getElementById("pipelineUpdatedField"); |
---|
[168] | 53 | document.getElementById("numSteps").value++; |
---|
[165] | 54 | |
---|
| 55 | newAjaxRequest(c, u, function(result){ |
---|
[166] | 56 | var resultUid = removeNL(result.responseText); |
---|
| 57 | //resultUid.replace("\n","").replace("\r",""); |
---|
| 58 | |
---|
| 59 | pipeline.value += resultUid+","; |
---|
| 60 | pipelineType.value += type+","; |
---|
| 61 | pipelineUpdated.value += "0,"; |
---|
[165] | 62 | updateSequencer(); |
---|
| 63 | }, a); |
---|
| 64 | } |
---|
[146] | 65 | |
---|
[152] | 66 | // Class manipulation |
---|
[146] | 67 | |
---|
[152] | 68 | function hasClass(ele,cls) { |
---|
[154] | 69 | if (ele.className) |
---|
| 70 | return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)')); |
---|
[152] | 71 | } |
---|
| 72 | |
---|
| 73 | function addClass(ele,cls) { |
---|
| 74 | if (!this.hasClass(ele,cls)) ele.className += " "+cls; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | function removeClass(ele,cls) { |
---|
| 78 | if (hasClass(ele,cls)) { |
---|
| 79 | var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)'); |
---|
| 80 | ele.className=ele.className.replace(reg,' '); |
---|
| 81 | } |
---|
| 82 | } |
---|
[146] | 83 | |
---|
[152] | 84 | //new scripts! |
---|
| 85 | //start here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
---|
| 86 | |
---|
| 87 | function selectStep(uid) { |
---|
[168] | 88 | /* |
---|
| 89 | |
---|
[167] | 90 | var nodes = document.getElementById("seqContentWrapper").childNodes; |
---|
[154] | 91 | for (var i = 0; i < nodes.length; i++) { //loop through childNodes. Skip first node (whitespace) |
---|
| 92 | if (hasClass(nodes[i], "displayStep")) { //check if current childNode is a displayStep, not divider or text. |
---|
| 93 | if (nodes[i].id == uid) { |
---|
[164] | 94 | if (hasClass(nodes[i], "selected")) { |
---|
| 95 | removeClass(nodes[i], "selected"); |
---|
| 96 | } |
---|
| 97 | else { |
---|
| 98 | addClass(nodes[i], "selected"); |
---|
| 99 | } |
---|
[154] | 100 | } |
---|
| 101 | else { |
---|
| 102 | removeClass(nodes[i], "selected"); |
---|
| 103 | } |
---|
| 104 | } |
---|
[153] | 105 | } |
---|
[168] | 106 | */ |
---|
| 107 | // Hier is een snellere manier voor! |
---|
| 108 | var element = document.getElementById(uid); |
---|
| 109 | var prevElement = document.getElementById(document.getElementById("selectedStepField").value); |
---|
[154] | 110 | |
---|
[168] | 111 | if (!element || !hasClass(element, "displayStep")) { |
---|
| 112 | return; |
---|
| 113 | } |
---|
| 114 | // misschien nog checks inbouwen of het echt wel een element is? |
---|
[154] | 115 | var selectedStepField = document.getElementById("selectedStepField"); |
---|
[168] | 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 | } |
---|
[154] | 133 | |
---|
[168] | 134 | |
---|
| 135 | // Update selected step field with uid of currently selected step. |
---|
| 136 | |
---|
| 137 | |
---|
[152] | 138 | } |
---|
[168] | 139 | |
---|
[169] | 140 | function deleteStep() { |
---|
| 141 | // delete an object from the session. |
---|
| 142 | // note: does not actually remove the object from the database, only takes it out of the pipeline array. |
---|
| 143 | |
---|
| 144 | var pl = stringToArray(document.getElementById("pipelineStringField").value, ","); |
---|
| 145 | var plType = stringToArray(document.getElementById("pipelineTypeField").value, ","); |
---|
| 146 | var plUpdated = stringToArray(document.getElementById("pipelineUpdatedField").value, ","); |
---|
| 147 | var selectedStep = document.getElementById("selectedStepField").value; |
---|
| 148 | |
---|
| 149 | // if no step has been selected, exit the function |
---|
| 150 | if (selectedStep == undefined || selectedStep == "") { |
---|
| 151 | return; |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | // find the array index of the specified object uid, then remove it from all three arrays. |
---|
| 155 | var index = pl.indexOf(selectedStep); |
---|
| 156 | if (index >= 0 && index < pl.length) { |
---|
| 157 | pl.splice(index, 1); |
---|
| 158 | plType.splice(index, 1); |
---|
| 159 | plUpdated.splice(index, 1); |
---|
| 160 | // set the updated status of all objects from *index* and forward to "0" (out of date) |
---|
| 161 | // this way they will be refreshed the next time updateSequencer(); is called, adn the visual display will match the new pipeline. |
---|
| 162 | for (var i = index-1; i < plUpdated.length; i++) { |
---|
| 163 | if (i >= 0 ) { |
---|
| 164 | plUpdated[i] = "0"; |
---|
| 165 | } |
---|
| 166 | } |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | document.getElementById("pipelineStringField").value = arrayToString(pl, ","); |
---|
| 170 | document.getElementById("pipelineTypeField").value = arrayToString(plType, ","); |
---|
| 171 | document.getElementById("pipelineUpdatedField").value = arrayToString(plUpdated, ","); |
---|
| 172 | deselectStep(selectedStep); // Make sure the info panel is up to date as well. (Not showing anything, as it should be...) |
---|
| 173 | document.getElementById("numSteps").value--; |
---|
| 174 | |
---|
| 175 | updateSequencer(false); |
---|
| 176 | |
---|
| 177 | |
---|
| 178 | |
---|
| 179 | } |
---|
| 180 | |
---|
[168] | 181 | function deselectStep(uid) { |
---|
| 182 | var field = document.getElementById("selectedStepField"); |
---|
| 183 | field.value = ""; |
---|
| 184 | var element = document.getElementById(uid); |
---|
| 185 | removeClass(element, "selected"); |
---|
| 186 | document.getElementById("infoPanelContent").innerHTML = ""; |
---|
| 187 | } |
---|
[152] | 188 | |
---|
[164] | 189 | function newAjaxRequest(c, u, cb, async) { |
---|
[152] | 190 | |
---|
| 191 | var xml; |
---|
| 192 | var content = c; //an array of strings, in "key=value" format. |
---|
| 193 | // assign a compatible request format |
---|
| 194 | if (window.XMLHttpRequest) { //Not IE5, IE6 |
---|
| 195 | xml = new XMLHttpRequest(); |
---|
| 196 | } |
---|
| 197 | else { //IE5, IE6 |
---|
| 198 | xml = new ActiveXObject("Microsoft.XMLHTTP"); |
---|
| 199 | } |
---|
| 200 | // subscribe the callback function to a response event |
---|
| 201 | xml.onreadystatechange = function() { |
---|
[164] | 202 | xml.responseText = "Processing..."; |
---|
[152] | 203 | if (xml.readyState == 4 && xml.status == 200) { |
---|
| 204 | cb(xml); |
---|
| 205 | } |
---|
| 206 | }; |
---|
| 207 | // initialize XMLRequest |
---|
[164] | 208 | xml.open("POST", u, async); |
---|
[152] | 209 | xml.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); |
---|
| 210 | var contentString = ""; |
---|
| 211 | //iterate through parameters passed in variable c |
---|
| 212 | if (typeof(content)=='object'&&(input instanceof Array)) { // parameters were passed as an array of key=value strings |
---|
| 213 | for (var i = 0; i < content.length; i++) { |
---|
| 214 | contentString += content[i]; |
---|
| 215 | if (i != (content.length - 1)) { |
---|
| 216 | contentString += "&"; |
---|
| 217 | } |
---|
| 218 | } |
---|
| 219 | } |
---|
[166] | 220 | else { // single parameter or string already formatted by calling function |
---|
[152] | 221 | contentString = content; |
---|
| 222 | } |
---|
| 223 | // finally send the formatted request |
---|
| 224 | xml.send(contentString); |
---|
| 225 | } |
---|
[153] | 226 | |
---|
[154] | 227 | |
---|
[153] | 228 | /* |
---|
| 229 | * ajaxStepRequest gets the markup for displaying a step in the sequencer from returnStep.php |
---|
| 230 | * Using ajax principle allows for editing of pipeline without constantly refreshing the page. |
---|
| 231 | */ |
---|
| 232 | |
---|
[165] | 233 | function ajaxStepRequest(UIDS, types) { |
---|
[154] | 234 | var c = "uids="+UIDS; |
---|
[165] | 235 | if (types != "") { |
---|
| 236 | c += "&types="+types; |
---|
| 237 | } |
---|
[153] | 238 | var u = "returnStep.php"; |
---|
| 239 | newAjaxRequest(c, u, function(result) { |
---|
[167] | 240 | document.getElementById("seqContentWrapper").innerHTML = result.responseText; |
---|
[164] | 241 | }, true); |
---|
[153] | 242 | } |
---|
| 243 | |
---|
[168] | 244 | function ajaxInfoRequest(uid, el, type) { |
---|
[153] | 245 | var c = "uid="+uid; |
---|
[168] | 246 | c += "&type="+type; |
---|
[153] | 247 | var u = "getInfo.php"; |
---|
| 248 | newAjaxRequest(c, u, function(result) { |
---|
| 249 | el.innerHTML = result.responseText; |
---|
[164] | 250 | }, true); |
---|
[153] | 251 | } |
---|
[146] | 252 | |
---|
[167] | 253 | function drawSteps2() { |
---|
| 254 | var content = document.getElementById("seqContentWrapper"); |
---|
[153] | 255 | var pipeline = document.getElementById("pipelineStringField").value; |
---|
[165] | 256 | var pipelineTypes = document.getElementById("pipelineTypeField").value; |
---|
[166] | 257 | var numSteps = document.getElementById("numSteps").value; |
---|
| 258 | if (numSteps > 0) { |
---|
| 259 | pipeline = pipeline.replace(/,/g , ",divider,"); //regex search for commas, global (repeat), to represent them with visual dividers. |
---|
| 260 | pipelineTypes = pipelineTypes.replace(/,/g, ",divider,"); |
---|
| 261 | ajaxStepRequest(pipeline, pipelineTypes); |
---|
| 262 | } |
---|
[146] | 263 | } |
---|
| 264 | |
---|
[167] | 265 | |
---|
[168] | 266 | function updateSequencer(firstLoad) { |
---|
| 267 | // Load hidden field values |
---|
[169] | 268 | |
---|
[164] | 269 | var plString = document.getElementById("pipelineStringField").value; |
---|
| 270 | var plTypeString = document.getElementById("pipelineTypeField").value; |
---|
| 271 | var plUpdatedString = document.getElementById("pipelineUpdatedField").value; |
---|
[168] | 272 | var count = document.getElementById("numSteps").value; |
---|
[153] | 273 | |
---|
[168] | 274 | if (count < 1) { |
---|
[169] | 275 | document.getElementById("seqContentWrapper").innerHTML = ""; |
---|
[168] | 276 | return; |
---|
| 277 | } |
---|
| 278 | // If this is on page-load time |
---|
| 279 | if (firstLoad == true) { |
---|
[169] | 280 | var seqContent = document.getElementById("seqContentWrapper"); |
---|
| 281 | seqContent.innerHTML = ""; |
---|
[168] | 282 | requestString = plString.slice(0, -1); |
---|
| 283 | requestString = requestString.replace(/,/g, ",divider,"); |
---|
| 284 | newAjaxRequest("uids="+requestString, "returnStep.php", function(result) { |
---|
| 285 | seqContent.innerHTML = result.responseText; |
---|
| 286 | }, true); |
---|
| 287 | |
---|
| 288 | plUpdatedString = ""; |
---|
| 289 | for (var i = 0; i < plString.split(",").length-1; i++) { |
---|
| 290 | plUpdatedString += "1,"; |
---|
| 291 | } |
---|
| 292 | |
---|
| 293 | document.getElementById("pipelineUpdatedField").value = plUpdatedString; |
---|
| 294 | } |
---|
| 295 | else { // if not |
---|
| 296 | var pl = stringToArray(plString, ","); |
---|
| 297 | var plType = stringToArray(plTypeString, ","); |
---|
| 298 | var plUpdated = stringToArray(plUpdatedString, ","); |
---|
[164] | 299 | |
---|
[168] | 300 | var count = pl.length; |
---|
[166] | 301 | |
---|
[168] | 302 | document.getElementById("numSteps").value = count; |
---|
| 303 | var seqContent = document.getElementById("seqContentWrapper"); |
---|
[169] | 304 | // hier zit een fout. Als er een deleted step nog in de pipeline staat haalt hij de eerste valid step weg ipv een text node. |
---|
| 305 | // twee mogelijkheden: |
---|
| 306 | // 1: check of het text node is. |
---|
| 307 | // 2: modulo check of het een even aantal steps is. Als alles klopt kan er onmogelijk een even aantal childNodes zijn. |
---|
| 308 | if (seqContent.childNodes.length % 2 == 0 && seqContent.childNodes.length > 0) { |
---|
[168] | 309 | seqContent.removeChild(seqContent.childNodes[0]); |
---|
[164] | 310 | |
---|
[168] | 311 | } |
---|
| 312 | |
---|
| 313 | |
---|
| 314 | for (var i = 0; i < pl.length; i++) { // loop through pipeline contents |
---|
| 315 | if (plUpdated[i] == "0") { // if the element is not up to date |
---|
| 316 | // first remove the step representation from the sequencer |
---|
| 317 | //timeDiff.setStartTime(); |
---|
| 318 | |
---|
[166] | 319 | |
---|
[168] | 320 | // IMPROVISE !!!!!!!!!! |
---|
| 321 | var elementByIndex = seqContent.childNodes[2*i]; // works with moved steps |
---|
| 322 | 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. |
---|
| 323 | var element = elementByIndex; |
---|
[166] | 324 | |
---|
[168] | 325 | |
---|
| 326 | // END IMPROVISE !!!!!!!!!!!! |
---|
| 327 | if (element == null) { |
---|
| 328 | element = document.createElement("div"); |
---|
| 329 | element.name = "placeholder"; |
---|
| 330 | seqContent.appendChild(element); |
---|
[166] | 331 | } |
---|
[168] | 332 | if (element.nextSibling) { |
---|
| 333 | var nextElement = element.nextSibling; |
---|
| 334 | } |
---|
| 335 | else { |
---|
| 336 | var nextElement = document.createElement("div"); |
---|
| 337 | nextElement.name = "placeholderNext"; |
---|
| 338 | seqContent.appendChild(nextElement); |
---|
| 339 | } |
---|
[164] | 340 | |
---|
[168] | 341 | // now request a new step representation and insert it after previousElement |
---|
| 342 | var holderDiv = document.createElement("div"); |
---|
| 343 | var requestString = "uids="+pl[i]; |
---|
| 344 | |
---|
| 345 | if (plType[i]) { |
---|
| 346 | requestString += "&types="+plType[i]; |
---|
| 347 | } |
---|
| 348 | // globally declare newDiv so it can be passed to the updateDividers function |
---|
| 349 | var newDiv; |
---|
| 350 | |
---|
| 351 | newAjaxRequest(requestString, "returnStep.php", function(result) { |
---|
| 352 | holderDiv.innerHTML = result.responseText; |
---|
| 353 | newDiv = holderDiv.childNodes[1]; |
---|
| 354 | seqContent.replaceChild(newDiv, element); |
---|
| 355 | if (nextElement.name == "placeholderNext") { |
---|
| 356 | seqContent.removeChild(nextElement); |
---|
| 357 | } |
---|
| 358 | plUpdated[i] = "1"; |
---|
| 359 | }, false); |
---|
| 360 | |
---|
[166] | 361 | |
---|
[168] | 362 | // ALTERNATIVE METHOD TO REPLACECHILD!!! |
---|
| 363 | //seqContent.removeChild(element); |
---|
| 364 | //seqContent.insertBefore(newDiv, nextElement); |
---|
[164] | 365 | |
---|
[168] | 366 | // Now check if dividers are necessary. |
---|
[164] | 367 | |
---|
[168] | 368 | //alert("INSERT CODE FOR UPDATEDIVIDERS HERE!"); |
---|
| 369 | //alert(timeDiff.getDiff()); |
---|
[169] | 370 | |
---|
| 371 | // If seqContent contains any further entries when the last pipeline uid has been drawn, these are to be removed. |
---|
| 372 | // This happens after the user performs a "delete step" operation and there is now one fewer step in the array than in seqContent. |
---|
| 373 | // All steps other than the first and the last are auto-adjusted due to "out of date" flag. |
---|
| 374 | if (i >= pl.length - 1) { |
---|
| 375 | |
---|
| 376 | // This is a really complicated way of saying "Delete the next two elements if they exist" |
---|
| 377 | while ((nextElement = newDiv.nextSibling) != undefined) { |
---|
| 378 | seqContent.removeChild(nextElement); |
---|
| 379 | } |
---|
| 380 | |
---|
| 381 | } |
---|
| 382 | // Do the same check for the first step in the pipeline. |
---|
| 383 | // Is there no more elegant solution for this? For instance, check if a step should be in the pipeline in the first place, else delete it and it's following divider |
---|
| 384 | |
---|
| 385 | |
---|
[168] | 386 | updateDividers(newDiv); |
---|
| 387 | } |
---|
[164] | 388 | } |
---|
[168] | 389 | |
---|
| 390 | // afterwards, convert the arrays back to strings and set to appropriate fields |
---|
| 391 | var newUpdatedString = arrayToString(plUpdated, ","); |
---|
| 392 | document.getElementById("pipelineUpdatedField").value = newUpdatedString; |
---|
[164] | 393 | } |
---|
[166] | 394 | } |
---|
| 395 | |
---|
| 396 | |
---|
| 397 | |
---|
| 398 | |
---|
| 399 | |
---|
| 400 | |
---|
| 401 | function updateDividers (element) { |
---|
[167] | 402 | var seqContent = document.getElementById("seqContentWrapper"); |
---|
[166] | 403 | |
---|
| 404 | if (element.nextSibling){ |
---|
| 405 | var nextElement = element.nextSibling; |
---|
[164] | 406 | } |
---|
[166] | 407 | if (element.previousSibling) { |
---|
| 408 | var previousElement = element.previousSibling; |
---|
| 409 | } |
---|
[164] | 410 | |
---|
[166] | 411 | if (nextElement){ |
---|
| 412 | if (!hasClass(nextElement, "divider")) { |
---|
| 413 | var holderDiv = document.createElement("div"); |
---|
| 414 | newAjaxRequest("uids=divider&types=divider", "returnStep.php", function(result) { |
---|
| 415 | holderDiv.innerHTML = result.responseText; |
---|
| 416 | var newDivider = holderDiv.childNodes[1]; |
---|
| 417 | seqContent.insertBefore(newDivider, nextElement); |
---|
| 418 | }, false); |
---|
| 419 | } |
---|
[164] | 420 | } |
---|
| 421 | |
---|
[166] | 422 | if (previousElement){ |
---|
| 423 | if (!hasClass(previousElement, "divider")) { |
---|
| 424 | var holderDiv = document.createElement("div"); |
---|
| 425 | newAjaxRequest("uids=divider&types=divider", "returnStep.php", function(result) { |
---|
| 426 | holderDiv.innerHTML = result.responseText; |
---|
| 427 | var newDivider = holderDiv.childNodes[1]; |
---|
| 428 | seqContent.insertBefore(newDivider, element); |
---|
| 429 | }, false); |
---|
| 430 | } |
---|
| 431 | } |
---|
| 432 | |
---|
[164] | 433 | } |
---|
| 434 | |
---|
[166] | 435 | |
---|
| 436 | |
---|
| 437 | |
---|
| 438 | |
---|
| 439 | |
---|
[167] | 440 | function savePipeline (confirmSave) { |
---|
| 441 | if (confirmSave==true) { |
---|
| 442 | var answer = confirm("Save changes to pipeline?"); |
---|
| 443 | } |
---|
| 444 | else { |
---|
| 445 | var answer = true; |
---|
| 446 | } |
---|
| 447 | |
---|
| 448 | |
---|
[164] | 449 | if (answer) { |
---|
[166] | 450 | var pipeline = document.getElementById("pipelineStringField").value; |
---|
| 451 | pipeline = pipeline.slice(0, pipeline.length - 1); |
---|
| 452 | var types = document.getElementById("pipelineTypeField").value; |
---|
| 453 | types = types.slice(0, types.length - 1); |
---|
| 454 | var session = document.getElementById("sessionField").value; |
---|
| 455 | var requestString = "uids="+pipeline+"&types="+types+"&sessionUid="+session; |
---|
[167] | 456 | console.log(requestString); |
---|
[166] | 457 | |
---|
| 458 | |
---|
| 459 | var success; |
---|
| 460 | newAjaxRequest(requestString, "savesession.php", function(result){ |
---|
| 461 | success = result.responseText; |
---|
| 462 | }, false); |
---|
| 463 | console.log(success); |
---|
[164] | 464 | } |
---|
| 465 | } |
---|
| 466 | |
---|
| 467 | function t_setOutOfDate() { |
---|
| 468 | // if a step is currently selected |
---|
| 469 | var uid = document.getElementById("selectedStepField").value; |
---|
| 470 | if (uid == "") { |
---|
| 471 | alert("No step selected!"); |
---|
| 472 | return; |
---|
| 473 | } |
---|
| 474 | |
---|
| 475 | // convert to arrays for looping |
---|
| 476 | var plString = document.getElementById("pipelineStringField").value; |
---|
| 477 | var plTypeString = document.getElementById("pipelineTypeField").value; |
---|
| 478 | var plUpdatedString = document.getElementById("pipelineUpdatedField").value; |
---|
| 479 | |
---|
| 480 | |
---|
[166] | 481 | var pl = stringToArray(plString, ","); |
---|
| 482 | var plType = stringToArray(plTypeString, ","); |
---|
| 483 | var plUpdated = stringToArray(plUpdatedString, ","); |
---|
[164] | 484 | |
---|
| 485 | // set the targeted element's tag for "Needs updating" |
---|
[166] | 486 | plUpdated[pl.indexOf(uid)] = "0"; |
---|
[164] | 487 | |
---|
| 488 | // then rewrite the content strings and set them to the appropriate fields |
---|
[166] | 489 | var newUpdatedString = arrayToString(plUpdated, ","); |
---|
| 490 | document.getElementById("pipelineUpdatedField").value = newUpdatedString; |
---|
| 491 | } |
---|
| 492 | |
---|
| 493 | function stringToArray(s, c) { |
---|
| 494 | var a = s.split(c); |
---|
| 495 | for (var i = 0; i < a.length; i++) { // remove empty items |
---|
| 496 | if (a[i] == "") { |
---|
| 497 | a.splice(i, 1); |
---|
| 498 | i--; |
---|
| 499 | } |
---|
[164] | 500 | } |
---|
[166] | 501 | return a; |
---|
| 502 | } |
---|
| 503 | |
---|
| 504 | function arrayToString(a, c) { |
---|
| 505 | var s = ""; |
---|
| 506 | for (var i = 0; i < a.length; i++) { |
---|
| 507 | if (a[i] != "") { |
---|
| 508 | s += a[i]+c; |
---|
| 509 | } |
---|
[164] | 510 | } |
---|
[166] | 511 | return s; |
---|
[167] | 512 | } |
---|
| 513 | |
---|
| 514 | |
---|
| 515 | function editStep() { |
---|
| 516 | // eerst saven, dan de object type zoeken in de typelist, dan redirecten naar de goede pagina |
---|
| 517 | savePipeline(false); |
---|
[168] | 518 | |
---|
[167] | 519 | var pipeline = document.getElementById("pipelineStringField").value; |
---|
| 520 | var pipelineTypes = document.getElementById("pipelineTypeField").value; |
---|
| 521 | var selectedStep = document.getElementById("selectedStepField").value; |
---|
| 522 | pipeline = stringToArray(pipeline, ","); |
---|
| 523 | pipelineTypes = stringToArray(pipelineTypes, ","); |
---|
| 524 | var stepType = pipelineTypes[pipeline.indexOf(selectedStep)]; |
---|
| 525 | |
---|
| 526 | var postForm = document.createElement("form"); |
---|
[168] | 527 | postForm.action = stepType.toLowerCase()+"Editor.php"; //redirect to "type"editor.php |
---|
[167] | 528 | postForm.method = "POST"; |
---|
| 529 | var objectUid = document.createElement("input"); |
---|
| 530 | objectUid.type = "hidden"; |
---|
| 531 | objectUid.value = selectedStep; |
---|
| 532 | postForm.appendChild(objectUid); |
---|
| 533 | postForm.submit(); |
---|
| 534 | } |
---|
| 535 | |
---|
| 536 | |
---|
| 537 | |
---|
| 538 | function moveStep (direction) { |
---|
| 539 | // misschien maar eens een loadhiddenfields functie maken voor deze meuk? |
---|
[168] | 540 | |
---|
[167] | 541 | var selectedStep = document.getElementById("selectedStepField").value; |
---|
| 542 | |
---|
| 543 | if (selectedStep != undefined && selectedStep != "") { |
---|
| 544 | var pipeline = stringToArray(document.getElementById("pipelineStringField").value, ","); |
---|
| 545 | var pipelineTypes = stringToArray(document.getElementById("pipelineTypeField").value, ","); |
---|
| 546 | var updated = stringToArray(document.getElementById("pipelineUpdatedField").value, ","); |
---|
| 547 | } |
---|
| 548 | else { |
---|
| 549 | alert("No step selected! Unable to move"); |
---|
| 550 | return; |
---|
| 551 | } |
---|
| 552 | |
---|
| 553 | var id = pipeline.indexOf(selectedStep); |
---|
[168] | 554 | if ((id == 0 && direction == -1) || (id == pipeline.length-1 && direction == 1)){ |
---|
| 555 | alert("Cannot move out of bounds!"); |
---|
| 556 | return; |
---|
| 557 | } |
---|
| 558 | var tempString = pipeline[id], tempType = pipelineTypes[id]; |
---|
| 559 | |
---|
| 560 | pipeline[id] = pipeline[id+direction]; |
---|
| 561 | pipelineTypes[id] = pipelineTypes[id+direction]; |
---|
| 562 | pipeline[id+direction] = tempString; |
---|
| 563 | pipelineTypes[id+direction] = tempType; |
---|
[167] | 564 | updated[id] = "0"; |
---|
| 565 | updated[id+direction] = "0"; |
---|
| 566 | |
---|
| 567 | pipeline = arrayToString(pipeline, ","); |
---|
| 568 | pipelineTypes = arrayToString(pipelineTypes, ","); |
---|
| 569 | updated = arrayToString(updated, ","); |
---|
| 570 | |
---|
| 571 | document.getElementById("pipelineStringField").value = pipeline; |
---|
| 572 | document.getElementById("pipelineTypeField").value = pipelineTypes; |
---|
| 573 | document.getElementById("pipelineUpdatedField").value = updated; |
---|
| 574 | updateSequencer(); |
---|
| 575 | |
---|
[168] | 576 | // Then reselect the previously selected step |
---|
| 577 | addClass(document.getElementById(selectedStep), "selected"); |
---|
[154] | 578 | } |
---|