source: other-projects/trunk/greenstone3-extension/mat/resources/script/getInfomation-bk.js@ 17693

Last change on this file since 17693 was 17693, checked in by cc108, 15 years ago

new resources folder

File size: 7.7 KB
Line 
1var opt;
2var winW = 630, winH = 460;
3
4function GD(obj){
5 var NID;
6 NID = obj.parentNode.id;
7 opt = "info";
8 reconfig();
9 ajaxSearch(NID);
10}
11
12function GX(obj){
13 var NID;
14 NID = obj.parentNode.id;
15 opt = "url";
16 reconfig();
17 ajaxSearch(NID);
18}
19
20function reconfig(){
21 var request2 ='<request type="system" to=""><system type="configure" subset="collectionList"/></request>';
22 var message2 = newElement('message', request2 );
23 var soapMessage2 = messageToSOAP(message2);
24 makeRequest(soapMessage2);
25}
26
27function windowSize(){
28 if (parseInt(navigator.appVersion)>3) {
29 if (navigator.appName=="Netscape") {
30 winW = window.innerWidth;
31 winH = window.innerHeight;
32 }
33
34 if (navigator.appName.indexOf("Microsoft")!=-1) {
35 winW = document.body.offsetWidth;
36 winH = document.body.offsetHeight;
37 }
38 }
39}
40
41
42function getwindowHeight(){
43
44 var Height;
45
46 if (parseInt(navigator.appVersion)>3) {
47 if (navigator.appName=="Netscape") {
48 Height = window.innerHeight;
49 }
50 if (navigator.appName.indexOf("Microsoft")!=-1) {
51 winW = document.body.offsetWidth;
52 Height = document.body.offsetHeight;
53 }
54 return Height;
55 }
56}
57
58
59function newwindows(url){
60
61 if(url!=''){
62 windowSize();
63 window.open(url,'mywindow',winW+','+winH+','+'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');
64 }
65
66 else{
67 alert("NO URL AVAILABLE");
68 }
69 //document.body.style.cursor = "default";
70}
71
72
73function newwin(nameList,valueList){
74 var newwindo;
75 var htm="<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><title>Metadata Element Detail</title><style type=text/css >body{font-family:arial;}</style></head>";
76 htm+="<body><table border=2>";
77
78 var internalElement = new Array();
79
80 for(var i =0;i<nameList.length; i++){
81 if (/^[A-Z]+$/.test(nameList[i].charAt(0))) {
82 //if(nameList[i]=="URL" && (valueList[i]. substring(0,4)=="http")){
83 if(valueList[i]. substring(0,4)=="http"){
84 htm+="<tr><td>"+nameList[i]+"<td><a href="+valueList[i]+" target=_blank >"+valueList[i];
85 }
86 else{
87 if(valueList[i].length>=200){
88 htm+="<tr><td>"+nameList[i]+"<td>"+valueList[i].substr(0,200)+" ...";
89 }
90 else{
91 htm+="<tr><td>"+nameList[i]+"<td>"+valueList[i];
92 }
93
94 }
95 }
96 else{ internalElement.push(i);}
97 }
98
99 for(var i =0; i<internalElement.length; i++){
100 var num = internalElement[i];
101 //if(nameList[num]=="URL" && (valueList[num]. substring(0,4)=="http")){
102 if(valueList[num]. substring(0,4)=="http"){
103 htm+="<tr><td>"+nameList[num]+"<td><a href="+valueList[num]+" target=_blank >"+valueList[num];
104 }
105 else{
106 if(valueList[num].length>=200){
107 htm+="<tr><td>"+nameList[num]+"<td>"+valueList[num].substr(0,200)+" ...";
108 }
109 else{
110 htm+="<tr><td>"+nameList[num]+"<td>"+valueList[num];
111 }
112
113 }
114
115 }
116
117 htm+="</table><p align=center><input type=button onclick=window.close() value=Close /></p></body></html>";
118 newwindo=window.open('','mywindow',winW+','+winH+','+'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');
119 newwindo.document.write(htm);
120 newwindo.document.close();
121 //document.body.style.cursor = "default";
122 }
123
124
125function ajaxSearch(request) {
126
127
128//alert("wait");
129
130
131//alert("This process takes a few seconds");
132
133var bodyTag = document.getElementsByTagName('body');
134var collection = (bodyTag[0].getAttribute('id'));
135request = 'HASH'+request;
136docID = newElementAtt('param', '', new Array('name', 'value'), new Array('metadata', 'all') ) ;
137paramList = newElement('paramList',docID);
138NodeID = newElementAtt('documentNode', '', new Array('nodeID'), new Array(request) ) ;
139documentNodeList = newElement('documentNodeList',NodeID);
140
141request = newElementAtt5('request', paramList,documentNodeList, new Array('lang', 'to', 'type'), new Array('en',collection+'/DocumentMetadataRetrieve', 'process' ) );
142message = newElement('message', request );
143soapMessage = messageToSOAP(message);
144
145makeRequest(soapMessage);
146//loadAsync(soapMessage);
147//alert(soapMessage);
148//alert("Please wait...");
149}
150
151function newElementAtt5(name, content,content2, nameArray, valueArray) {
152
153 e = '<' + name + ' ' ;
154 for (i=0; i < nameArray.length; i++) {
155 e += newAttribute(nameArray[i], valueArray[i])
156 }
157 e += '>' + content+content2;
158 e += '</' + name + '>';
159
160 return e;
161}
162
163function messageToSOAP(message) {
164 soapBody = '<soapenv:Body>' + message + '</soapenv:Body>'
165 soap = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' + soapBody + '</soapenv:Envelope>'
166 x= '<?xml version="1.0" encoding="UTF-8"?>' + soap;
167 return x;
168}
169
170function newElement(name, content) {
171 e = '<' + name + '>' + content;
172 e += '</' + name + '>';
173 return e;
174}
175
176function newElementAtt(name, content, nameArray, valueArray) {
177 e = '<' + name + ' ' ;
178 for (i=0; i < nameArray.length; i++) {
179 e += newAttribute(nameArray[i], valueArray[i])
180 }
181 e += '>' + content;
182 e += '</' + name + '>';
183 return e;
184}
185
186
187function newAttribute(name, value) {
188 return ' ' + name + '="' + value + '"';
189}
190
191function makeRequest(postData){
192 //alert(postData)
193 YAHOO.util.Connect.initHeader('SOAPAction','http://tempuri.org/GetMagnetometerStation',true);
194 //var request = YAHOO.util.Connect.asyncRequest('POST', 'http://hinau.cs.waikato.ac.nz:8090/greenstone3/services/localsite', callback, postData);
195 //var request = YAHOO.util.Connect.asyncRequest('POST', 'http://nzdl.org/greenstone3/mat/services/localsite', callback, postData);
196var request = YAHOO.util.Connect.asyncRequest('POST', '/greenstone3/mat/services/localsite', callback, postData);
197}
198
199
200var handleSuccess = function(o){
201//document.body.style.cursor='wait';
202//alert(o.responseText);
203//alert("done");
204//alert(opt+"?");
205//alert(opt+"step 3");
206 var nameList = new Array();
207 var valueList = new Array();
208
209
210 var xmldoc = o.responseXML;
211 var nodes = xmldoc.getElementsByTagName('metadata');
212 var mesg = "";
213 var msg = "";
214 var urllocation ="";
215 //alert(o.responseText);
216 for(var i=0; i<nodes.length; i++) {
217 mesg = nodes[i].firstChild.nodeValue;
218 //alert(mesg+" "+mesg.indexOf('^'));
219
220 if(mesg==valueList[valueList.length-1]){}
221 else{
222 msg = nodes[i].getAttribute('name');
223 if(msg.indexOf('^')!=-1){
224 msg = msg.replace('^','.');
225 }
226 if(msg!='prettymd' && msg.substring(0,12)!='metadatafreq' && msg.substring(0,12)!='metadatalist'&& msg.substring(0,10)!='metadataset' ){
227 valueList.push(mesg);
228 nameList.push(msg);
229 }
230 if((msg=="URL" && mesg.substring(0,4)=="http") ||(mesg.substring(0,4)=="http") ){
231 //alert(msg+ " "+mesg);
232 urllocation = mesg;
233 }
234 }
235
236 }
237 //document.ajax.dyn.value="Received:";
238 //alert(nameList)
239 if(opt=="info" && nameList.length!=0){
240 //alert(nameList.length+nameList[0]);
241
242 newwin(nameList,valueList);
243 }
244 else if(opt=="url" && nameList.length!=0){
245 newwindows(urllocation);
246 }
247 //document.body.style.cursor = "default";
248};
249
250var handleFailure = function(o){
251//alert(o.responseText);
252alert("fail");
253};
254
255var callback =
256{
257 success:handleSuccess,
258 failure:handleFailure,
259 argument:['foo','bar']
260};
Note: See TracBrowser for help on using the repository browser.