9b076da071a3385c7b089fc7fc8c9b3bf59354cd
[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         var progressListener = {
10                 onProgressChange        : function(){},
11                 onLocationChange        : function(){},
12                 onStatusChange          : function(){},
13                 onSecurityChange        : function(){},
14                 onStateChange           : function ( webProgress, request, stateFlags, status) {
15                         const nsIWebProgressListener = Components.interfaces.nsIWebProgressListener;
16                         const nsIChannel = Components.interfaces.nsIChannel;
17                         if (stateFlags == 65540 || stateFlags == 65537 || stateFlags == 65552) { return; }
18                         dump('onStateChange: stateFlags = ' + stateFlags + ' status = ' + status + '\n');
19                         if (stateFlags & nsIWebProgressListener.STATE_IS_REQUEST) {
20                                 dump('\tSTATE_IS_REQUEST\n');
21                         }
22                         if (stateFlags & nsIWebProgressListener.STATE_IS_DOCUMENT) {
23                                 dump('\tSTATE_IS_DOCUMENT\n');
24                                 if( stateFlags & nsIWebProgressListener.STATE_STOP ) set_opac_vars(p); 
25                         }
26                         if (stateFlags & nsIWebProgressListener.STATE_IS_NETWORK) {
27                                 dump('\tSTATE_IS_NETWORK\n');
28                         }
29                         if (stateFlags & nsIWebProgressListener.STATE_IS_WINDOW) {
30                                 dump('\tSTATE_IS_WINDOW\n');
31                         }
32                         if (stateFlags & nsIWebProgressListener.STATE_START) {
33                                 dump('\tSTATE_START\n');
34                         }
35                         if (stateFlags & nsIWebProgressListener.STATE_REDIRECTING) {
36                                 dump('\tSTATE_REDIRECTING\n');
37                         }
38                         if (stateFlags & nsIWebProgressListener.STATE_TRANSFERING) {
39                                 dump('\tSTATE_TRANSFERING\n');
40                         }
41                         if (stateFlags & nsIWebProgressListener.STATE_NEGOTIATING) {
42                                 dump('\tSTATE_NEGOTIATING\n');
43                         }
44                         if (stateFlags & nsIWebProgressListener.STATE_STOP) {
45                                 dump('\tSTATE_STOP\n');
46                         }
47                 }
48         }
49         progressListener.QueryInterface = function(){return this;};
50         return progressListener;
51 }
52
53 /* init the opac */
54 function opac_init(p) {
55         sdump('D_OPAC',"Initing OPAC\n");
56
57         p.opac_progressListener = buildProgressListener(p);
58
59         p.opac_iframe = p.w.document.getElementById('opac_opac_iframe');
60         p.opac_iframe.addProgressListener(p.opac_progressListener, 
61                 Components.interfaces.nsIWebProgress.NOTIFY_ALL );
62         p.opac_iframe.setAttribute("src", OPAC_URL) 
63 }
64
65 /* shoves data into the OPAC's space */
66 function set_opac_vars(p) {
67         sdump('D_OPAC',arg_dump(arguments));
68         p.opac_iframe.contentWindow.IAMXUL = true;
69         p.opac_iframe.contentWindow.xulG = mw.G;
70         p.opac_iframe.contentWindow.attachEvt("rresult", "recordDrawn", 
71                 function(id,node){opac_make_details_page(p,id,node)});
72         dump('p.opac_iframe = ' + p.opac_iframe + '\n');
73         dump('p.opac_iframe.contentWindow = ' + p.opac_iframe.contentWindow + '\n');
74         dump('p.opac_iframe.contentWindow = ' + p.opac_iframe.contentWindow + '\n');
75         dump('p.opac_iframe.contentWindow.G = ' + p.opac_iframe.contentWindow.G + '\n');
76         dump('p.opac_iframe.contentWindow.G.evt = ' + p.opac_iframe.contentWindow.G.evt + '\n');
77         dump('p.opac_iframe.contentWindow.G.evt.rresult = ' + p.opac_iframe.contentWindow.G.evt.rresult + '\n');
78         dump('p.opac_iframe.contentWindow.G.evt.rresult.recordDrawn = ' + p.opac_iframe.contentWindow.G.evt.rresult.recordDrawn + '\n');
79         p.opac_iframe.removeProgressListener(p.opac_progressListener);
80         p.opac_iframe.addProgressListener(p.opac_progressListener, 
81                 Components.interfaces.nsIWebProgress.NOTIFY_STATE_DOCUMENT );
82
83 }
84
85 function opac_make_details_page(p, id, node) {
86         sdump('D_OPAC',arg_dump(arguments));
87         dump("Node HREF attribute is: " + node.getAttribute("href") + "\n and doc id is " + id +'\n');
88         var f = function() {
89                 spawn_copy_browser(
90                         p.w.app_shell, 'new_tab', 'main_tabbox', {
91                                 'find_this_id' : id
92                         }
93                 ).find_this_id = id;
94                 return true;
95         }
96         node.addEventListener( 'click', f, false );
97 }
98
99 /* -------------------------------------------------------------------------- 
100         back-forward
101         -------------------------------------------------------------------------- */
102 function opac_build_navigation(p) {
103         p.webForward = function webForward() {
104                 try {
105                         if(p.opac_iframe.webNavigation.canGoForward)
106                                 p.opac_iframe.webNavigation.goForward();
107                 } catch(E) {
108                         sdump('D_OPAC','goForward error: ' + js2JSON(E) + '\n');
109                 }
110         }
111
112         p.webBack = function webBack() {
113                 try {
114                         if(p.opac_iframe.webNavigation.canGoBack)
115                                 p.opac_iframe.webNavigation.goBack();
116                 } catch(E) {
117                         sdump('D_OPAC','goBack error: ' + js2JSON(E) + '\n');
118                 }
119         }
120 }
121
122
123
124
125
126
127