]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/holds.js
removed the older Cookie.js code.
[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
56
57         swapCanvas($('check_holds_box'));
58         setTimeout( function() { holdsCheckPossibility(recid, type); }, 10 );
59 }
60
61 function _holdsDrawWindow(recid, type) {
62
63         swapCanvas($('holds_box'));
64
65         var rec = findRecord( recid, type );
66         currentHoldsRecordObj = rec;
67
68         if(!holdsOrgSelectorBuilt) {
69                 holdsBuildOrgSelector(null,0);
70                 holdsOrgSelectorBuilt = true;
71         }
72
73         appendClear($('holds_recipient'), text(
74                 holdRecipient.family_name() + ', ' +  
75                         holdRecipient.first_given_name()));
76         appendClear($('holds_title'), text(rec.title()));
77         appendClear($('holds_author'), text(rec.author()));
78
79         removeChildren($('holds_format'));
80         for( var i in rec.types_of_resource() ) {
81                 var res = rec.types_of_resource()[i];
82                 var img = elem("img");
83                 setResourcePic(img, res);
84                 $('holds_format').appendChild(text(' '+res+' '));
85                 $('holds_format').appendChild(img);
86                 $('holds_format').appendChild(text(' '));
87         }
88
89         appendClear( $('holds_phone'), text(holdRecipient.day_phone()));
90         appendClear( $('holds_email'), text(holdRecipient.email()));
91         $('holds_cancel').onclick = showCanvas;
92         $('holds_submit').onclick = holdsPlaceHold; 
93 }
94
95
96 function holdsCheckPossibility(recid, type) {
97         var req = new Request(CHECK_HOLD_POSSIBLE, G.user.session, 
98                         { titleid : recid, patronid : G.user.id(), depth : 0 } );
99         req.send(true);
100         var res = req.result();
101
102         if(res) _holdsDrawWindow(recid, type);
103         else drawCanvas();
104 }
105
106
107 function holdsBuildOrgSelector(node) {
108
109         if(!node) node = globalOrgTree;
110
111         var selector = $('holds_org_selector');
112         var index = selector.options.length;
113
114         var indent = findOrgType(node.ou_type()).depth() - 1;
115         setSelectorVal( selector, index, node.name(), node.id(), null, indent );
116         
117         if( node.id() == holdRecipient.home_ou() ) {
118                 selector.selectedIndex = index;
119                 selector.options[index].selected = true;        
120         }
121
122         for( var i in node.children() ) {
123                 var child = node.children()[i];
124                 if(child) holdsBuildOrgSelector(child);
125         }
126 }
127
128 function holdsPlaceHold() {
129
130         var org = $('holds_org_selector').options[
131                 $('holds_org_selector').selectedIndex].value;
132
133         var hold = new ahr();
134         hold.pickup_lib(org); 
135         hold.request_lib(org); 
136         hold.requestor(holdRequestor.id());
137         hold.usr(holdRecipient.id());
138         hold.hold_type('T');
139         hold.email_notify(holdRecipient.email());
140         hold.phone_notify(holdRecipient.day_phone());
141         hold.target(currentHoldRecord);
142         
143         var req = new Request( CREATE_HOLD, holdRequestor.session, hold );
144         req.send(true);
145         var res = req.result();
146
147         if( res == '1' ) alert($('holds_success').innerHTML);
148         else alert($('holds_failure').innerHTML);
149         
150         showCanvas();
151         holdRecipient = null;
152         holdRequestor = null;
153 }
154
155 function holdsCancel(holdid, user) {
156         if(!user) user = G.user;
157         var req = new Request(CANCEL_HOLD, user.session, holdid);
158         req.send(true);
159         return req.result();
160 }
161
162