1 | /* |
---|
2 | * To change this template, choose Tools | Templates |
---|
3 | * and open the template in the editor. |
---|
4 | */ |
---|
5 | var timeDiff = { |
---|
6 | setStartTime:function (){ |
---|
7 | d = new Date(); |
---|
8 | time = d.getTime(); |
---|
9 | }, |
---|
10 | |
---|
11 | getDiff:function (){ |
---|
12 | d = new Date(); |
---|
13 | return (d.getTime()-time); |
---|
14 | } |
---|
15 | } |
---|
16 | |
---|
17 | |
---|
18 | |
---|
19 | |
---|
20 | |
---|
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 | |
---|
42 | function removeNL(s){ |
---|
43 | return s.replace(/[\n\r\t]/g,""); |
---|
44 | } |
---|
45 | |
---|
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"); |
---|
53 | document.getElementById("numSteps").value++; |
---|
54 | |
---|
55 | newAjaxRequest(c, u, function(result){ |
---|
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,"; |
---|
62 | updateSequencer(); |
---|
63 | }, a); |
---|
64 | } |
---|
65 | |
---|
66 | // Class manipulation |
---|
67 | |
---|
68 | function hasClass(ele,cls) { |
---|
69 | if (ele.className) |
---|
70 | return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)')); |
---|
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 | } |
---|
83 | |
---|
84 | //new scripts! |
---|
85 | //start here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
---|
86 | |
---|
87 | function selectStep(uid) { |
---|
88 | /* |
---|
89 | |
---|
90 | var nodes = document.getElementById("seqContentWrapper").childNodes; |
---|
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) { |
---|
94 | if (hasClass(nodes[i], "selected")) { |
---|
95 | removeClass(nodes[i], "selected"); |
---|
96 | } |
---|
97 | else { |
---|
98 | addClass(nodes[i], "selected"); |
---|
99 | } |
---|
100 | } |
---|
101 | else { |
---|
102 | removeClass(nodes[i], "selected"); |
---|
103 | } |
---|
104 | } |
---|
105 | } |
---|
106 | */ |
---|
107 | // Hier is een snellere manier voor! |
---|
108 | var element = document.getElementById(uid); |
---|
109 | var prevElement = document.getElementById(document.getElementById("selectedStepField").value); |
---|
110 | |
---|
111 | if (!element || !hasClass(element, "displayStep")) { |
---|
112 | return; |
---|
113 | } |
---|
114 | // misschien nog checks inbouwen of het echt wel een element is? |
---|
115 | var selectedStepField = document.getElementById("selectedStepField"); |
---|
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 | } |
---|
133 | |
---|
134 | |
---|
135 | // Update selected step field with uid of currently selected step. |
---|
136 | |
---|
137 | |
---|
138 | } |
---|
139 | |
---|
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 | |
---|
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 | } |
---|
188 | |
---|
189 | function newAjaxRequest(c, u, cb, async) { |
---|
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() { |
---|
202 | xml.responseText = "Processing..."; |
---|
203 | if (xml.readyState == 4 && xml.status == 200) { |
---|
204 | cb(xml); |
---|
205 | } |
---|
206 | }; |
---|
207 | // initialize XMLRequest |
---|
208 | xml.open("POST", u, async); |
---|
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 | } |
---|
220 | else { // single parameter or string already formatted by calling function |
---|
221 | contentString = content; |
---|
222 | } |
---|
223 | // finally send the formatted request |
---|
224 | xml.send(contentString); |
---|
225 | } |
---|
226 | |
---|
227 | |
---|
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 | |
---|
233 | function ajaxStepRequest(UIDS, types) { |
---|
234 | var c = "uids="+UIDS; |
---|
235 | if (types != "") { |
---|
236 | c += "&types="+types; |
---|
237 | } |
---|
238 | var u = "returnStep.php"; |
---|
239 | newAjaxRequest(c, u, function(result) { |
---|
240 | document.getElementById("seqContentWrapper").innerHTML = result.responseText; |
---|
241 | }, true); |
---|
242 | } |
---|
243 | |
---|
244 | function ajaxInfoRequest(uid, el, type) { |
---|
245 | var c = "uid="+uid; |
---|
246 | c += "&type="+type; |
---|
247 | var u = "getInfo.php"; |
---|
248 | newAjaxRequest(c, u, function(result) { |
---|
249 | el.innerHTML = result.responseText; |
---|
250 | }, true); |
---|
251 | } |
---|
252 | |
---|
253 | function drawSteps2() { |
---|
254 | var content = document.getElementById("seqContentWrapper"); |
---|
255 | var pipeline = document.getElementById("pipelineStringField").value; |
---|
256 | var pipelineTypes = document.getElementById("pipelineTypeField").value; |
---|
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 | } |
---|
263 | } |
---|
264 | |
---|
265 | |
---|
266 | function updateSequencer(firstLoad) { |
---|
267 | // Load hidden field values |
---|
268 | |
---|
269 | var plString = document.getElementById("pipelineStringField").value; |
---|
270 | var plTypeString = document.getElementById("pipelineTypeField").value; |
---|
271 | var plUpdatedString = document.getElementById("pipelineUpdatedField").value; |
---|
272 | var count = document.getElementById("numSteps").value; |
---|
273 | |
---|
274 | if (count < 1) { |
---|
275 | document.getElementById("seqContentWrapper").innerHTML = ""; |
---|
276 | return; |
---|
277 | } |
---|
278 | // If this is on page-load time |
---|
279 | if (firstLoad == true) { |
---|
280 | var seqContent = document.getElementById("seqContentWrapper"); |
---|
281 | seqContent.innerHTML = ""; |
---|
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, ","); |
---|
299 | |
---|
300 | var count = pl.length; |
---|
301 | |
---|
302 | document.getElementById("numSteps").value = count; |
---|
303 | var seqContent = document.getElementById("seqContentWrapper"); |
---|
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) { |
---|
309 | seqContent.removeChild(seqContent.childNodes[0]); |
---|
310 | |
---|
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 | |
---|
319 | |
---|
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; |
---|
324 | |
---|
325 | |
---|
326 | // END IMPROVISE !!!!!!!!!!!! |
---|
327 | if (element == null) { |
---|
328 | element = document.createElement("div"); |
---|
329 | element.name = "placeholder"; |
---|
330 | seqContent.appendChild(element); |
---|
331 | } |
---|
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 | } |
---|
340 | |
---|
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 | |
---|
361 | |
---|
362 | // ALTERNATIVE METHOD TO REPLACECHILD!!! |
---|
363 | //seqContent.removeChild(element); |
---|
364 | //seqContent.insertBefore(newDiv, nextElement); |
---|
365 | |
---|
366 | // Now check if dividers are necessary. |
---|
367 | |
---|
368 | //alert("INSERT CODE FOR UPDATEDIVIDERS HERE!"); |
---|
369 | //alert(timeDiff.getDiff()); |
---|
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 | |
---|
386 | updateDividers(newDiv); |
---|
387 | } |
---|
388 | } |
---|
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; |
---|
393 | } |
---|
394 | } |
---|
395 | |
---|
396 | |
---|
397 | |
---|
398 | |
---|
399 | |
---|
400 | |
---|
401 | function updateDividers (element) { |
---|
402 | var seqContent = document.getElementById("seqContentWrapper"); |
---|
403 | |
---|
404 | if (element.nextSibling){ |
---|
405 | var nextElement = element.nextSibling; |
---|
406 | } |
---|
407 | if (element.previousSibling) { |
---|
408 | var previousElement = element.previousSibling; |
---|
409 | } |
---|
410 | |
---|
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 | } |
---|
420 | } |
---|
421 | |
---|
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 | |
---|
433 | } |
---|
434 | |
---|
435 | |
---|
436 | |
---|
437 | |
---|
438 | |
---|
439 | |
---|
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 | |
---|
449 | if (answer) { |
---|
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; |
---|
456 | console.log(requestString); |
---|
457 | |
---|
458 | |
---|
459 | var success; |
---|
460 | newAjaxRequest(requestString, "savesession.php", function(result){ |
---|
461 | success = result.responseText; |
---|
462 | }, false); |
---|
463 | console.log(success); |
---|
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 | |
---|
481 | var pl = stringToArray(plString, ","); |
---|
482 | var plType = stringToArray(plTypeString, ","); |
---|
483 | var plUpdated = stringToArray(plUpdatedString, ","); |
---|
484 | |
---|
485 | // set the targeted element's tag for "Needs updating" |
---|
486 | plUpdated[pl.indexOf(uid)] = "0"; |
---|
487 | |
---|
488 | // then rewrite the content strings and set them to the appropriate fields |
---|
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 | } |
---|
500 | } |
---|
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 | } |
---|
510 | } |
---|
511 | return s; |
---|
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); |
---|
518 | |
---|
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"); |
---|
527 | postForm.action = stepType.toLowerCase()+"Editor.php"; //redirect to "type"editor.php |
---|
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? |
---|
540 | |
---|
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); |
---|
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; |
---|
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 | |
---|
576 | // Then reselect the previously selected step |
---|
577 | addClass(document.getElementById(selectedStep), "selected"); |
---|
578 | } |
---|