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 ) {
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() );
110 if(holdEditCallback) holdEditCallback(hold);
114 function _holdsDrawWindow(recid, type) {
116 swapCanvas($('holds_box'));
118 var rec = findRecord( recid, type );
119 currentHoldsRecordObj = rec;
121 if(!holdsOrgSelectorBuilt) {
122 holdsBuildOrgSelector(null,0);
123 holdsOrgSelectorBuilt = true;
127 var dsel = $('holds_depth_selector');
128 unHideMe($('holds_depth_selector_row'));
129 if(dsel.getElementsByTagName('option').length == 0) {
130 var types = globalOrgTypes;
131 var depth = findOrgDepth(G.user.ws_ou());
134 if(t.depth() > depth) return;
135 insertSelectorVal(dsel, -1, t.opac_label(), t.depth());
141 appendClear($('holds_recipient'), text(
142 holdRecipient.family_name() + ', ' +
143 holdRecipient.first_given_name()));
144 appendClear($('holds_title'), text(rec.title()));
145 appendClear($('holds_author'), text(rec.author()));
147 removeChildren($('holds_format'));
148 for( var i in rec.types_of_resource() ) {
149 var res = rec.types_of_resource()[i];
150 var img = elem("img");
151 setResourcePic(img, res);
152 $('holds_format').appendChild(text(' '+res+' '));
153 $('holds_format').appendChild(img);
154 $('holds_format').appendChild(text(' '));
158 $('holds_phone').value = holdRecipient.day_phone();
159 appendClear( $('holds_email'), text(holdRecipient.email()));
161 var pref = G.user.prefs[PREF_HOLD_NOTIFY];
164 if( ! pref.match(/email/i) )
165 $('holds_enable_email').checked = false;
167 if( ! pref.match(/phone/i) ) {
168 $('holds_phone').disabled = true;
169 $('holds_enable_phone').checked = false;
173 $('holds_cancel').onclick = function(){ runEvt('common', 'holdUpdateCanceled'), showCanvas() };
174 $('holds_submit').onclick = function(){holdsPlaceHold(holdsBuildHoldFromWindow())};
175 $('holds_update').onclick = function(){holdsPlaceHold(holdsBuildHoldFromWindow())};
176 appendClear($('holds_physical_desc'), text(rec.physical_description()));
177 if(type == 'M') hideMe($('hold_physical_desc_row'));
181 function holdsCheckPossibility(recid, type, pickuplib) {
182 var req = new Request(CHECK_HOLD_POSSIBLE, G.user.session,
183 { titleid : recid, patronid : G.user.id(), depth : 0, pickup_lib : pickuplib } );
189 function holdsBuildOrgSelector(node) {
191 if(!node) node = globalOrgTree;
193 var selector = $('holds_org_selector');
194 var index = selector.options.length;
196 var type = findOrgType(node.ou_type());
197 var indent = type.depth() - 1;
198 var opt = setSelectorVal( selector, index, node.name(), node.id(), null, indent );
199 if(!type.can_have_vols()) opt.disabled = true;
201 if( node.id() == holdRecipient.home_ou() ) {
202 selector.selectedIndex = index;
203 selector.options[index].selected = true;
206 for( var i in node.children() ) {
207 var child = node.children()[i];
208 if(child) holdsBuildOrgSelector(child);
212 function holdsBuildHoldFromWindow() {
214 var org = $('holds_org_selector').options[
215 $('holds_org_selector').selectedIndex].value;
217 var hold = new ahr();
224 if( $('holds_enable_phone').checked ) {
225 var phone = $('holds_phone').value;
226 if( !phone.match(REGEX_PHONE) ) {
227 alert($('holds_bad_phone').innerHTML);
230 hold.phone_notify(phone);
233 hold.phone_notify("");
236 if( $('holds_enable_email').checked )
237 hold.email_notify(1);
239 hold.email_notify(0);
242 hold.pickup_lib(org);
243 hold.request_lib(org);
244 hold.requestor(holdRequestor.id());
245 hold.usr(holdRecipient.id());
247 hold.target(currentHoldRecord);
249 hold.selection_depth(getSelectorVal($('holds_depth_selector')));
253 function holdsPlaceHold(hold) {
255 swapCanvas($('check_holds_box'));
256 alert(currentHoldRecord + ' : ' + hold.pickup_lib() );
258 if( ! holdsCheckPossibility(currentHoldRecord, currentHoldType, hold.pickup_lib() ) ) {
259 alert($('hold_not_allowed').innerHTML);
264 var req = new Request( CREATE_HOLD, holdRequestor.session, hold );
266 var res = req.result();
268 if( res == '1' ) alert($('holds_success').innerHTML);
269 else alert($('holds_failure').innerHTML);
273 holdRecipient = null;
274 holdRequestor = null;
275 currentHoldRecord = null;
276 currentHoldType = null;
278 runEvt('common', 'holdUpdated');
281 function holdsCancel(holdid, user) {
282 if(!user) user = G.user;
283 var req = new Request(CANCEL_HOLD, user.session, holdid);
286 runEvt('common', 'holdUpdated');
289 function holdsUpdate(hold, user) {
290 if(!user) user = G.user;
291 var req = new Request(UPDATE_HOLD, user.session, hold);
293 var x = req.result(); /* cause an exception if there is one */
294 runEvt('common', 'holdUpdated');