debugging. Here in the office, the dynamically built progressListener shows the...
[working/Evergreen.git] / Evergreen / staff_client / chrome / content / evergreen / opac / opac.js
1 sdump('D_OPAC','Loading opac.js\n');
2
3 var OPAC_URL = "http://spacely.georgialibraries.org:8080/";
4
5 /* listen for page changes */
6
7 function buildProgressListener(p) {
8         sdump('D_OPAC',arg_dump(arguments));
9         return {
10                 onProgressChange        : function(){},
11                 onLocationChange        : function(){},
12                 onStatusChange          : function(){},
13                 onSecurityChange        : function(){},
14                 QueryInterface          : function(){return this;},
15                 onStateChange           : function ( webProgress, request, stateFlags, status) {
16                         const nsIWebProgressListener = Components.interfaces.nsIWebProgressListener;
17                         const nsIChannel = Components.interfaces.nsIChannel;
18                         if (stateFlags == 65540 || stateFlags == 65537 || stateFlags == 65552) { return; }
19                         dump('onStateChange: stateFlags = ' + stateFlags + ' status = ' + status + '\n');
20                         if (stateFlags & nsIWebProgressListener.STATE_IS_REQUEST) {
21                                 dump('\tSTATE_IS_REQUEST\n');
22                         }
23                         if (stateFlags & nsIWebProgressListener.STATE_IS_DOCUMENT) {
24                                 dump('\tSTATE_IS_DOCUMENT\n');
25                                 if( stateFlags & nsIWebProgressListener.STATE_STOP ) set_opac_vars(p); 
26                         }
27                         if (stateFlags & nsIWebProgressListener.STATE_IS_NETWORK) {
28                                 dump('\tSTATE_IS_NETWORK\n');
29                         }
30                         if (stateFlags & nsIWebProgressListener.STATE_IS_WINDOW) {
31                                 dump('\tSTATE_IS_WINDOW\n');
32                         }
33                         if (stateFlags & nsIWebProgressListener.STATE_START) {
34                                 dump('\tSTATE_START\n');
35                         }
36                         if (stateFlags & nsIWebProgressListener.STATE_REDIRECTING) {
37                                 dump('\tSTATE_REDIRECTING\n');
38                         }
39                         if (stateFlags & nsIWebProgressListener.STATE_TRANSFERING) {
40                                 dump('\tSTATE_TRANSFERING\n');
41                         }
42                         if (stateFlags & nsIWebProgressListener.STATE_NEGOTIATING) {
43                                 dump('\tSTATE_NEGOTIATING\n');
44                         }
45                         if (stateFlags & nsIWebProgressListener.STATE_STOP) {
46                                 dump('\tSTATE_STOP\n');
47                         }
48                 }
49         }
50 }
51
52 /* init the opac */
53 function opac_init(p) {
54         sdump('D_OPAC',"Initing OPAC\n");
55
56         p.opac_iframe = p.w.document.getElementById('opac_opac_iframe');
57         p.opac_iframe.addProgressListener(buildProgressListener(p), 
58                 Components.interfaces.nsIWebProgress.NOTIFY_ALL );
59         p.opac_iframe.setAttribute("src", OPAC_URL) 
60 }
61
62 /* shoves data into the OPAC's space */
63 function set_opac_vars(p) {
64         sdump('D_OPAC',arg_dump(arguments));
65         p.opac_iframe.contentWindow.IAMXUL = true;
66         p.opac_iframe.contentWindow.xulG = mw.G;
67         p.opac_iframe.contentWindow.attachEvt("rresult", "recordDrawn", opac_make_details_page);
68         dump('p.opac_iframe = ' + p.opac_iframe + '\n');
69         dump('p.opac_iframe.contentWindow = ' + p.opac_iframe.contentWindow + '\n');
70         dump('p.opac_iframe.contentWindow = ' + p.opac_iframe.contentWindow + '\n');
71         dump('p.opac_iframe.contentWindow.G = ' + p.opac_iframe.contentWindow.G + '\n');
72         dump('p.opac_iframe.contentWindow.G.evt = ' + p.opac_iframe.contentWindow.G.evt + '\n');
73         dump('p.opac_iframe.contentWindow.G.evt.rresult = ' + p.opac_iframe.contentWindow.G.evt.rresult + '\n');
74         dump('p.opac_iframe.contentWindow.G.evt.rresult.recordDrawn = ' + p.opac_iframe.contentWindow.G.evt.rresult.recordDrawn + '\n');
75         var a = p.opac_iframe.contentWindow.G.evt.rresult.recordDrawn;
76         for (var i in a) {
77                 dump('\t'+i+'\t'+a[i]+'\n');    
78         }
79 }
80
81 function opac_make_details_page(id, node) {
82         sdump('D_OPAC',arg_dump(arguments));
83         dump("Node HREF attribute is: " + node.getAttribute("href") + "\n and doc id is " + id +'\n');
84         alert("Node HREF attribute is: " + node.getAttribute("href") + "\n and doc id is " + id +'\n');
85 }
86
87
88 /* -------------------------------------------------------------------------- 
89         back-forward
90         -------------------------------------------------------------------------- */
91 function opac_build_navigation(p) {
92         p.webForward = function webForward() {
93                 try {
94                         if(p.opac_iframe.webNavigation.canGoForward)
95                                 p.opac_iframe.webNavigation.goForward();
96                 } catch(E) {
97                         sdump('D_OPAC','goForward error: ' + js2JSON(E) + '\n');
98                 }
99         }
100
101         p.webBack = function webBack() {
102                 try {
103                         if(p.opac_iframe.webNavigation.canGoBack)
104                                 p.opac_iframe.webNavigation.goBack();
105                 } catch(E) {
106                         sdump('D_OPAC','goBack error: ' + js2JSON(E) + '\n');
107                 }
108         }
109 }
110
111
112
113
114
115
116