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

Last change on this file since 153 was 153, checked in by fpvanagthoven, 13 years ago
File size: 5.1 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    var selectedInfo = document.getElementById("selectedStepField");
54    if (selectedInfo == null) {     // This is the first time a step is selected after a reload of the page, therefore a hidden input field is not yet present.
55        selectedInfo = document.createElement("input")
56        selectedInfo.setAttribute("type","hidden");
57        selectedInfo.setAttribute("id","selectedStepField");
58        selectedInfo.setAttribute("value",uid);
59        var hiddenInputFields = document.getElementById("hiddenInputs");
60        hiddenInputFields.appendChild(selectedInfo);
61    }
62    else {      // There already exists a hidden input field with id selectedStepField, therefore we only change the value of this field.
63        var hiddenInput = document.getElementById("selectedStepField");
64        hiddenInput.value = uid;
65    }
66}
67                                                                           
68                                                                           
69/*
70 * This function allows for simple use of AJAX requests.
71 * Calling format:
72 *
73 * var c[] = "uid=123";
74 *  var c[] = "name=tschipper";
75 *  var u = "getResult.php";
76 *  newAjaxRequest(c, u, function(xml) {
77 *      <!--Do something-->
78 *  });
79 * 
80 *  It is of course also possible to refer to an external function instead of
81 *  defining function(xml){} in the call itself, as below:
82 * 
83 *  newAjaxRequest(c, u, externalFunction(xml));
84 */
85
86function newAjaxRequest(c, u, cb) {
87   
88    var xml;
89    var content = c;    //an array of strings, in "key=value"  format.
90    // assign a compatible request format
91    if (window.XMLHttpRequest) {    //Not IE5, IE6
92        xml = new XMLHttpRequest();
93    }
94    else {                          //IE5, IE6
95        xml = new ActiveXObject("Microsoft.XMLHTTP");
96    }
97    // subscribe the callback function to a response event
98    xml.onreadystatechange = function() {
99        if (xml.readyState == 4 && xml.status == 200) {
100            //alert("Received!");
101            cb(xml);
102        }
103    };
104    // initialize XMLRequest
105    xml.open("POST", u, true);
106    xml.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
107    var contentString = "";
108    //iterate through parameters passed in variable c
109    if (typeof(content)=='object'&&(input instanceof Array)) {    // parameters were passed as an array of key=value strings
110        for (var i = 0; i < content.length; i++) {
111            contentString += content[i];
112            if (i != (content.length - 1)) {
113                contentString += "&";
114            }
115        }
116    }
117    else {                      // single parameter or string already formatted by calling function
118        contentString = content;
119    }
120    // finally send the formatted request
121    //alert(contentString);
122    xml.send(contentString);
123}
124
125/*
126 * ajaxStepRequest gets  the markup for displaying a step in the sequencer from returnStep.php
127 * Using ajax principle allows for editing of pipeline without constantly refreshing the page.
128 */
129
130function ajaxStepRequest(UID) {
131    var c = "uid="+UID;
132    var u = "returnStep.php";
133    newAjaxRequest(c, u, function(result) {
134        var newDiv = document.createElement("div");
135        newDiv.innerHTML = result.responseText;
136        document.getElementById("seqContent").appendChild(newDiv);
137    });
138}
139
140function ajaxInfoRequest(id, el) {
141    var uid = id;
142    var c = "uid="+uid;
143    var u = "getInfo.php";
144    newAjaxRequest(c, u, function(result) {
145        el.innerHTML = result.responseText;
146    });
147}
148                           
149
150
151
152
153
154
155function drawSteps() {
156    var content = document.getElementById("seqContent");
157    var pipeline = document.getElementById("pipelineStringField").value;
158    var copy = pipeline;
159    pipeline = copy.split(",");
160   
161    // then do an xmlhttp request for each step to be added to the sequencer
162    var numberOfSteps = pipeline.length;
163    for (var i = 0; i < numberOfSteps; i++) {
164        ajaxStepRequest(pipeline[i]);
165        if (i < (numberOfSteps-1)) {
166            ajaxStepRequest("divider");
167        }
168    }
169   
170               
171}
172
173function updatePipelineHidden (pipelineString) {
174   
175}
176
177
Note: See TracBrowser for help on using the repository browser.