]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/holds.js
Much bookbag integration - more to follow
[Evergreen.git] / Open-ILS / web / opac / skin / default / js / holds.js
1
2 var currentHoldRecord;
3 var currentHoldRecordObj;
4 var holdsOrgSelectorBuilt = false;
5 var holdRecipient;
6 var holdRequestor
7 var holdEmail;
8 var holdPhone;
9
10
11 function holdsHandleStaff() {
12         swapCanvas($('xulholds_box'));
13         $('xul_recipient_barcode').focus();
14         $('xul_recipient_barcode').onkeypress = function(evt) 
15                 {if(userPressedEnter(evt)) { _holdsHandleStaff(); } };
16         $('xul_recipient_barcode_submit').onclick = _holdsHandleStaff;
17 }
18
19 function _holdsHandleStaff() {
20         var barcode = $('xul_recipient_barcode').value;
21         var user = grabUserByBarcode( G.user.session, barcode );
22         var code = checkILSEvent(user);
23         if(code || !user) {
24                 alertILSEvent(code, barcode);
25                 showCanvas();
26                 return;
27         }
28         holdRecipient = user;
29         holdsDrawWindow( currentHoldRecord, null );
30 }
31
32 function holdsDrawWindow(recid, type) {
33
34         if(recid == null) {
35                 recid = currentHoldRecord;
36                 if(recid == null) return;
37         }       
38         currentHoldRecord = recid;
39         
40         if(isXUL() && holdRecipient == null ) { 
41                 holdsHandleStaff();
42                 return;
43         }
44
45         if( holdRecipient == null ) holdRecipient = G.user;
46         if( holdRequestor == null ) holdRequestor = G.user;
47
48         if(!(holdRequestor && holdRequestor.session)) {
49
50                 detachAllEvt('common','locationChanged');
51                 attachEvt('common','loggedIn', holdsDrawWindow)
52                 initLogin();
53                 return;
54         }
55         swapCanvas($('holds_box'));
56
57         var rec = findRecord( recid, type );
58         currentHoldsRecordObj = rec;
59
60         if(!holdsOrgSelectorBuilt) {
61                 holdsBuildOrgSelector(null,0);
62                 holdsOrgSelectorBuilt = true;
63         }
64
65         appendClear($('holds_recipient'), text(
66                 holdRecipient.family_name() + ', ' +  
67                         holdRecipient.first_given_name()));
68         appendClear($('holds_title'), text(rec.title()));
69         appendClear($('holds_author'), text(rec.author()));
70
71         //removeChildren($('holds_format'));
72         for( var i in rec.types_of_resource() ) {
73                 var res = rec.types_of_resource()[i];
74                 var img = elem("img");
75                 setResourcePic(img, res);
76                 $('holds_format').appendChild(text(' '+res+' '));
77                 $('holds_format').appendChild(img);
78                 $('holds_format').appendChild(text(' '));
79         }
80
81         appendClear( $('holds_phone'), text(holdRecipient.day_phone()));
82         appendClear( $('holds_email'), text(holdRecipient.email()));
83         $('holds_cancel').onclick = showCanvas;
84         $('holds_submit').onclick = holdsPlaceHold; 
85 }
86
87
88 function holdsBuildOrgSelector(node) {
89
90         if(!node) node = globalOrgTree;
91
92         var selector = $('holds_org_selector');
93         var index = selector.options.length;
94
95         var indent = findOrgType(node.ou_type()).depth() - 1;
96         setSelectorVal( selector, index, node.name(), node.id(), null, indent );
97         
98         if( node.id() == holdRecipient.home_ou() ) {
99                 selector.selectedIndex = index;
100                 selector.options[index].selected = true;        
101         }
102
103         for( var i in node.children() ) {
104                 var child = node.children()[i];
105                 if(child) holdsBuildOrgSelector(child);
106         }
107 }
108
109 function holdsPlaceHold() {
110
111         var org = $('holds_org_selector').options[
112                 $('holds_org_selector').selectedIndex].value;
113
114         var hold = new ahr();
115         hold.pickup_lib(org); 
116         hold.request_lib(org); 
117         hold.requestor(holdRequestor.id());
118         hold.usr(holdRecipient.id());
119         hold.hold_type('T');
120         hold.email_notify(holdRecipient.email());
121         hold.phone_notify(holdRecipient.day_phone());
122         hold.target(currentHoldRecord);
123         
124         var req = new Request( CREATE_HOLD, holdRequestor.session, hold );
125         req.send(true);
126         var res = req.result();
127
128         if( res == '1' ) alert($('holds_success').innerHTML);
129         else alert($('holds_failure').innerHTML);
130         
131         showCanvas();
132         holdRecipient = null;
133         holdRequestor = null;
134 }
135
136 function holdsCancel(holdid, user) {
137         if(!user) user = G.user;
138         var req = new Request(CANCEL_HOLD, user.session, holdid);
139         req.send(true);
140         return req.result();
141 }
142
143