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;
21 function _holdsHandleStaff() {
22 var barcode = $('xul_recipient_barcode').value;
23 var user = grabUserByBarcode( G.user.session, barcode );
24 var code = checkILSEvent(user);
26 alertILSEvent(code, barcode);
31 holdsDrawWindow( currentHoldRecord, null );
34 function holdsDrawWindow(recid, type, edithold, done_callback) {
37 recid = currentHoldRecord;
38 if(recid == null) return;
40 currentHoldRecord = recid;
41 holdEditHold = edithold;
42 holdEditCallback = done_callback;
44 if(isXUL() && holdRecipient == null ) {
49 if( holdRecipient == null ) holdRecipient = G.user;
50 if( holdRequestor == null ) holdRequestor = G.user;
52 if(!(holdRequestor && holdRequestor.session)) {
54 detachAllEvt('common','locationChanged');
55 attachEvt('common','loggedIn', holdsDrawWindow)
61 swapCanvas($('check_holds_box'));
64 setTimeout( function() { holdsCheckPossibility(recid, type); }, 10 );
67 _holdsDrawWindow(recid, type);
68 _holdsUpdateEditHold(edithold);
72 function _holdsUpdateEditHold(hold) {
74 if( hold.capture_time() )
75 $('holds_org_selector').disabled = true;
77 setSelector($('holds_org_selector'), hold.pickup_lib());
79 $('holds_submit').onclick = holdsEditHold;
82 if(hold.phone_notify()) {
83 $('holds_enable_phone').checked = true;
84 $('holds_phone').value = hold.phone_notify();
87 $('holds_phone').disabled = true;
88 $('holds_enable_phone').checked = false;
91 if(hold.email_notify()) {
92 $('holds_enable_email').checked = true;
95 $('holds_enable_email').checked = false;
99 function holdsEditHold() {
100 var hold = holdsBuildHoldFromWindow();
101 hold.id( holdEditHold.id() );
104 if(holdEditCallback) holdEditCallback(hold);
108 function _holdsDrawWindow(recid, type) {
110 swapCanvas($('holds_box'));
112 var rec = findRecord( recid, type );
113 currentHoldsRecordObj = rec;
115 if(!holdsOrgSelectorBuilt) {
116 holdsBuildOrgSelector(null,0);
117 holdsOrgSelectorBuilt = true;
120 appendClear($('holds_recipient'), text(
121 holdRecipient.family_name() + ', ' +
122 holdRecipient.first_given_name()));
123 appendClear($('holds_title'), text(rec.title()));
124 appendClear($('holds_author'), text(rec.author()));
126 removeChildren($('holds_format'));
127 for( var i in rec.types_of_resource() ) {
128 var res = rec.types_of_resource()[i];
129 var img = elem("img");
130 setResourcePic(img, res);
131 $('holds_format').appendChild(text(' '+res+' '));
132 $('holds_format').appendChild(img);
133 $('holds_format').appendChild(text(' '));
137 $('holds_phone').value = holdRecipient.day_phone();
138 appendClear( $('holds_email'), text(holdRecipient.email()));
140 var pref = G.user.prefs[PREF_HOLD_NOTIFY];
143 if( ! pref.match(/email/i) )
144 $('holds_enable_email').checked = false;
146 if( ! pref.match(/phone/i) ) {
147 $('holds_phone').disabled = true;
148 $('holds_enable_phone').checked = false;
152 $('holds_cancel').onclick = showCanvas;
153 $('holds_submit').onclick = function(){holdsPlaceHold(holdsBuildHoldFromWindow())};
154 appendClear($('holds_physical_desc'), text(rec.physical_description()));
155 if(type == 'M') hideMe($('hold_physical_desc_row'));
159 function holdsCheckPossibility(recid, type) {
160 var req = new Request(CHECK_HOLD_POSSIBLE, G.user.session,
161 { titleid : recid, patronid : G.user.id(), depth : 0 } );
163 var res = req.result();
165 if(res) _holdsDrawWindow(recid, type);
170 function holdsBuildOrgSelector(node) {
172 if(!node) node = globalOrgTree;
174 var selector = $('holds_org_selector');
175 var index = selector.options.length;
177 var type = findOrgType(node.ou_type());
178 var indent = type.depth() - 1;
179 var opt = setSelectorVal( selector, index, node.name(), node.id(), null, indent );
180 if(!type.can_have_vols()) opt.disabled = true;
182 if( node.id() == holdRecipient.home_ou() ) {
183 selector.selectedIndex = index;
184 selector.options[index].selected = true;
187 for( var i in node.children() ) {
188 var child = node.children()[i];
189 if(child) holdsBuildOrgSelector(child);
193 function holdsBuildHoldFromWindow() {
195 var org = $('holds_org_selector').options[
196 $('holds_org_selector').selectedIndex].value;
198 var hold = new ahr();
201 if( $('holds_enable_phone').checked ) {
202 var phone = $('holds_phone').value;
203 if( !phone.match(REGEX_PHONE) ) {
204 alert($('holds_bad_phone').innerHTML);
207 hold.phone_notify(phone);
210 hold.phone_notify("");
213 if( $('holds_enable_email').checked )
214 hold.email_notify(1);
216 hold.email_notify(0);
219 hold.pickup_lib(org);
220 hold.request_lib(org);
221 hold.requestor(holdRequestor.id());
222 hold.usr(holdRecipient.id());
224 hold.target(currentHoldRecord);
228 function holdsPlaceHold(hold) {
230 var req = new Request( CREATE_HOLD, holdRequestor.session, hold );
232 var res = req.result();
234 if( res == '1' ) alert($('holds_success').innerHTML);
235 else alert($('holds_failure').innerHTML);
238 holdRecipient = null;
239 holdRequestor = null;
242 function holdsCancel(holdid, user) {
243 if(!user) user = G.user;
244 var req = new Request(CANCEL_HOLD, user.session, holdid);
249 function holdsUpdate(hold, user) {
250 if(!user) user = G.user;
251 var req = new Request(UPDATE_HOLD, user.session, hold);
253 var x = req.result(); /* cause an exception if there is one */