partial details apge
[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         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(ev) {
89                 spawn_record_details(
90                         p.w.app_shell, 'new_tab', 'main_tabbox', {
91                                 'find_this_id' : id
92                         }
93                 ).find_this_id = id;
94                 ev.preventDefault();
95                 ev.stopPropagation();
96                 return true;
97         }
98         node.addEventListener( 'click', f, false );
99 }
100
101 /* -------------------------------------------------------------------------- 
102         back-forward
103         -------------------------------------------------------------------------- */
104 function opac_build_navigation(p) {
105         p.webForward = function webForward() {
106                 try {
107                         if(p.opac_iframe.webNavigation.canGoForward)
108                                 p.opac_iframe.webNavigation.goForward();
109                 } catch(E) {
110                         sdump('D_OPAC','goForward error: ' + js2JSON(E) + '\n');
111                 }
112         }
113
114         p.webBack = function webBack() {
115                 try {
116                         if(p.opac_iframe.webNavigation.canGoBack)
117                                 p.opac_iframe.webNavigation.goBack();
118                 } catch(E) {
119                         sdump('D_OPAC','goBack error: ' + js2JSON(E) + '\n');
120                 }
121         }
122 }
123
124
125
126
127
128
129