1 | /* |
---|
2 | * To change this template, choose Tools | Templates |
---|
3 | * and open the template in the editor. |
---|
4 | */ |
---|
5 | |
---|
6 | function IsItemSelected(check, target) { |
---|
7 | if (check.value) { |
---|
8 | target.disabled = false; |
---|
9 | } |
---|
10 | else { |
---|
11 | target.disabled = true; |
---|
12 | } |
---|
13 | } |
---|
14 | |
---|
15 | function 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 | function SubmitToolbox() { |
---|
28 | document.forms['toolbox'].submit(); |
---|
29 | } |
---|
30 | |
---|
31 | // Class manipulation |
---|
32 | |
---|
33 | function hasClass(ele,cls) { |
---|
34 | if (ele.className) |
---|
35 | return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)')); |
---|
36 | } |
---|
37 | |
---|
38 | function addClass(ele,cls) { |
---|
39 | if (!this.hasClass(ele,cls)) ele.className += " "+cls; |
---|
40 | } |
---|
41 | |
---|
42 | function removeClass(ele,cls) { |
---|
43 | if (hasClass(ele,cls)) { |
---|
44 | var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)'); |
---|
45 | ele.className=ele.className.replace(reg,' '); |
---|
46 | } |
---|
47 | } |
---|
48 | |
---|
49 | //new scripts! |
---|
50 | //start here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
---|
51 | |
---|
52 | function selectStep(uid) { |
---|
53 | var nodes = document.getElementById("seqContent").childNodes; |
---|
54 | for (var i = 0; i < nodes.length; i++) { //loop through childNodes. Skip first node (whitespace) |
---|
55 | //debugger; |
---|
56 | if (hasClass(nodes[i], "displayStep")) { //check if current childNode is a displayStep, not divider or text. |
---|
57 | if (nodes[i].id == uid) { |
---|
58 | if (hasClass(nodes[i], "selected")) { |
---|
59 | removeClass(nodes[i], "selected"); |
---|
60 | } |
---|
61 | else { |
---|
62 | addClass(nodes[i], "selected"); |
---|
63 | } |
---|
64 | } |
---|
65 | else { |
---|
66 | removeClass(nodes[i], "selected"); |
---|
67 | } |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | // Update selected step field with uid of currently selected step. |
---|
72 | var selectedStepField = document.getElementById("selectedStepField"); |
---|
73 | selectedStepField.value = uid; |
---|
74 | |
---|
75 | } |
---|
76 | |
---|
77 | |
---|
78 | /* |
---|
79 | * This function allows for simple use of AJAX requests. |
---|
80 | * Calling format: |
---|
81 | * |
---|
82 | * var c[] = "uid=123"; |
---|
83 | * var c[] = "name=tschipper"; |
---|
84 | * var u = "getResult.php"; |
---|
85 | * newAjaxRequest(c, u, function(xml) { |
---|
86 | * <!--Do something--> |
---|
87 | * }); |
---|
88 | * |
---|
89 | * It is of course also possible to refer to an external function instead of |
---|
90 | * defining function(xml){} in the call itself, as below: |
---|
91 | * |
---|
92 | * newAjaxRequest(c, u, externalFunction(xml)); |
---|
93 | */ |
---|
94 | |
---|
95 | function newAjaxRequest(c, u, cb, async) { |
---|
96 | |
---|
97 | var xml; |
---|
98 | var content = c; //an array of strings, in "key=value" format. |
---|
99 | // assign a compatible request format |
---|
100 | if (window.XMLHttpRequest) { //Not IE5, IE6 |
---|
101 | xml = new XMLHttpRequest(); |
---|
102 | } |
---|
103 | else { //IE5, IE6 |
---|
104 | xml = new ActiveXObject("Microsoft.XMLHTTP"); |
---|
105 | } |
---|
106 | // subscribe the callback function to a response event |
---|
107 | xml.onreadystatechange = function() { |
---|
108 | xml.responseText = "Processing..."; |
---|
109 | if (xml.readyState == 4 && xml.status == 200) { |
---|
110 | cb(xml); |
---|
111 | } |
---|
112 | }; |
---|
113 | // initialize XMLRequest |
---|
114 | xml.open("POST", u, async); |
---|
115 | xml.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); |
---|
116 | var contentString = ""; |
---|
117 | //iterate through parameters passed in variable c |
---|
118 | if (typeof(content)=='object'&&(input instanceof Array)) { // parameters were passed as an array of key=value strings |
---|
119 | for (var i = 0; i < content.length; i++) { |
---|
120 | contentString += content[i]; |
---|
121 | if (i != (content.length - 1)) { |
---|
122 | contentString += "&"; |
---|
123 | } |
---|
124 | } |
---|
125 | } |
---|
126 | else { // single parameter or string already formatted by calling function |
---|
127 | contentString = content; |
---|
128 | } |
---|
129 | // finally send the formatted request |
---|
130 | //alert(contentString); |
---|
131 | xml.send(contentString); |
---|
132 | } |
---|
133 | |
---|
134 | |
---|
135 | /* |
---|
136 | * ajaxStepRequest gets the markup for displaying a step in the sequencer from returnStep.php |
---|
137 | * Using ajax principle allows for editing of pipeline without constantly refreshing the page. |
---|
138 | */ |
---|
139 | |
---|
140 | function ajaxStepRequest(UIDS) { |
---|
141 | var c = "uids="+UIDS; |
---|
142 | var u = "returnStep.php"; |
---|
143 | newAjaxRequest(c, u, function(result) { |
---|
144 | document.getElementById("seqContent").innerHTML = result.responseText; |
---|
145 | }, true); |
---|
146 | } |
---|
147 | |
---|
148 | function ajaxInfoRequest(id, el) { |
---|
149 | var uid = id; |
---|
150 | var c = "uid="+uid; |
---|
151 | var u = "getInfo.php"; |
---|
152 | newAjaxRequest(c, u, function(result) { |
---|
153 | el.innerHTML = result.responseText; |
---|
154 | }, true); |
---|
155 | } |
---|
156 | |
---|
157 | function drawSteps() { |
---|
158 | var content = document.getElementById("seqContent"); |
---|
159 | var pipeline = document.getElementById("pipelineStringField").value; |
---|
160 | pipeline = pipeline.replace(/,/g , ",divider,"); //regex search for commas, global (repeat), to represent them with visual dividers. |
---|
161 | ajaxStepRequest(pipeline); |
---|
162 | } |
---|
163 | |
---|
164 | function updateSequencer() { |
---|
165 | var plString = document.getElementById("pipelineStringField").value; |
---|
166 | var plTypeString = document.getElementById("pipelineTypeField").value; |
---|
167 | var plUpdatedString = document.getElementById("pipelineUpdatedField").value; |
---|
168 | |
---|
169 | var pl = plString.split(","); |
---|
170 | var plType = plTypeString.split(","); |
---|
171 | var plUpdated = plUpdatedString.split(","); |
---|
172 | //console.log(plUpdated); |
---|
173 | |
---|
174 | |
---|
175 | for (var i = 0; i < pl.length; i++) { // loop through pipeline contents |
---|
176 | if (plUpdated[i] == "0") { // if the element is not up to date |
---|
177 | // first remove the step representation from the sequencer |
---|
178 | var seqContent = document.getElementById("seqContent"); |
---|
179 | var element = document.getElementById(pl[i]); |
---|
180 | var nextElement = element.nextSibling; |
---|
181 | |
---|
182 | // now request a new step representation and insert it after previousElement |
---|
183 | var holderDiv = document.createElement("div"); |
---|
184 | var requestString = "uids="+pl[i]; |
---|
185 | var resultText; |
---|
186 | newAjaxRequest(requestString, "returnStep.php", function(result) { |
---|
187 | holderDiv.innerHTML = result.responseText; |
---|
188 | }, false); |
---|
189 | |
---|
190 | //debugger; |
---|
191 | while (holderDiv.childNodes.length == 1) { |
---|
192 | // wait for response |
---|
193 | } |
---|
194 | var newDiv = holderDiv.childNodes[1]; |
---|
195 | seqContent.replaceChild(newDiv, element); |
---|
196 | plUpdated[i] = "1"; |
---|
197 | // ALTERNATIVE METHOD TO REPLACECHILD!!! |
---|
198 | //seqContent.removeChild(element); |
---|
199 | //seqContent.insertBefore(newDiv, nextElement); |
---|
200 | |
---|
201 | |
---|
202 | } |
---|
203 | else { |
---|
204 | |
---|
205 | } |
---|
206 | } |
---|
207 | |
---|
208 | // afterwards, convert the arrays back to strings |
---|
209 | var newUpdatedString = ""; |
---|
210 | |
---|
211 | for (var i = 0; i < plUpdated.length; i++) { |
---|
212 | newUpdatedString += plUpdated[i]+","; |
---|
213 | } |
---|
214 | |
---|
215 | if (newUpdatedString.substring(newUpdatedString.length - 1) == ",") { // remove comma at the end of string! |
---|
216 | newUpdatedString = newUpdatedString.substring(0, newUpdatedString.length-1); |
---|
217 | |
---|
218 | } |
---|
219 | document.getElementById("pipelineUpdatedField").value = newUpdatedString; |
---|
220 | |
---|
221 | } |
---|
222 | |
---|
223 | function savePipeline() { |
---|
224 | var answer = confirm("Save changes to pipeline?"); |
---|
225 | if (answer) { |
---|
226 | newAjaxRequest("", "savesession.php", function(){}, false); |
---|
227 | alert("Saved!"); |
---|
228 | } |
---|
229 | } |
---|
230 | |
---|
231 | function t_setOutOfDate() { |
---|
232 | // if a step is currently selected |
---|
233 | var uid = document.getElementById("selectedStepField").value; |
---|
234 | if (uid == "") { |
---|
235 | alert("No step selected!"); |
---|
236 | return; |
---|
237 | } |
---|
238 | |
---|
239 | // convert to arrays for looping |
---|
240 | var plString = document.getElementById("pipelineStringField").value; |
---|
241 | var plTypeString = document.getElementById("pipelineTypeField").value; |
---|
242 | var plUpdatedString = document.getElementById("pipelineUpdatedField").value; |
---|
243 | |
---|
244 | var pl = plString.split(","); |
---|
245 | var plType = plTypeString.split(","); |
---|
246 | var plUpdated = plUpdatedString.split(","); |
---|
247 | |
---|
248 | |
---|
249 | |
---|
250 | // set the targeted element's tag for "Needs updating" |
---|
251 | for (var i = 0; i < pl.length; i++) { |
---|
252 | if (pl[i] == uid) { |
---|
253 | plUpdated[i] = 0; |
---|
254 | } |
---|
255 | } |
---|
256 | |
---|
257 | // then rewrite the content strings and set them to the appropriate fields |
---|
258 | |
---|
259 | var newUpdatedString = ""; |
---|
260 | for (var i = 0; i < pl.length; i++) { |
---|
261 | newUpdatedString += plUpdated[i]+","; |
---|
262 | } |
---|
263 | alert(newUpdatedString+": OLD"); |
---|
264 | if (newUpdatedString.substring(newUpdatedString.length-1) == ",") { |
---|
265 | newUpdatedString = newUpdatedString.substring(0, newUpdatedString.length-1); |
---|
266 | } |
---|
267 | alert(newUpdatedString+": NEW!"); |
---|
268 | |
---|
269 | document.getElementById("pipelineUpdatedField").value = newUpdatedString; |
---|
270 | //alert("OOD set"); |
---|
271 | } |
---|