]> matita.cs.unibo.it Git - helm.git/blob - helm/uwobo-panel/control.js
cd04429c0ddfc29c27212ee7efb4401e8e4c060c
[helm.git] / helm / uwobo-panel / control.js
1
2 function getParam(name, def)
3 {
4   var search = top.location.search;
5   search = search.slice(1);
6   var args = search.split("&");
7   var value = "-1";
8   for (var i = 0 ; i < args.length ; i++) {
9     var couple = args[i].split("=");
10     if (couple[0] == name) value = couple[1];
11   }
12   if (value == "-1") value = def;
13   return value;
14 }
15
16 function getInitialPort()
17 {
18   return "68080";
19 }
20
21 function getInitialProcessorURL()
22 {
23   return getParam("processorURL", "http://phd.cs.unibo.it:8080/helm/servlet/uwobo/");
24 }
25
26 function getInitialGetterURL()
27 {
28   return getParam("getterURL", "http://phd.cs.unibo.it:8081/");
29 }
30
31 function getUwoboURL()
32 {
33   return document.uwoboURL.elements[0].value;
34 }
35
36 function getGetterURL()
37 {
38   return document.getterURL.elements[0].value;
39 }
40
41 function selectUwoboURL(ss)
42 {
43   if (ss.selectedIndex == 0) {
44     document.uwoboURL.elements[0].value = "";
45   } else {
46     document.uwoboURL.elements[0].value = "http://" + ss.options[ss.selectedIndex].value + ":8080/helm/servlet/uwobo/";
47   }
48 }
49
50 function selectGetterURL(ss)
51 {
52   if (ss.selectedIndex == 0) {
53     document.getterURL.elements[0].value = "";
54   } else {
55     document.getterURL.elements[0].value = "http://" + ss.options[ss.selectedIndex].value + ":8081/";
56   }
57 }
58
59 function getPredefinedStylesheetKey(i)
60 {
61   var v = document.predefinedStylesheets.elements[0].options[i].value;
62   var va = v.split(",");
63   return va[0];
64 }
65
66 function getPredefinedStylesheetURI(i)
67 {
68   var v = document.predefinedStylesheets.elements[0].options[i].value;
69   var va = v.split(",");
70   return va[1];
71 }
72
73 function getPredefinedStylesheetUseGetter(i)
74 {
75   var v = document.predefinedStylesheets.elements[0].options[i].value;
76   var va = v.split(",");
77   return va[2];
78 }
79
80 function selectPredefinedStylesheet(ss)
81 {
82   if (ss.selectedIndex == 0) {
83     document.stylesheetURI.elements[0].value = "";
84     document.stylesheetKey.elements[0].value = "";
85   } else {
86     document.stylesheetURI.elements[0].value = getPredefinedStylesheetURI(ss.selectedIndex);
87     document.stylesheetKey.elements[0].value = getPredefinedStylesheetKey(ss.selectedIndex);
88   }
89
90   document.loadUseGetter.elements[0].checked = getPredefinedStylesheetUseGetter(ss.selectedIndex) == "true" ? true : false;
91   document.loadEscape.elements[0].checked = true;
92 }
93
94 function getStylesheetURL()
95 {
96   var s;
97
98   if (document.loadUseGetter.elements[0].checked) {
99     s = getGetterURL() + "getxslt?uri=" + document.stylesheetURI.elements[0].value;
100   } else {
101     s = document.stylesheetURI.elements[0].value;
102   }
103
104   if (document.loadEscape.elements[0].checked) s = escape(s);
105   
106   return s;
107 }
108
109 function loadStylesheet()
110 {
111   top.result.location.replace(getUwoboURL() + "add?bind=" + document.stylesheetKey.elements[0].value + "," + getStylesheetURL());
112 }
113
114 function removeStylesheet()
115 {
116   top.result.location.replace(getUwoboURL() + "remove?keys=" + document.stylesheetKey.elements[0].value);
117 }
118
119 function removeAllStylesheets()
120 {
121   top.result.location.replace(getUwoboURL() + "remove");
122 }
123
124 function reloadStylesheet()
125 {
126   top.result.location.replace(getUwoboURL() + "reload?keys=" + document.stylesheetKey.elements[0].value);
127 }
128
129 function loadAllPredefined()
130 {
131   with (document.predefinedStylesheets.elements[0]) {
132     var i;
133     var request = "";
134
135     for (i = 1; i < length; i++)
136       request +=
137         (request == "" ? "" : "&") +
138         "bind=" + getPredefinedStylesheetKey(i) + "," +  escape((getPredefinedStylesheetUseGetter(i) == "true" ? (getGetterURL() + "getxslt?uri=") : "") + getPredefinedStylesheetURI(i));
139     top.result.location.replace(getUwoboURL() + "add?" + request);
140   }
141 }
142
143 function removeAllPredefined()
144 {
145   with (document.predefinedStylesheets.elements[0]) {
146     var i;
147     var request = "";
148
149     for (i = 1; i < length; i++)
150       request += getPredefinedStylesheetKey(i) + (i == length - 1 ? "" : ",");
151     top.result.location.replace(getUwoboURL() + "remove?keys=" + request);
152   }
153 }
154
155 function applyStylesheets()
156 {
157   var i = 0;
158   var keyList = document.keyList.elements[0].value.split(" ");
159
160   var url = getUwoboURL() + "apply?xmluri=";
161   
162   var sourceURL = "";
163
164   if (document.applyUseGetter.elements[0].checked)
165     sourceURL += getGetterURL() + "getxml?uri=";
166     
167   sourceURL += document.sourceDocument.elements[0].value;
168
169   if (document.escapeSource.elements[0].checked)
170     url += escape(sourceURL);
171   else
172     url += sourceURL;
173
174   url += "&keys=";
175   for (i = 0; i < keyList.length; i++) {
176     url += keyList[i];
177     if (i < keyList.length - 1) url += ",";
178   }
179
180   var paramList = document.parameters.elements[0].value.split(" ");
181   for (i = 0; i < paramList.length; i++)
182     if (paramList[i].length > 0) {
183       if (document.escapeParameters.elements[0].checked) {
184         var p = paramList[i].split("=");
185         url += "&param." + p[0] + "=" + escape(p[1]);
186       } else
187         url += "&param." + paramList[i];
188     }
189   
190   top.result.location.replace(url);
191 }