3 var currentHoldRecordObj;
4 var holdsOrgSelectorBuilt = false;
13 function holdsHandleStaff() {
14 swapCanvas($('xulholds_box'));
15 $('xul_recipient_barcode').focus();
16 $('xul_recipient_barcode').onkeypress = function(evt)
17 {if(userPressedEnter(evt)) { _holdsHandleStaff(); } };
18 $('xul_recipient_barcode_submit').onclick = _holdsHandleStaff;
19 $('xul_recipient_me').onclick = _holdsHandleStaffMe;
22 function _holdsHandleStaffMe() {
23 holdRecipient = G.user;
24 holdsDrawWindow( currentHoldRecord, null );
27 function _holdsHandleStaff() {
28 var barcode = $('xul_recipient_barcode').value;
29 var user = grabUserByBarcode( G.user.session, barcode );
30 var code = checkILSEvent(user);
32 alertILSEvent(code, barcode);
37 holdsDrawWindow( currentHoldRecord, null );
40 function holdsDrawWindow(recid, type, edithold, done_callback) {
43 recid = currentHoldRecord;
44 if(recid == null) return;
46 currentHoldRecord = recid;
47 holdEditHold = edithold;
48 holdEditCallback = done_callback;
50 if(isXUL() && holdRecipient == null ) {
55 if( holdRecipient == null ) holdRecipient = G.user;
56 if( holdRequestor == null ) holdRequestor = G.user;
58 if(!(holdRequestor && holdRequestor.session)) {
60 detachAllEvt('common','locationChanged');
61 attachEvt('common','loggedIn', holdsDrawWindow)
67 swapCanvas($('check_holds_box'));
70 hideMe($('holds_submit'));
71 unHideMe($('holds_update'));
72 _holdsDrawWindow(recid, type);
73 _holdsUpdateEditHold(edithold);
76 setTimeout( function() { holdsCheckPossibility(recid, type); }, 10 );
80 function _holdsUpdateEditHold(hold) {
82 if( hold.capture_time() )
83 $('holds_org_selector').disabled = true;
85 setSelector($('holds_org_selector'), hold.pickup_lib());
87 $('holds_submit').onclick = holdsEditHold;
88 $('holds_update').onclick = holdsEditHold;
91 if(hold.phone_notify()) {
92 $('holds_enable_phone').checked = true;
93 $('holds_phone').value = hold.phone_notify();
96 $('holds_phone').disabled = true;
97 $('holds_enable_phone').checked = false;
100 if(hold.email_notify()) {
101 $('holds_enable_email').checked = true;
104 $('holds_enable_email').checked = false;
108 function holdsEditHold() {
109 var hold = holdsBuildHoldFromWindow();
110 //hold.id( holdEditHold.id() );
113 if(holdEditCallback) holdEditCallback(hold);
117 function _holdsDrawWindow(recid, type) {
119 swapCanvas($('holds_box'));
121 var rec = findRecord( recid, type );
122 currentHoldsRecordObj = rec;
124 if(!holdsOrgSelectorBuilt) {
125 holdsBuildOrgSelector(null,0);
126 holdsOrgSelectorBuilt = true;
130 var dsel = $('holds_depth_selector');
131 unHideMe($('holds_depth_selector_row'));
132 if(dsel.getElementsByTagName('option').length == 0) {
133 var types = globalOrgTypes;
134 var depth = findOrgDepth(G.user.ws_ou());
137 if(t.depth() > depth) return;
138 insertSelectorVal(dsel, -1, t.opac_label(), t.depth());
144 appendClear($('holds_recipient'), text(
145 holdRecipient.family_name() + ', ' +
146 holdRecipient.first_given_name()));
147 appendClear($('holds_title'), text(rec.title()));
148 appendClear($('holds_author'), text(rec.author()));
150 removeChildren($('holds_format'));
151 for( var i in rec.types_of_resource() ) {
152 var res = rec.types_of_resource()[i];
153 var img = elem("img");
154 setResourcePic(img, res);
155 $('holds_format').appendChild(text(' '+res+' '));
156 $('holds_format').appendChild(img);
157 $('holds_format').appendChild(text(' '));
161 $('holds_phone').value = holdRecipient.day_phone();
162 appendClear( $('holds_email'), text(holdRecipient.email()));
164 var pref = G.user.prefs[PREF_HOLD_NOTIFY];
167 if( ! pref.match(/email/i) )
168 $('holds_enable_email').checked = false;
170 if( ! pref.match(/phone/i) ) {
171 $('holds_phone').disabled = true;
172 $('holds_enable_phone').checked = false;
176 $('holds_cancel').onclick = function(){ runEvt('common', 'holdUpdateCanceled'), showCanvas() };
177 $('holds_submit').onclick = function(){holdsPlaceHold(holdsBuildHoldFromWindow())};
178 $('holds_update').onclick = function(){holdsPlaceHold(holdsBuildHoldFromWindow())};
179 appendClear($('holds_physical_desc'), text(rec.physical_description()));
180 if(type == 'M') hideMe($('hold_physical_desc_row'));
184 function holdsCheckPossibility(recid, type) {
185 var req = new Request(CHECK_HOLD_POSSIBLE, G.user.session,
186 { titleid : recid, patronid : G.user.id(), depth : 0 } );
188 var res = req.result();
190 if(res) _holdsDrawWindow(recid, type);
195 function holdsBuildOrgSelector(node) {
197 if(!node) node = globalOrgTree;
199 var selector = $('holds_org_selector');
200 var index = selector.options.length;
202 var type = findOrgType(node.ou_type());
203 var indent = type.depth() - 1;
204 var opt = setSelectorVal( selector, index, node.name(), node.id(), null, indent );
205 if(!type.can_have_vols()) opt.disabled = true;
207 if( node.id() == holdRecipient.home_ou() ) {
208 selector.selectedIndex = index;
209 selector.options[index].selected = true;
212 for( var i in node.children() ) {
213 var child = node.children()[i];
214 if(child) holdsBuildOrgSelector(child);
218 function holdsBuildHoldFromWindow() {
220 var org = $('holds_org_selector').options[
221 $('holds_org_selector').selectedIndex].value;
223 var hold = new ahr();
230 if( $('holds_enable_phone').checked ) {
231 var phone = $('holds_phone').value;
232 if( !phone.match(REGEX_PHONE) ) {
233 alert($('holds_bad_phone').innerHTML);
236 hold.phone_notify(phone);
239 hold.phone_notify("");
242 if( $('holds_enable_email').checked )
243 hold.email_notify(1);
245 hold.email_notify(0);
248 hold.pickup_lib(org);
249 hold.request_lib(org);
250 hold.requestor(holdRequestor.id());
251 hold.usr(holdRecipient.id());
253 hold.target(currentHoldRecord);
255 hold.selection_depth(getSelectorVal($('holds_depth_selector')));
259 function holdsPlaceHold(hold) {
261 var req = new Request( CREATE_HOLD, holdRequestor.session, hold );
263 var res = req.result();
265 if( res == '1' ) alert($('holds_success').innerHTML);
266 else alert($('holds_failure').innerHTML);
269 holdRecipient = null;
270 holdRequestor = null;
271 runEvt('common', 'holdUpdated');
274 function holdsCancel(holdid, user) {
275 if(!user) user = G.user;
276 var req = new Request(CANCEL_HOLD, user.session, holdid);
279 runEvt('common', 'holdUpdated');
282 function holdsUpdate(hold, user) {
283 if(!user) user = G.user;
284 var req = new Request(UPDATE_HOLD, user.session, hold);
286 var x = req.result(); /* cause an exception if there is one */
287 runEvt('common', 'holdUpdated');