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'));
74 var req = new Request(FETCH_HOLD_STATUS, G.user.session, edithold.id() );
76 status = req.result();
78 _holdsUpdateEditHold(edithold, status);
82 function _holdsUpdateEditHold(hold, status) {
84 if( hold.capture_time() )
85 $('holds_org_selector').disabled = true;
87 setSelector($('holds_org_selector'), hold.pickup_lib());
89 if( status > 3 ) $('holds_org_selector').disabled = true;
91 $('holds_submit').onclick = holdsEditHold;
92 $('holds_update').onclick = holdsEditHold;
95 if(hold.phone_notify()) {
96 $('holds_enable_phone').checked = true;
97 $('holds_phone').value = hold.phone_notify();
100 $('holds_phone').disabled = true;
101 $('holds_enable_phone').checked = false;
104 if(hold.email_notify()) {
105 $('holds_enable_email').checked = true;
108 $('holds_enable_email').checked = false;
112 function holdsEditHold() {
113 var hold = holdsBuildHoldFromWindow();
114 //hold.id( holdEditHold.id() );
118 if(holdEditCallback) holdEditCallback(hold);
122 function _holdsDrawWindow(recid, type) {
124 swapCanvas($('holds_box'));
126 var rec = findRecord( recid, type );
127 currentHoldsRecordObj = rec;
129 if(!holdsOrgSelectorBuilt) {
130 holdsBuildOrgSelector(null,0);
131 holdsOrgSelectorBuilt = true;
135 var dsel = $('holds_depth_selector');
136 unHideMe($('holds_depth_selector_row'));
137 if(dsel.getElementsByTagName('option').length == 0) {
138 var types = globalOrgTypes;
139 var depth = findOrgDepth(G.user.ws_ou());
142 if(t.depth() > depth) return;
143 insertSelectorVal(dsel, -1, t.opac_label(), t.depth());
149 appendClear($('holds_recipient'), text(
150 holdRecipient.family_name() + ', ' +
151 holdRecipient.first_given_name()));
152 appendClear($('holds_title'), text(rec.title()));
153 appendClear($('holds_author'), text(rec.author()));
155 removeChildren($('holds_format'));
156 for( var i in rec.types_of_resource() ) {
157 var res = rec.types_of_resource()[i];
158 var img = elem("img");
159 setResourcePic(img, res);
160 $('holds_format').appendChild(text(' '+res+' '));
161 $('holds_format').appendChild(img);
162 $('holds_format').appendChild(text(' '));
166 $('holds_phone').value = holdRecipient.day_phone();
167 appendClear( $('holds_email'), text(holdRecipient.email()));
169 var pref = G.user.prefs[PREF_HOLD_NOTIFY];
172 if( ! pref.match(/email/i) )
173 $('holds_enable_email').checked = false;
175 if( ! pref.match(/phone/i) ) {
176 $('holds_phone').disabled = true;
177 $('holds_enable_phone').checked = false;
181 $('holds_cancel').onclick = function(){ runEvt('common', 'holdUpdateCanceled'), showCanvas() };
182 $('holds_submit').onclick = function(){holdsPlaceHold(holdsBuildHoldFromWindow())};
183 $('holds_update').onclick = function(){holdsPlaceHold(holdsBuildHoldFromWindow())};
184 appendClear($('holds_physical_desc'), text(rec.physical_description()));
185 if(type == 'M') hideMe($('hold_physical_desc_row'));
189 function holdsCheckPossibility(recid, type, pickuplib) {
190 var req = new Request(CHECK_HOLD_POSSIBLE, G.user.session,
191 { titleid : recid, patronid : G.user.id(), depth : 0, pickup_lib : pickuplib } );
197 function holdsBuildOrgSelector(node) {
199 if(!node) node = globalOrgTree;
201 var selector = $('holds_org_selector');
202 var index = selector.options.length;
204 var type = findOrgType(node.ou_type());
205 var indent = type.depth() - 1;
206 var opt = setSelectorVal( selector, index, node.name(), node.id(), null, indent );
207 if(!type.can_have_vols()) opt.disabled = true;
209 if( node.id() == holdRecipient.home_ou() ) {
210 selector.selectedIndex = index;
211 selector.options[index].selected = true;
214 for( var i in node.children() ) {
215 var child = node.children()[i];
216 if(child) holdsBuildOrgSelector(child);
220 function holdsBuildHoldFromWindow() {
222 var org = $('holds_org_selector').options[
223 $('holds_org_selector').selectedIndex].value;
225 var hold = new ahr();
232 if( $('holds_enable_phone').checked ) {
233 var phone = $('holds_phone').value;
234 if( !phone || !phone.match(REGEX_PHONE) ) {
235 alert($('holds_bad_phone').innerHTML);
238 hold.phone_notify(phone);
241 hold.phone_notify("");
244 if( $('holds_enable_email').checked )
245 hold.email_notify(1);
247 hold.email_notify(0);
250 hold.pickup_lib(org);
251 hold.request_lib(org);
252 hold.requestor(holdRequestor.id());
253 hold.usr(holdRecipient.id());
255 hold.target(currentHoldRecord);
257 hold.selection_depth(getSelectorVal($('holds_depth_selector')));
261 function holdsPlaceHold(hold) {
265 swapCanvas($('check_holds_box'));
267 if( ! holdsCheckPossibility(currentHoldRecord, currentHoldType, hold.pickup_lib() ) ) {
268 alert($('hold_not_allowed').innerHTML);
273 var req = new Request( CREATE_HOLD, holdRequestor.session, hold );
275 var res = req.result();
277 if( res == '1' ) alert($('holds_success').innerHTML);
278 else alert($('holds_failure').innerHTML);
282 holdRecipient = null;
283 holdRequestor = null;
284 currentHoldRecord = null;
285 currentHoldType = null;
287 runEvt('common', 'holdUpdated');
290 function holdsCancel(holdid, user) {
291 if(!user) user = G.user;
292 var req = new Request(CANCEL_HOLD, user.session, holdid);
295 runEvt('common', 'holdUpdated');
298 function holdsUpdate(hold, user) {
299 if(!user) user = G.user;
300 var req = new Request(UPDATE_HOLD, user.session, hold);
302 var x = req.result(); /* cause an exception if there is one */
303 runEvt('common', 'holdUpdated');