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

Last change on this file since 166 was 166, checked in by fpvanagthoven, 13 years ago

Jos, nevermind. Mijn fout, ik heb die creator[0] in SessionConnector:117 weer teruggezet.

  • ToolBox?.php is overgezet naar javascript werking.
  • updateSequencer() werkt.
  • updateDividers() werkt.
  • t_setOutOfDate is in principe niet meer nodig, maar handig voor test purposes. Deze flagget de geselecteerde object voor een refresh.
  • saveSession() werkt! De pipeline editor is nu dus daadwerkelijk bruikbaar! [move/delete/clear/edit nog niet!]
  • Verkeerde calling code voor session->creator aangepast, login systeem werkt nu goed.
  • createObject.php werkt!
File size: 11.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
27function removeNL(s){
28    return s.replace(/[\n\r\t]/g,"");
29}
30
31function SubmitToolbox(type) {
32    var c = "objectToCreate="+type;
33    var u = "createObject.php";
34    var a = true;
35    var pipeline = document.getElementById("pipelineStringField");
36    var pipelineType = document.getElementById("pipelineTypeField");
37    var pipelineUpdated = document.getElementById("pipelineUpdatedField");
38   
39    newAjaxRequest(c, u, function(result){
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,";
46        updateSequencer();
47    }, a);
48}
49
50// Class manipulation
51
52function hasClass(ele,cls) {
53    if (ele.className)
54        return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
55}
56 
57function addClass(ele,cls) {
58    if (!this.hasClass(ele,cls)) ele.className += " "+cls;
59}
60 
61function removeClass(ele,cls) {
62    if (hasClass(ele,cls)) {
63        var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
64        ele.className=ele.className.replace(reg,' ');
65    }
66}
67
68//new scripts!
69//start here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
70
71function selectStep(uid) {
72    var nodes = document.getElementById("seqContent").childNodes;
73    for (var i = 0; i < nodes.length; i++) {     //loop through childNodes. Skip first node (whitespace)
74        if (hasClass(nodes[i], "displayStep")) {    //check if current childNode is a displayStep, not divider or text.
75            if (nodes[i].id == uid) {
76                if (hasClass(nodes[i], "selected")) {
77                    removeClass(nodes[i], "selected");
78                }
79                else {
80                    addClass(nodes[i], "selected");
81                }               
82            }
83            else {
84                removeClass(nodes[i], "selected");
85            }
86        }
87    }
88   
89    // Update selected step field with uid of currently selected step.
90    var selectedStepField = document.getElementById("selectedStepField");
91    selectedStepField.value = uid;
92   
93}
94                                                                           
95function 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    xml.send(contentString);
131}
132
133
134/*
135 * ajaxStepRequest gets  the markup for displaying a step in the sequencer from returnStep.php
136 * Using ajax principle allows for editing of pipeline without constantly refreshing the page.
137 */
138
139function ajaxStepRequest(UIDS, types) {
140    var c = "uids="+UIDS;
141    if (types != "") {
142        c += "&types="+types;
143    }
144    var u = "returnStep.php";
145    newAjaxRequest(c, u, function(result) {
146        document.getElementById("seqContent").innerHTML = result.responseText;
147    }, true);
148}
149
150function ajaxInfoRequest(id, el) {
151    var uid = id;
152    var c = "uid="+uid;
153    var u = "getInfo.php";
154    newAjaxRequest(c, u, function(result) {
155        el.innerHTML = result.responseText;
156    }, true);
157}
158
159function drawSteps() {
160    var content = document.getElementById("seqContent");
161    var pipeline = document.getElementById("pipelineStringField").value;
162    var pipelineTypes = document.getElementById("pipelineTypeField").value;
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    }
169}
170
171function updateSequencer() {
172    var plString = document.getElementById("pipelineStringField").value;
173    var plTypeString = document.getElementById("pipelineTypeField").value;
174    var plUpdatedString = document.getElementById("pipelineUpdatedField").value;
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;
184   
185    for (var i = 0; i < pl.length; i++) {   // loop through pipeline contents
186        if (plUpdated[i] == "0") {   // if the element is not up to date
187            // first remove the step representation from the sequencer
188            var seqContent = document.getElementById("seqContent");
189            var element = document.getElementById(pl[i]);
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            }
203           
204            // now request a new step representation and insert it after previousElement
205            var holderDiv = document.createElement("div");
206            var requestString = "uids="+pl[i];
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           
214            newAjaxRequest(requestString, "returnStep.php", function(result) {
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";
222            }, false);
223           
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, ",");
238    document.getElementById("pipelineUpdatedField").value = newUpdatedString;
239   
240}
241
242
243
244
245
246
247function 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
285
286function savePipeline() {
287    var answer = confirm("Save changes to pipeline?");
288    if (answer) {
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);
303    }
304}
305
306function t_setOutOfDate() {
307    // if a step is currently selected
308    var uid = document.getElementById("selectedStepField").value;
309    if (uid == "") {
310        alert("No step selected!");
311        return;
312    }
313   
314    // convert to arrays for looping
315    var plString = document.getElementById("pipelineStringField").value;
316    var plTypeString = document.getElementById("pipelineTypeField").value;
317    var plUpdatedString = document.getElementById("pipelineUpdatedField").value;
318   
319   
320    var pl = stringToArray(plString, ",");   
321    var plType = stringToArray(plTypeString, ",");   
322    var plUpdated = stringToArray(plUpdatedString, ",");   
323   
324    // set the targeted element's tag for "Needs updating"
325    plUpdated[pl.indexOf(uid)] = "0";
326   
327    // then rewrite the content strings and set them to the appropriate fields
328    var newUpdatedString = arrayToString(plUpdated, ",");
329    document.getElementById("pipelineUpdatedField").value = newUpdatedString;
330}
331
332function 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
343function 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 TracBrowser for help on using the repository browser.