]> matita.cs.unibo.it Git - helm.git/blob - helm/on-line/javascript/control.js
Code improvement: more code shared.
[helm.git] / helm / on-line / javascript / control.js
1 function updateMode(i, s)
2 {
3   var mode = top.mode;
4   var mode_list = mode.split(",");
5   var res = "";
6   var j;
7
8   for (j = 0; j < mode_list.length; j++) {
9     if (j == i) res += s;
10     else res += mode_list[j];
11     if (j < mode_list.length - 1) res += ",";
12   }
13   
14   top.mode = res;
15 }
16
17 function updateOutput(output,format)
18 {
19   var theoryuri = top.theoryuri;
20   var cicuri = top.cicuri;
21   var mode = top.mode;
22   var topurl = top.topurl;
23   var processorURL = top.processorURL;
24   var getterURL = top.getterURL;
25   var draw_graphURL = top.draw_graphURL;
26   var uri_set_queueURL = top.uri_set_queueURL;
27   var mode_list = mode.split(",");
28   var new_mode = output.options[output.selectedIndex].value;
29   var dest = "?theoryuri=" + theoryuri + "&cicuri=" + cicuri + "&topurl=" + topurl + "&processorURL=" + processorURL + "&getterURL=" + getterURL + "&draw_graphURL=" + draw_graphURL + "&uri_set_queueURL=" + uri_set_queueURL + "&mode=";
30   
31   if (new_mode != mode_list[0]) {
32     updateMode(0, new_mode);
33     if (new_mode == "raw") updateMode(2, format.options[format.selectedIndex].value);
34     else updateMode(1, format.options[format.selectedIndex].value);
35
36     var href =
37      top.processorURL + 'apply' +
38      '?keys=RT' +
39      '&param.topurl=' + topurl +
40      '&xmluri=' +
41      escape(top.topurl + '/html/library/control.html' + dest + top.mode);
42     
43     location.href = href;
44   }
45 }
46
47 function updateFormat(format)
48 {
49   var mode = top.mode;
50   var mode_list = mode.split(",");
51
52   if (mode_list[0] == "raw") {
53     updateMode(1, format.options[format.selectedIndex].value);
54   } else {
55     updateMode(2, format.options[format.selectedIndex].value);
56   }
57
58   refreshReload();
59 }
60
61 function updateNatural(checkbox)
62 {
63   if (checkbox.checked) updateMode(3, "yes");
64   else updateMode(3, "no");
65   refreshReload();
66 }
67
68 function updateAnnotations(checkbox)
69 {
70   if (checkbox.checked) updateMode(4, "yes");
71   else updateMode(4, "no");
72   refreshReload();
73 }
74
75 function updateCompressed(checkbox)
76 {
77   if (checkbox.checked) updateMode(5, "gz");
78   else updateMode(5, "normal");
79   refreshReload();
80 }
81
82 function updateDTDPatched(checkbox)
83 {
84   if (checkbox.checked) updateMode(6, "yes");
85   else updateMode(6, "no");
86   refreshReload();
87 }
88
89 function refreshReload()
90 {
91    var search = 
92       "?mode=" + top.mode +
93       "&cicuri=" + top.cicuri +
94       "&theoryuri=" + top.theoryuri +
95       "&processorURL=" + top.processorURL +
96       "&getterURL=" + top.getterURL +
97       "&draw_graphURL=" + top.draw_graphURL +
98       "&uri_set_queueURL=" + top.uri_set_queueURL +
99       "&UNICODEvsSYMBOL=" + top.UNICODEvsSYMBOL;
100
101    var href =
102     top.processorURL + 'apply' +
103     '?keys=RT' +
104     '&param.topurl=' + top.topurl +
105     '&xmluri=' +
106     escape(top.topurl + '/html/library/index.html' + search);
107     
108    top.frames[0].document.links[0].href = href;
109    top.frames[0].document.links[1].href =
110     top.topurl + '/html/index.html' + search;
111
112    return true;
113 }
114
115 function refreshcicHeader(headerURL)
116 {
117    top.cicheader.location.search = "?keys=GP&xmluri=" + headerURL + "&param.uri=" + top.cicuri;
118    return true;
119 }
120
121 function refreshtheoryHeader(headerURL)
122 {
123    top.theoryheader.location.search = "?keys=GP&xmluri=" + headerURL + "&param.uri=" + top.theoryuri;
124    return true;
125 }
126
127 function getCICMathMLKeys()
128 {
129   return escape("d_c,C1,G,C2,L");
130 }
131
132 function getTheoryKeys()
133 {
134   return escape("T1,T2,L,E");
135 }
136
137 function makeURL(type,uri,cicflags,typesflags)
138 {
139   var mode = top.mode;
140   var processorURL = top.processorURL;
141   var getterURL = top.getterURL;
142   var draw_graphURL = top.draw_graphURL;
143   var uri_set_queueURL = top.uri_set_queueURL;
144   var UNICODEvsSYMBOL = top.UNICODEvsSYMBOL;
145   var mode_list = mode.split(",");
146   
147   var keys = "";
148   var url = "";
149
150   var interfaceURL = top.topurl + "/html/cic/index.html";
151   var thinterfaceURL = top.topurl + "/html/theory/index.html";
152
153   var output = mode_list[0];
154   var format;
155   if (output == "raw") format = mode_list[1];
156   else format = mode_list[2];
157   
158   if (output == "raw") {
159     var ext = "";
160     var rdfprefix = "";
161     if (format == "types") ext = ".types"
162     else if (format == "ann") ext = ".ann"
163     else if (format == "fwd") rdfprefix = "helm:rdf:www.cs.unibo.it/helm/rdf/forward//"
164     else if (format == "bwd") rdfprefix = "helm:rdf:www.cs.unibo.it/helm/rdf/backward//";
165     url = getterURL + "getxml?uri=" + rdfprefix + uri + ext + "&format=" +
166           mode_list[5] + "&patch_dtd=" + mode_list[6];
167   } else {
168     if (format == "html" && type == "cic") {
169       keys = escape("d_c,C1,HC2,L") +
170        "&param.processorURL=" + escape(processorURL) +
171        "&param.getterURL=" + escape(getterURL) +
172        "&param.draw_graphURL=" + escape(draw_graphURL) +
173        "&param.uri_set_queueURL=" + escape(uri_set_queueURL) +
174        "&param.UNICODEvsSYMBOL=" + escape(UNICODEvsSYMBOL) +
175        "&prop.doctype-public="+escape("-//W3C//DTD XHTML 1.0 Transitional//EN")+
176        "&prop.encoding=iso-8859-1" +
177        "&prop.media-type=text/html" +
178        "&param.doctype-public="+escape("-//W3C//DTD XHTML 1.0 Transitional//EN")+
179        "&param.encoding=iso-8859-1" +
180        "&param.media-type=text/html" +
181        "&param.keys=" + escape("d_c,C1,HC2,L") +
182        "&param.interfaceURL=" + escape(interfaceURL);
183     } else if (format == "html" && type == "theory") {
184       keys = getTheoryKeys()+
185        "&param.processorURL=" + escape(processorURL) +
186        "&param.getterURL=" + escape(getterURL) +
187        "&param.draw_graphURL=" + escape(draw_graphURL) +
188        "&param.uri_set_queueURL=" + escape(uri_set_queueURL) +
189        "&param.UNICODEvsSYMBOL=" + escape(UNICODEvsSYMBOL) +
190        "&param.keys=" + escape("d_c,C1,HC2,L") +
191        "&param.thkeys=" + getTheoryKeys() +
192        "&param.embedkeys=" + escape("d_c,TC1,HC2,L") +
193        "&param.doctype-public="+escape("-//W3C//DTD XHTML 1.0 Transitional//EN")+
194        "&param.encoding=iso-8859-1" +
195        "&param.thencoding=iso-8859-1" +
196        "&param.media-type=text/html" +
197        "&param.thmedia-type=text/html" +
198        "&param.interfaceURL=" + escape(interfaceURL) +
199        "&param.thinterfaceURL=" + escape(thinterfaceURL);
200     } else if (format == "mml_cont" && type == "cic") {
201       keys = escape("d_c,C1");
202     } else if (format == "mml_cont" && type == "theory") {
203       keys = escape("T1,L,E")+
204        "&param.keys=" + escape("d_c,C1") +
205        "&param.thkeys=T1,L,E" +
206        "&param.embedkeys=" + escape("d_c,TC1") +
207
208        "&param.processorURL=" + escape(processorURL) +
209        "&param.getterURL=" + escape(getterURL) +
210        "&param.draw_graphURL=" + escape(draw_graphURL) +
211        "&param.uri_set_queueURL=" + escape(uri_set_queueURL) +
212        "&param.doctype-public=" +
213        "&param.encoding=" +
214        "&param.thencoding=iso-8859-1" +
215        "&param.media-type=text/xml" +
216        "&param.thmedia-type=text/html" +
217        "&param.interfaceURL=" + escape(interfaceURL) +
218        "&param.thinterfaceURL=" + escape(thinterfaceURL);
219     } else if (format == "mml_pres" && type == "cic") {
220       keys = getCICMathMLKeys()+
221        "&param.processorURL=" + escape(processorURL) +
222        "&param.getterURL=" + escape(getterURL) +
223        "&param.draw_graphURL=" + escape(draw_graphURL) +
224        "&param.uri_set_queueURL=" + escape(uri_set_queueURL) +
225        "&prop.doctype-public="+
226        "&prop.encoding=" +
227        "&prop.media-type=text/xml" +
228        "&param.doctype-public=" +
229        "&param.encoding=" +
230        "&param.media-type=text/xml" +
231        "&param.keys=" + getCICMathMLKeys() +
232        "&param.interfaceURL=" + escape(interfaceURL);
233     } else if (format == "mml_pres" && type == "theory") {
234       keys = getTheoryKeys()+
235        "&param.keys=" + getCICMathMLKeys() +
236        "&param.thkeys=" + getTheoryKeys() +
237        "&param.embedkeys=" + escape(d_c,TC1,G,C2,L) +
238        "&param.processorURL=" + escape(processorURL) +
239        "&param.getterURL=" + escape(getterURL) +
240        "&param.draw_graphURL=" + escape(draw_graphURL) +
241        "&param.uri_set_queueURL=" + escape(uri_set_queueURL) +
242        "&param.doctype-public=" +
243        "&param.encoding=" +
244        "&param.thencoding=iso-8859-1" +
245        "&param.media-type=text/xml" +
246        "&param.thmedia-type=text/html" +
247        "&param.interfaceURL=" + escape(interfaceURL) +
248        "&param.thinterfaceURL=" + escape(thinterfaceURL);
249     }
250
251     var naturalLanguage = typesflags;
252     if (typesflags != "NO" || type == "theory") {
253        naturalLanguage = mode_list[3];
254     }
255     var annotations = cicflags;
256     if (cicflags != "NO" || type == "theory") {
257        annotations = mode_list[4];
258     }
259     url = processorURL + "apply?xmluri=" + escape(getterURL + "getxml?uri=" + uri) + "&keys=" + keys + "&param.CICURI=" + uri + "&param.naturalLanguage=" + naturalLanguage + "&param.annotations=" + annotations + "&param.topurl=" + top.topurl;
260   }
261
262   if (output == "raw")
263    return url;
264   else if (type == "cic")
265    return interfaceURL + "?url=" + escape(url);
266   else if (type == "theory")
267    return thinterfaceURL + "?url=" + escape(url)
268 }
269