1 /* staff client integration functions */
3 // Browser staff client runs the TPAC within an iframe, whose onload
4 // is not called until after the page onload is called. window.onload
5 // actions are wrapped in timeouts (below) to ensure the wrapping page
6 // has a chance to insert the necessary xulG, etc. functions into the
9 function debug(msg){dump(msg+'\n')}
11 function attachEvt(scope, name, action) {
12 if(!eventCache[scope]) eventCache[scope] = {};
13 if(!eventCache[scope][name]) eventCache[scope][name] = [];
14 eventCache[scope][name].push(action);
16 function runEvt(scope, name) {
17 debug('running event '+scope+':'+name);
18 var args = Array.prototype.slice.call(arguments).slice(2);
19 if(eventCache[scope]) {
20 var evt = eventCache[scope][name];
21 for(var i in evt) {evt[i].apply(evt[i], args);}
24 function staff_hold_usr_input_disabler(input) {
25 document.getElementById("hold_usr_input").disabled =
26 Boolean(Number(input.value));
27 staff_hold_usr_barcode_changed();
29 function no_hold_submit(event) {
30 if (event.which == 13) {
31 staff_hold_usr_barcode_changed();
36 function staff_hold_usr_barcode_changed(isload) {
38 if (!document.getElementById('place_hold_submit')) {
39 // in some cases, the submit button is not present.
40 // exit early to avoid needless JS errors
44 if (!window.xulG) return;
46 var adv_link = document.getElementById('advanced_hold_link');
48 adv_link.setAttribute('href', adv_link.getAttribute('href').replace(/&?is_requestor=[01]/,''));
49 var is_requestor = document.getElementById('hold_usr_is_requestor').checked ? 1 : 0;
50 adv_link.setAttribute('href', adv_link.getAttribute('href') + '&is_requestor=' + is_requestor.toString());
53 var cur_hold_barcode = undefined;
55 if(!barcode || barcode === true) barcode = document.getElementById('staff_barcode').value;
56 var only_settings = true;
57 if(!document.getElementById('hold_usr_is_requestor').checked) {
59 barcode = document.getElementById('hold_usr_input').value;
60 only_settings = false;
62 if(barcode && barcode != '' && !document.getElementById('hold_usr_is_requestor_not').checked)
63 document.getElementById('hold_usr_is_requestor_not').checked = 'checked';
65 if(barcode == undefined || barcode == '') {
66 document.getElementById('patron_name').innerHTML = '';
67 // No submitting on empty barcode, but empty barcode doesn't really count as "not found" either
68 document.getElementById('place_hold_submit').disabled = true;
69 document.getElementById("patron_usr_barcode_not_found").style.display = 'none';
70 cur_hold_barcode = null;
73 if(barcode == cur_hold_barcode)
75 // No submitting until we think the barcode is valid
76 document.getElementById('place_hold_submit').disabled = true;
78 if (window.IAMBROWSER) {
79 // Browser client operates asynchronously
80 if (!xulG.get_barcode_and_settings_async) return;
81 xulG.get_barcode_and_settings_async(barcode, only_settings)
83 function(load_info) { // load succeeded
84 staff_hold_usr_barcode_changed2(
85 isload, only_settings, barcode, cur_hold_barcode, load_info);
88 // load failed (rejected). Call staff_hold_usr_barcode_changed2
89 // anyway, since it handles clearing the form
90 staff_hold_usr_barcode_changed2(
91 isload, only_settings, barcode, cur_hold_barcode, false);
95 // XUL version is synchronous
96 if (!xulG.get_barcode_and_settings) return;
97 var load_info = xulG.get_barcode_and_settings(window, barcode, only_settings);
98 staff_hold_usr_barcode_changed2(isload, only_settings, barcode, cur_hold_barcode, load_info);
102 function staff_hold_usr_barcode_changed2(
103 isload, only_settings, barcode, cur_hold_barcode, load_info) {
105 if(load_info == false || load_info == undefined) {
106 document.getElementById('patron_name').innerHTML = '';
107 document.getElementById("patron_usr_barcode_not_found").style.display = '';
108 cur_hold_barcode = null;
111 cur_hold_barcode = load_info.barcode;
112 if(!only_settings || (isload && isload !== true)) document.getElementById('hold_usr_input').value = load_info.barcode; // Safe at this point as we already set cur_hold_barcode
113 if(!only_settings || (isload && isload !== true) && load_info.pickup_lib) document.getElementById('pickup_lib').value = load_info.pickup_lib; // Safe at this point as we already set cur_hold_barcode
114 if(load_info.settings['opac.default_pickup_location'])
115 document.getElementById('pickup_lib').value = load_info.settings['opac.default_pickup_location'];
116 if(!load_info.settings['opac.default_phone']) load_info.settings['opac.default_phone'] = '';
117 if(!load_info.settings['opac.default_sms_notify']) load_info.settings['opac.default_sms_notify'] = '';
118 if(!load_info.settings['opac.default_sms_carrier']) load_info.settings['opac.default_sms_carrier'] = '';
119 if(load_info.settings['opac.hold_notify'] || load_info.settings['opac.hold_notify'] === '') {
120 var email = load_info.settings['opac.hold_notify'].indexOf('email') > -1;
121 var phone = load_info.settings['opac.hold_notify'].indexOf('phone') > -1;
122 var sms = load_info.settings['opac.hold_notify'].indexOf('sms') > -1;
123 var update_elements = document.getElementsByName('email_notify');
124 for(var i in update_elements) update_elements[i].checked = (email ? 'checked' : '');
125 update_elements = document.getElementsByName('phone_notify_checkbox');
126 for(var i in update_elements) update_elements[i].checked = (phone ? 'checked' : '');
127 update_elements = document.getElementsByName('sms_notify_checkbox');
128 for(var i in update_elements) update_elements[i].checked = (sms ? 'checked' : '');
130 update_elements = document.getElementsByName('phone_notify');
131 for(var i in update_elements) update_elements[i].value = load_info.settings['opac.default_phone'];
132 update_elements = document.getElementsByName('sms_notify');
133 for(var i in update_elements) update_elements[i].value = load_info.settings['opac.default_sms_notify'];
134 update_elements = document.getElementsByName('sms_carrier');
135 for(var i in update_elements) update_elements[i].value = load_info.settings['opac.default_sms_carrier'];
136 update_elements = document.getElementsByName('email_notify');
137 for(var i in update_elements) {
138 update_elements[i].disabled = (load_info.user_email ? false : true);
139 if(update_elements[i].disabled) update_elements[i].checked = false;
141 update_elements = document.getElementsByName('email_address');
142 for(var i in update_elements) update_elements[i].textContent = load_info.user_email;
143 if(!document.getElementById('hold_usr_is_requestor').checked && document.getElementById('hold_usr_input').value) {
144 document.getElementById('patron_name').innerHTML = load_info.patron_name;
145 document.getElementById("patron_usr_barcode_not_found").style.display = 'none';
147 // Ok, now we can allow submitting again, unless this is a "true" load, in which case we likely have a blank barcode box active
149 // update the advanced hold options link to propagate the patron
150 // barcode if clicked. This is needed when the patron barcode
151 // is manually entered (i.e. the staff client does not provide one).
152 var adv_link = document.getElementById('advanced_hold_link');
153 if (adv_link) { // not present on MR hold pages
154 var href = adv_link.getAttribute('href').replace(
155 /;usr_barcode=[^;\&]+|$/,
156 ';usr_barcode=' + encodeURIComponent(cur_hold_barcode));
157 adv_link.setAttribute('href', href);
161 document.getElementById('place_hold_submit').disabled = false;
163 window.onload = function() {
164 // record details page events
166 setTimeout(function() {
168 if (location.href.match(/is_requestor=[01]/)) {
169 var loc = location.href;
170 var is_req_match = new RegExp("is_requestor=[01]");
171 var is_req = is_req_match.exec(loc).toString();
172 is_req = is_req.replace(/is_requestor=/, '');
174 document.getElementById('hold_usr_is_requestor').checked = 'checked';
175 document.getElementById('hold_usr_input').disabled = true;
177 document.getElementById('hold_usr_is_requestor_not').checked = 'checked';
178 document.getElementById('hold_usr_input').disabled = false;
182 var rec = location.href.match(/\/opac\/record\/(\d+)/);
184 runEvt('rdetail', 'recordRetrieved', rec[1]);
185 runEvt('rdetail', 'MFHDDrawn');
187 if(location.href.match(/place_hold/)) {
188 // patron barcode may come from XUL or a CGI param
189 var patron_barcode = xulG.patron_barcode ||
190 document.getElementById('hold_usr_input').value;
192 staff_hold_usr_barcode_changed(patron_barcode);
194 staff_hold_usr_barcode_changed(true);
200 function rdetail_next_prev_actions(index, count, prev, next, start, end, results) {
201 /* we mostly get the relative URL from the template: recid?query_args...
202 replace the recid and args on location.href to get the new URL */
203 function fullurl(url) {
204 if (url.match(/eg\/opac\/results/)) {
205 return location.href.replace(/\/eg\/opac\/.+$/, url);
207 return location.href.replace(/\/\d+\??.*/, '/' + url);
213 window.rdetailPrev = function() { location.href = fullurl(prev); }
215 window.rdetailStart = function() { location.href = fullurl(start); }
218 if (index < count - 1) {
220 window.rdetailNext = function() { location.href = fullurl(next); }
222 window.rdetailEnd = function() { location.href = fullurl(end); }
225 window.rdetailBackToResults = function() { location.href = fullurl(results); };
228 window.onload = function() {
230 setTimeout(function() {
231 runEvt('rdetail', 'nextPrevDrawn', Number(index), Number(count));