]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/opac/staff.js
e5db0087b4e36b380545834471d12df1f52b6b9d
[working/Evergreen.git] / Open-ILS / web / js / ui / default / opac / staff.js
1 /* staff client integration functions */
2 function debug(msg){dump(msg+'\n')}
3 var eventCache={};
4 function attachEvt(scope, name, action) {
5     if(!eventCache[scope]) eventCache[scope] = {};
6     if(!eventCache[scope][name]) eventCache[scope][name] = [];
7     eventCache[scope][name].push(action);
8 }
9 function runEvt(scope, name) {
10     debug('running event '+scope+':'+name);
11     var args = Array.prototype.slice.call(arguments).slice(2);
12     if(eventCache[scope]) {
13         var evt = eventCache[scope][name];
14         for(var i in evt) {evt[i].apply(evt[i], args);}
15     } 
16 }
17 function staff_hold_usr_input_disabler(input) {
18     document.getElementById("hold_usr_input").disabled =
19         Boolean(Number(input.value));
20     staff_hold_usr_barcode_changed();
21 }
22 function no_hold_submit(event) {
23     if (event.which == 13) {
24         staff_hold_usr_barcode_changed();
25         return false;
26     }
27     return true;
28 }
29 var cur_hold_barcode = undefined;
30 function staff_hold_usr_barcode_changed(isload) {
31     if(typeof xulG != 'undefined' && xulG.get_barcode_and_settings) {
32         var barcode = isload;
33         if(!barcode || barcode === true) barcode = document.getElementById('staff_barcode').value;
34         var only_settings = true;
35         if(!document.getElementById('hold_usr_is_requestor').checked) {
36             if(!isload) {
37                 barcode = document.getElementById('hold_usr_input').value;
38                 only_settings = false;
39             }
40             if(barcode && barcode != '' && !document.getElementById('hold_usr_is_requestor_not').checked)
41                 document.getElementById('hold_usr_is_requestor_not').checked = 'checked';
42         }
43         if(barcode == undefined || barcode == '') {
44             document.getElementById('patron_name').innerHTML = '';
45             // No submitting on empty barcode, but empty barcode doesn't really count as "not found" either
46             document.getElementById('place_hold_submit').disabled = true;
47             document.getElementById("patron_usr_barcode_not_found").style.display = 'none';
48             cur_hold_barcode = null;
49             return;
50         }
51         if(barcode == cur_hold_barcode)
52             return;
53         // No submitting until we think the barcode is valid
54         document.getElementById('place_hold_submit').disabled = true;
55         var load_info = xulG.get_barcode_and_settings(window, barcode, only_settings);
56         if(load_info == false || load_info == undefined) {
57             document.getElementById('patron_name').innerHTML = '';
58             document.getElementById("patron_usr_barcode_not_found").style.display = '';
59             cur_hold_barcode = null;
60             return;
61         }
62         cur_hold_barcode = load_info.barcode;
63         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
64         if(load_info.settings['opac.default_pickup_location'])
65             document.getElementById('pickup_lib').value = load_info.settings['opac.default_pickup_location'];
66         if(!load_info.settings['opac.default_phone']) load_info.settings['opac.default_phone'] = '';
67         if(!load_info.settings['opac.default_sms_notify']) load_info.settings['opac.default_sms_notify'] = '';
68         if(!load_info.settings['opac.default_sms_carrier']) load_info.settings['opac.default_sms_carrier'] = '';
69         if(load_info.settings['opac.hold_notify'] || load_info.settings['opac.hold_notify'] === '') {
70             var email = load_info.settings['opac.hold_notify'].indexOf('email') > -1;
71             var phone = load_info.settings['opac.hold_notify'].indexOf('phone') > -1;
72             var sms = load_info.settings['opac.hold_notify'].indexOf('sms') > -1;
73             var update_elements = document.getElementsByName('email_notify');
74             for(var i in update_elements) update_elements[i].checked = (email ? 'checked' : '');
75             update_elements = document.getElementsByName('phone_notify_checkbox');
76             for(var i in update_elements) update_elements[i].checked = (phone ? 'checked' : '');
77             update_elements = document.getElementsByName('sms_notify_checkbox');
78             for(var i in update_elements) update_elements[i].checked = (sms ? 'checked' : '');
79         }
80         update_elements = document.getElementsByName('phone_notify');
81         for(var i in update_elements) update_elements[i].value = load_info.settings['opac.default_phone'];
82         update_elements = document.getElementsByName('sms_notify');
83         for(var i in update_elements) update_elements[i].value = load_info.settings['opac.default_sms_notify'];
84         update_elements = document.getElementsByName('sms_carrier');
85         for(var i in update_elements) update_elements[i].value = load_info.settings['opac.default_sms_carrier'];
86         update_elements = document.getElementsByName('email_notify');
87         for(var i in update_elements) {
88             update_elements[i].disabled = (load_info.user_email ? false : true);
89             if(update_elements[i].disabled) update_elements[i].checked = false;
90         }
91         update_elements = document.getElementsByName('email_address');
92         for(var i in update_elements) update_elements[i].textContent = load_info.user_email;
93         if(!document.getElementById('hold_usr_is_requestor').checked && document.getElementById('hold_usr_input').value) {
94             document.getElementById('patron_name').innerHTML = load_info.patron_name;
95             document.getElementById("patron_usr_barcode_not_found").style.display = 'none';
96         }
97         // Ok, now we can allow submitting again, unless this is a "true" load, in which case we likely have a blank barcode box active
98         if (isload !== true)
99             document.getElementById('place_hold_submit').disabled = false;
100     }
101 }
102 window.onload = function() {
103     // record details page events
104     var rec = location.href.match(/\/opac\/record\/(\d+)/);
105     if(rec && rec[1]) { 
106         runEvt('rdetail', 'recordRetrieved', rec[1]); 
107         runEvt('rdetail', 'MFHDDrawn');
108     }
109     if(location.href.match(/place_hold/)) {
110         if(xulG.patron_barcode) {
111             staff_hold_usr_barcode_changed(xulG.patron_barcode);
112         } else {
113             staff_hold_usr_barcode_changed(true);
114         }
115     }
116 }
117
118 function rdetail_next_prev_actions(index, count, prev, next, start, end, results) {
119     /*  we mostly get the relative URL from the template:  recid?query_args...
120         replace the recid and args on location.href to get the new URL  */
121     function fullurl(url) {
122         if (url.match(/eg\/opac\/results/)) {
123             return location.href.replace(/\/eg\/opac\/.+$/, url);
124         } else {
125             return location.href.replace(/\/\d+\??.*/, '/' + url);
126         }
127     }
128
129     if (index > 0) {
130         if(prev) 
131             window.rdetailPrev = function() { location.href = fullurl(prev); }
132         if(start) 
133             window.rdetailStart = function() { location.href = fullurl(start); }
134     }
135
136     if (index < count - 1) {
137         if(next) 
138             window.rdetailNext = function() { location.href = fullurl(next); }
139         if(end) 
140             window.rdetailEnd = function() { location.href = fullurl(end); }
141     }
142
143     window.rdetailBackToResults = function() { location.href = fullurl(results); };
144
145     ol = window.onload;
146     window.onload = function() {
147         if(ol) ol(); 
148         runEvt('rdetail', 'nextPrevDrawn', Number(index), Number(count)); 
149     };
150 }