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