4 var currentHoldRecordObj;
5 var holdsOrgSelectorBuilt = false;
14 function holdsHandleStaff() {
15 swapCanvas($('xulholds_box'));
16 $('xul_recipient_barcode').focus();
17 $('xul_recipient_barcode').onkeypress = function(evt)
18 {if(userPressedEnter(evt)) { _holdsHandleStaff(); } };
19 $('xul_recipient_barcode_submit').onclick = _holdsHandleStaff;
20 $('xul_recipient_me').onclick = _holdsHandleStaffMe;
23 function _holdsHandleStaffMe() {
24 holdRecipient = G.user;
25 holdsDrawWindow( currentHoldRecord, null );
28 function _holdsHandleStaff() {
29 var barcode = $('xul_recipient_barcode').value;
30 var user = grabUserByBarcode( G.user.session, barcode );
31 var code = checkILSEvent(user);
33 alertILSEvent(user, barcode);
38 holdsDrawWindow( currentHoldRecord, null );
41 function holdsDrawWindow(recid, type, edithold, done_callback) {
44 recid = currentHoldRecord;
45 if(recid == null) return;
48 currentHoldRecord = recid;
49 currentHoldType = type;
50 holdEditHold = edithold;
51 holdEditCallback = done_callback;
53 if(isXUL() && holdRecipient == null && holdEditHold == null) {
58 if( holdRecipient == null ) holdRecipient = G.user;
59 if( holdRequestor == null ) holdRequestor = G.user;
61 if(!(holdRequestor && holdRequestor.session)) {
63 detachAllEvt('common','locationChanged');
64 attachEvt('common','loggedIn', holdsDrawWindow)
69 _holdsDrawWindow(recid, type);
71 hideMe($('holds_submit'));
72 unHideMe($('holds_update'));
73 _holdsUpdateEditHold(edithold);
77 function _holdsUpdateEditHold(hold) {
79 if( hold.capture_time() )
80 $('holds_org_selector').disabled = true;
82 setSelector($('holds_org_selector'), hold.pickup_lib());
84 $('holds_submit').onclick = holdsEditHold;
85 $('holds_update').onclick = holdsEditHold;
88 if(hold.phone_notify()) {
89 $('holds_enable_phone').checked = true;
90 $('holds_phone').value = hold.phone_notify();
93 $('holds_phone').disabled = true;
94 $('holds_enable_phone').checked = false;
97 if(hold.email_notify()) {
98 $('holds_enable_email').checked = true;
101 $('holds_enable_email').checked = false;
105 function holdsEditHold() {
106 var hold = holdsBuildHoldFromWindow();
107 //hold.id( holdEditHold.id() );
111 if(holdEditCallback) holdEditCallback(hold);
115 function _holdsDrawWindow(recid, type) {
117 swapCanvas($('holds_box'));
119 var rec = findRecord( recid, type );
120 currentHoldsRecordObj = rec;
122 if(!holdsOrgSelectorBuilt) {
123 holdsBuildOrgSelector(null,0);
124 holdsOrgSelectorBuilt = true;
128 var dsel = $('holds_depth_selector');
129 unHideMe($('holds_depth_selector_row'));
130 if(dsel.getElementsByTagName('option').length == 0) {
131 var types = globalOrgTypes;
132 var depth = findOrgDepth(G.user.ws_ou());
135 if(t.depth() > depth) return;
136 insertSelectorVal(dsel, -1, t.opac_label(), t.depth());
142 appendClear($('holds_recipient'), text(
143 holdRecipient.family_name() + ', ' +
144 holdRecipient.first_given_name()));
145 appendClear($('holds_title'), text(rec.title()));
146 appendClear($('holds_author'), text(rec.author()));
148 removeChildren($('holds_format'));
149 for( var i in rec.types_of_resource() ) {
150 var res = rec.types_of_resource()[i];
151 var img = elem("img");
152 setResourcePic(img, res);
153 $('holds_format').appendChild(text(' '+res+' '));
154 $('holds_format').appendChild(img);
155 $('holds_format').appendChild(text(' '));
159 $('holds_phone').value = holdRecipient.day_phone();
160 appendClear( $('holds_email'), text(holdRecipient.email()));
162 var pref = G.user.prefs[PREF_HOLD_NOTIFY];
165 if( ! pref.match(/email/i) )
166 $('holds_enable_email').checked = false;
168 if( ! pref.match(/phone/i) ) {
169 $('holds_phone').disabled = true;
170 $('holds_enable_phone').checked = false;
174 $('holds_cancel').onclick = function(){ runEvt('common', 'holdUpdateCanceled'), showCanvas() };
175 $('holds_submit').onclick = function(){holdsPlaceHold(holdsBuildHoldFromWindow())};
176 $('holds_update').onclick = function(){holdsPlaceHold(holdsBuildHoldFromWindow())};
177 appendClear($('holds_physical_desc'), text(rec.physical_description()));
178 if(type == 'M') hideMe($('hold_physical_desc_row'));
182 function holdsCheckPossibility(recid, type, pickuplib) {
183 var req = new Request(CHECK_HOLD_POSSIBLE, G.user.session,
184 { titleid : recid, patronid : G.user.id(), depth : 0, pickup_lib : pickuplib } );
190 function holdsBuildOrgSelector(node) {
192 if(!node) node = globalOrgTree;
194 var selector = $('holds_org_selector');
195 var index = selector.options.length;
197 var type = findOrgType(node.ou_type());
198 var indent = type.depth() - 1;
199 var opt = setSelectorVal( selector, index, node.name(), node.id(), null, indent );
200 if(!type.can_have_vols()) opt.disabled = true;
202 if( node.id() == holdRecipient.home_ou() ) {
203 selector.selectedIndex = index;
204 selector.options[index].selected = true;
207 for( var i in node.children() ) {
208 var child = node.children()[i];
209 if(child) holdsBuildOrgSelector(child);
213 function holdsBuildHoldFromWindow() {
215 var org = $('holds_org_selector').options[
216 $('holds_org_selector').selectedIndex].value;
218 var hold = new ahr();
225 if( $('holds_enable_phone').checked ) {
226 var phone = $('holds_phone').value;
227 if( !phone || !phone.match(REGEX_PHONE) ) {
228 alert($('holds_bad_phone').innerHTML);
231 hold.phone_notify(phone);
234 hold.phone_notify("");
237 if( $('holds_enable_email').checked )
238 hold.email_notify(1);
240 hold.email_notify(0);
243 hold.pickup_lib(org);
244 hold.request_lib(org);
245 hold.requestor(holdRequestor.id());
246 hold.usr(holdRecipient.id());
248 hold.target(currentHoldRecord);
250 hold.selection_depth(getSelectorVal($('holds_depth_selector')));
254 function holdsPlaceHold(hold) {
258 swapCanvas($('check_holds_box'));
260 if( ! holdsCheckPossibility(currentHoldRecord, currentHoldType, hold.pickup_lib() ) ) {
261 alert($('hold_not_allowed').innerHTML);
266 var req = new Request( CREATE_HOLD, holdRequestor.session, hold );
268 var res = req.result();
270 if( res == '1' ) alert($('holds_success').innerHTML);
271 else alert($('holds_failure').innerHTML);
275 holdRecipient = null;
276 holdRequestor = null;
277 currentHoldRecord = null;
278 currentHoldType = null;
280 runEvt('common', 'holdUpdated');
283 function holdsCancel(holdid, user) {
284 if(!user) user = G.user;
285 var req = new Request(CANCEL_HOLD, user.session, holdid);
288 runEvt('common', 'holdUpdated');
291 function holdsUpdate(hold, user) {
292 if(!user) user = G.user;
293 var req = new Request(UPDATE_HOLD, user.session, hold);
295 var x = req.result(); /* cause an exception if there is one */
296 runEvt('common', 'holdUpdated');