]> matita.cs.unibo.it Git - helm.git/blob - helm/uwobo-panel/control.js
Initial revision
[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 = "";
129
130     for (i = 1; i < length; i++)
131       request +=
132         (request == "" ? "" : "&") +
133         "bind=" + getPredefinedStylesheetKey(i) + "," +  escape((getPredefinedStylesheetUseGetter(i) == "true" ? (getGetterURL() + "getxslt?uri=") : "") + getPredefinedStylesheetURI(i));
134     top.result.location.replace(getUwoboURL() + "add?" + request);
135   }
136 }
137
138 function removeAllPredefined()
139 {
140   with (document.predefinedStylesheets.elements[0]) {
141     var i;
142     var request = "";
143
144     for (i = 1; i < length; i++)
145       request += getPredefinedStylesheetKey(i) + (i == length - 1 ? "" : ",");
146     top.result.location.replace(getUwoboURL() + "remove?keys=" + request);
147   }
148 }
149
150 function applyStylesheets()
151 {
152   var i = 0;
153   var keyList = document.keyList.elements[0].value.split(" ");
154
155   var url = getUwoboURL() + "apply?xmluri=";
156   
157   var sourceURL = "";
158
159   if (document.applyUseGetter.elements[0].checked)
160     sourceURL += getGetterURL() + "getxml?uri=";
161     
162   sourceURL += document.sourceDocument.elements[0].value;
163
164   if (document.escapeSource.elements[0].checked)
165     url += escape(sourceURL);
166   else
167     url += sourceURL;
168
169   url += "&keys=";
170   for (i = 0; i < keyList.length; i++) {
171     url += keyList[i];
172     if (i < keyList.length - 1) url += ",";
173   }
174
175   var paramList = document.parameters.elements[0].value.split(" ");
176   for (i = 0; i < paramList.length; i++)
177     if (paramList[i].length > 0) {
178       if (document.escapeParameters.elements[0].checked) {
179         var p = paramList[i].split("=");
180         url += "&param." + p[0] + "=" + escape(p[1]);
181       } else
182         url += "&param." + paramList[i];
183     }
184   
185   top.result.location.replace(url);
186 }