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
RevLine 
[146]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
[166]27function removeNL(s){
28    return s.replace(/[\n\r\t]/g,"");
[146]29}
[166]30
[165]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){
[166]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,";
[165]46        updateSequencer();
47    }, a);
48}
[146]49
[152]50// Class manipulation
[146]51
[152]52function hasClass(ele,cls) {
[154]53    if (ele.className)
54        return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
[152]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}
[146]67
[152]68//new scripts!
69//start here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
70
71function selectStep(uid) {
[154]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) {
[164]76                if (hasClass(nodes[i], "selected")) {
77                    removeClass(nodes[i], "selected");
78                }
79                else {
80                    addClass(nodes[i], "selected");
81                }               
[154]82            }
83            else {
84                removeClass(nodes[i], "selected");
85            }
86        }
[153]87    }
[154]88   
89    // Update selected step field with uid of currently selected step.
90    var selectedStepField = document.getElementById("selectedStepField");
91    selectedStepField.value = uid;
92   
[152]93}
94                                                                           
[164]95function newAjaxRequest(c, u, cb, async) {
[152]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() {
[164]108        xml.responseText = "Processing...";
[152]109        if (xml.readyState == 4 && xml.status == 200) {
110            cb(xml);
111        }
112    };
113    // initialize XMLRequest
[164]114    xml.open("POST", u, async);
[152]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    }
[166]126    else { // single parameter or string already formatted by calling function
[152]127        contentString = content;
128    }
129    // finally send the formatted request
130    xml.send(contentString);
131}
[153]132
[154]133
[153]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
[165]139function ajaxStepRequest(UIDS, types) {
[154]140    var c = "uids="+UIDS;
[165]141    if (types != "") {
142        c += "&types="+types;
143    }
[153]144    var u = "returnStep.php";
145    newAjaxRequest(c, u, function(result) {
[154]146        document.getElementById("seqContent").innerHTML = result.responseText;
[164]147    }, true);
[153]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;
[164]156    }, true);
[153]157}
[146]158
[152]159function drawSteps() {
[153]160    var content = document.getElementById("seqContent");
161    var pipeline = document.getElementById("pipelineStringField").value;
[165]162    var pipelineTypes = document.getElementById("pipelineTypeField").value;
[166]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    }
[146]169}
170
[164]171function updateSequencer() {
172    var plString = document.getElementById("pipelineStringField").value;
173    var plTypeString = document.getElementById("pipelineTypeField").value;
174    var plUpdatedString = document.getElementById("pipelineUpdatedField").value;
[153]175   
[164]176   
[166]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   
[164]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]);
[166]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            }
[164]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];
[166]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           
[164]214            newAjaxRequest(requestString, "returnStep.php", function(result) {
[166]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";
[164]222            }, false);
223           
[166]224                       
225            // ALTERNATIVE METHOD TO REPLACECHILD!!!
226            //seqContent.removeChild(element);
227            //seqContent.insertBefore(newDiv, nextElement);
[164]228           
[166]229            // Now check if dividers are necessary.
[164]230           
[166]231            //alert("INSERT CODE FOR UPDATEDIVIDERS HERE!");
232            updateDividers(newDiv);
[164]233        }
234    }
235   
[166]236    // afterwards, convert the arrays back to strings and set to appropriate fields
237    var newUpdatedString = arrayToString(plUpdated, ",");
238    document.getElementById("pipelineUpdatedField").value = newUpdatedString;
[164]239   
[166]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;
[164]252    }
[166]253    if (element.previousSibling) {
254        var previousElement = element.previousSibling;
255    }
[164]256   
[166]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        }
[164]266    }
267   
[166]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   
[164]279}
280
[166]281
282
283
284
285
[164]286function savePipeline() {
287    var answer = confirm("Save changes to pipeline?");
288    if (answer) {
[166]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);
[164]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   
[166]320    var pl = stringToArray(plString, ",");   
321    var plType = stringToArray(plTypeString, ",");   
322    var plUpdated = stringToArray(plUpdatedString, ",");   
[164]323   
324    // set the targeted element's tag for "Needs updating"
[166]325    plUpdated[pl.indexOf(uid)] = "0";
[164]326   
327    // then rewrite the content strings and set them to the appropriate fields
[166]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        }
[164]339    }
[166]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        }
[164]349    }
[166]350    return s;
[154]351}
Note: See TracBrowser for help on using the repository browser.