source: Dev/trunk/js/sequencerScripts.js @ 165

Last change on this file since 165 was 165, checked in by fpvanagthoven, 13 years ago
File size: 9.3 KB
Line 
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6function IsItemSelected(check, target) {
7    if (check.value) {
8        target.disabled = false;
9    }
10    else {
11        target.disabled = true;
12    }
13}
14
15function IsCheckEnabled(check, target) {
16    if (check.checked) {
17        target.disabled = false;
18        this.removeClass(target, "dis");
19       
20    }
21    else {
22        target.disabled = true;
23        this.addClass(target, "dis");
24    }
25}
26
27/*
28function SubmitToolbox() {
29    document.forms['toolbox'].submit();
30}
31*/
32function SubmitToolbox(type) {
33    var c = "objectToCreate="+type;
34    var u = "createObject.php";
35    var a = true;
36    var pipeline = document.getElementById("pipelineStringField");
37    var pipelineType = document.getElementById("pipelineTypeField");
38    var pipelineUpdated = document.getElementById("pipelineUpdatedField");
39   
40    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";
48        updateSequencer();
49    }, a);
50}
51
52// Class manipulation
53
54function hasClass(ele,cls) {
55    if (ele.className)
56        return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
57}
58 
59function addClass(ele,cls) {
60    if (!this.hasClass(ele,cls)) ele.className += " "+cls;
61}
62 
63function removeClass(ele,cls) {
64    if (hasClass(ele,cls)) {
65        var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
66        ele.className=ele.className.replace(reg,' ');
67    }
68}
69
70//new scripts!
71//start here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
72
73function selectStep(uid) {
74    var nodes = document.getElementById("seqContent").childNodes;
75    for (var i = 0; i < nodes.length; i++) {     //loop through childNodes. Skip first node (whitespace)
76        //debugger;
77        if (hasClass(nodes[i], "displayStep")) {    //check if current childNode is a displayStep, not divider or text.
78            if (nodes[i].id == uid) {
79                if (hasClass(nodes[i], "selected")) {
80                    removeClass(nodes[i], "selected");
81                }
82                else {
83                    addClass(nodes[i], "selected");
84                }               
85            }
86            else {
87                removeClass(nodes[i], "selected");
88            }
89        }
90    }
91   
92    // Update selected step field with uid of currently selected step.
93    var selectedStepField = document.getElementById("selectedStepField");
94    selectedStepField.value = uid;
95   
96}
97                                                                           
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 of
111 *  defining function(xml){} in the call itself, as below:
112 * 
113 *  newAjaxRequest(c, u, externalFunction(xml));
114 */
115
116function newAjaxRequest(c, u, cb, async) {
117   
118    var xml;
119    var content = c;    //an array of strings, in "key=value"  format.
120    // assign a compatible request format
121    if (window.XMLHttpRequest) {    //Not IE5, IE6
122        xml = new XMLHttpRequest();
123    }
124    else {                          //IE5, IE6
125        xml = new ActiveXObject("Microsoft.XMLHTTP");
126    }
127    // subscribe the callback function to a response event
128    xml.onreadystatechange = function() {
129        xml.responseText = "Processing...";
130        if (xml.readyState == 4 && xml.status == 200) {
131            cb(xml);
132        }
133    };
134    // initialize XMLRequest
135    xml.open("POST", u, async);
136    xml.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
137    var contentString = "";
138    //iterate through parameters passed in variable c
139    if (typeof(content)=='object'&&(input instanceof Array)) {    // parameters were passed as an array of key=value strings
140        for (var i = 0; i < content.length; i++) {
141            contentString += content[i];
142            if (i != (content.length - 1)) {
143                contentString += "&";
144            }
145        }
146    }
147    else {                      // single parameter or string already formatted by calling function
148        contentString = content;
149    }
150    // finally send the formatted request
151    //alert(contentString);
152    xml.send(contentString);
153}
154
155
156/*
157 * ajaxStepRequest gets  the markup for displaying a step in the sequencer from returnStep.php
158 * Using ajax principle allows for editing of pipeline without constantly refreshing the page.
159 */
160
161function ajaxStepRequest(UIDS, types) {
162    var c = "uids="+UIDS;
163    if (types != "") {
164        c += "&types="+types;
165    }
166    var u = "returnStep.php";
167    newAjaxRequest(c, u, function(result) {
168        document.getElementById("seqContent").innerHTML = result.responseText;
169    }, true);
170}
171
172function ajaxInfoRequest(id, el) {
173    var uid = id;
174    var c = "uid="+uid;
175    var u = "getInfo.php";
176    newAjaxRequest(c, u, function(result) {
177        el.innerHTML = result.responseText;
178    }, true);
179}
180
181function drawSteps() {
182    var content = document.getElementById("seqContent");
183    var pipeline = document.getElementById("pipelineStringField").value;
184    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);
188}
189
190function updateSequencer() {
191    var plString = document.getElementById("pipelineStringField").value;
192    var plTypeString = document.getElementById("pipelineTypeField").value;
193    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   
200   
201    for (var i = 0; i < pl.length; i++) {   // loop through pipeline contents
202        if (plUpdated[i] == "0") {   // if the element is not up to date
203            // first remove the step representation from the sequencer
204            var seqContent = document.getElementById("seqContent");
205            var element = document.getElementById(pl[i]);
206            var nextElement = element.nextSibling;
207           
208            // now request a new step representation and insert it after previousElement
209            var holderDiv = document.createElement("div");
210            var requestString = "uids="+pl[i];
211            var resultText;
212            newAjaxRequest(requestString, "returnStep.php", function(result) {
213                holderDiv.innerHTML = result.responseText;
214            }, false);
215           
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    }
245    document.getElementById("pipelineUpdatedField").value = newUpdatedString;
246   
247}
248
249function savePipeline() {
250    var answer = confirm("Save changes to pipeline?");
251    if (answer) {
252        newAjaxRequest("", "savesession.php", function(){}, false);
253        alert("Saved!");
254    }
255}
256
257function t_setOutOfDate() {
258    // if a step is currently selected
259    var uid = document.getElementById("selectedStepField").value;
260    if (uid == "") {
261        alert("No step selected!");
262        return;
263    }
264   
265    // convert to arrays for looping
266    var plString = document.getElementById("pipelineStringField").value;
267    var plTypeString = document.getElementById("pipelineTypeField").value;
268    var plUpdatedString = document.getElementById("pipelineUpdatedField").value;
269   
270    var pl = plString.split(",");
271    var plType = plTypeString.split(",");
272    var plUpdated = plUpdatedString.split(",");
273   
274   
275   
276    // 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    }
282   
283    // 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   
294    document.getElementById("pipelineUpdatedField").value = newUpdatedString;
295//alert("OOD set");
296}
Note: See TracBrowser for help on using the repository browser.