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

Last change on this file since 152 was 152, checked in by fpvanagthoven, 13 years ago
  • getInfo.php returnet informatie over het aangevraagde object. Dit kan via ajax routines op verscheidene infopanels weergegeven worden. (Bijvoorbeeld in de huidige versie van selectSession.php). Deze script wordt later nog uitgebreid om verschillende soorten objecten en sets informatie weer te geven. (Momenteel alleen sessions!)
  • selectSession werkt grotendeels, op deleteSession en een non-fatal error bij createSession na.
  • logout.php gebruikt nu ook destroy_session();
  • sequencerScripts.js uitgebreid om een simpel aan te roepen AJAX routine mogelijk te maken. Dit biedt de mogelijkheid om pagina's aan te passen zonder een refresh.
File size: 4.5 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 SubmitToolbox() {
28    document.forms['toolbox'].submit();
29}
30
31// Class manipulation
32
33function hasClass(ele,cls) {
34    return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
35}
36 
37function addClass(ele,cls) {
38    if (!this.hasClass(ele,cls)) ele.className += " "+cls;
39}
40 
41function removeClass(ele,cls) {
42    if (hasClass(ele,cls)) {
43        var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
44        ele.className=ele.className.replace(reg,' ');
45    }
46}
47
48//new scripts!
49//start here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
50
51function selectStep(uid) {
52    document.getElementById(uid).addClass("selected");
53    document.sequencer.controls.selectedStep.value = uid;
54}
55                                                                           
56                                                                           
57/*
58 * ajaxStepRequest gets  the markup for displaying a step in the sequencer from returnStep.php
59 * Using ajax principle allows for editing of pipeline without constantly refreshing the page.
60 */
61
62function ajaxStepRequest(UID) {
63    var c = "uid="+UID;
64    var u = "returnStep.php";
65    newAjaxRequest(c, u, function(result) {
66        var newDiv = result.responseText;
67        document.getElementById("seqContent").appendChild(newDiv);
68    });
69}
70
71function ajaxInfoRequest(id, el) {
72    var uid = id;
73    var c = "uid="+uid;
74    var u = "getInfo.php";
75    newAjaxRequest(c, u, function(result) {
76        el.innerHTML = result.responseText;
77    });
78}
79
80/*
81 * This function allows for simple use of AJAX requests.
82 * Calling format:
83 *
84 * var c[] = "uid=123";
85 *  var c[] = "name=tschipper";
86 *  var u = "getResult.php";
87 *  newAjaxRequest(c, u, function(xml) {
88 *      <!--Do something-->
89 *  });
90 * 
91 *  It is of course also possible to refer to an external function instead of
92 *  defining function(xml){} in the call itself, as below:
93 * 
94 *  newAjaxRequest(c, u, externalFunction(xml));
95 */
96
97function newAjaxRequest(c, u, cb) {
98   
99    var xml;
100    var content = c;    //an array of strings, in "key=value"  format.
101    // assign a compatible request format
102    if (window.XMLHttpRequest) {    //Not IE5, IE6
103        xml = new XMLHttpRequest();
104    }
105    else {                          //IE5, IE6
106        xml = new ActiveXObject("Microsoft.XMLHTTP");
107    }
108    // subscribe the callback function to a response event
109    xml.onreadystatechange = function() {
110        if (xml.readyState == 4 && xml.status == 200) {
111            //alert("Received!");
112            cb(xml);
113        }
114    };
115    // initialize XMLRequest
116    xml.open("POST", u, true);
117    xml.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
118    var contentString = "";
119    //iterate through parameters passed in variable c
120    if (typeof(content)=='object'&&(input instanceof Array)) {    // parameters were passed as an array of key=value strings
121        for (var i = 0; i < content.length; i++) {
122            contentString += content[i];
123            if (i != (content.length - 1)) {
124                contentString += "&";
125            }
126        }
127    }
128    else {                      // single parameter or string already formatted by calling function
129        contentString = content;
130    }
131    // finally send the formatted request
132    //alert(contentString);
133    xml.send(contentString);
134}
135                           
136
137function drawSteps() {
138    var sequencer = document.getElementById("sequencer");
139    var seqContent = document.getElementById("seqContent");
140               
141    // first delete all current children of seqContent (to reset the sequencer).
142    while (seqContent.childNodes.length > 0) {
143        var step = seqContent.childNodes[0];
144        step.parentNode.removeChild(step);
145    }
146               
147    // get pipeline contents from hidden form inputs.
148    var pipeline = sequencer.controls.pipeline.value;
149    var pipeline = pipeline.split(", ");
150               
151    // then do an xmlhttp request for each step to be added to the sequencer
152    var numberOfSteps = pipeline.length;
153    for (var i = 0; i > numberOfSteps; i++) {
154        ajaxStepRequest(pipeline[i]);
155    }
156               
157}
158
Note: See TracBrowser for help on using the repository browser.