]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/js/ui/default/opac/staff.js
6e2cbda6e949a42c3b829f2e2fbfb2ff5e55904d
[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 == '' || barcode == cur_hold_barcode)
44             return;
45         var load_info = xulG.get_barcode_and_settings(window, barcode, only_settings);
46         if(load_info == false || load_info == undefined)
47             return;
48         cur_hold_barcode = load_info.barcode;
49         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
50         if(load_info.settings['opac.default_pickup_location'])
51             document.getElementById('pickup_lib').value = load_info.settings['opac.default_pickup_location'];
52         if(!load_info.settings['opac.default_phone']) load_info.settings['opac.default_phone'] = '';
53         if(!load_info.settings['opac.default_sms_notify']) load_info.settings['opac.default_sms_notify'] = '';
54         if(!load_info.settings['opac.default_sms_carrier']) load_info.settings['opac.default_sms_carrier'] = '';
55         if(load_info.settings['opac.hold_notify'] || load_info.settings['opac.hold_notify'] === '') {
56             var email = load_info.settings['opac.hold_notify'].indexOf('email') > -1;
57             var phone = load_info.settings['opac.hold_notify'].indexOf('phone') > -1;
58             var sms = load_info.settings['opac.hold_notify'].indexOf('sms') > -1;
59             var update_elements = document.getElementsByName('email_notify');
60             for(var i in update_elements) update_elements[i].checked = (email ? 'checked' : '');
61             update_elements = document.getElementsByName('phone_notify_checkbox');
62             for(var i in update_elements) update_elements[i].checked = (phone ? 'checked' : '');
63             update_elements = document.getElementsByName('sms_notify_checkbox');
64             for(var i in update_elements) update_elements[i].checked = (sms ? 'checked' : '');
65         }
66         update_elements = document.getElementsByName('phone_notify');
67         for(var i in update_elements) update_elements[i].value = load_info.settings['opac.default_phone'];
68         update_elements = document.getElementsByName('sms_notify');
69         for(var i in update_elements) update_elements[i].value = load_info.settings['opac.default_sms_notify'];
70         update_elements = document.getElementsByName('sms_carrier');
71         for(var i in update_elements) update_elements[i].value = load_info.settings['opac.default_sms_carrier'];
72         update_elements = document.getElementsByName('email_notify');
73         for(var i in update_elements) {
74             update_elements[i].disabled = (load_info.user_email ? false : true);
75             if(update_elements[i].disabled) update_elements[i].checked = false;
76         }
77         update_elements = document.getElementsByName('email_address');
78         for(var i in update_elements) update_elements[i].textContent = load_info.user_email;
79     }
80 }
81 window.onload = function() {
82     // record details page events
83     var rec = location.href.match(/\/opac\/record\/(\d+)/);
84     if(rec && rec[1]) { 
85         runEvt('rdetail', 'recordRetrieved', rec[1]); 
86         runEvt('rdetail', 'MFHDDrawn');
87     }
88     if(location.href.match(/place_hold/)) {
89         if(xulG.patron_barcode) {
90             staff_hold_usr_barcode_changed(xulG.patron_barcode);
91         } else {
92             staff_hold_usr_barcode_changed(true);
93         }
94     }
95 }
96
97 function rdetail_next_prev_actions(index, count, prev, next, start, end, results) {
98     /*  we mostly get the relative URL from the template:  recid?query_args...
99         replace the recid and args on location.href to get the new URL  */
100     function fullurl(url) {
101         if (url.match(/eg\/opac\/results/)) {
102             return location.href.replace(/eg\/opac\/.+$/, url);
103         } else {
104             return location.href.replace(/\/\d+\??.*/, '/' + url);
105         }
106     }
107
108     if (index > 0) {
109         if(prev) 
110             window.rdetailPrev = function() { location.href = fullurl(prev); }
111         if(start) 
112             window.rdetailStart = function() { location.href = fullurl(start); }
113     }
114
115     if (index < count - 1) {
116         if(next) 
117             window.rdetailNext = function() { location.href = fullurl(next); }
118         if(end) 
119             window.rdetailEnd = function() { location.href = fullurl(end); }
120     }
121
122     window.rdetailBackToResults = function() { location.href = fullurl(results); };
123
124     ol = window.onload;
125     window.onload = function() {
126         if(ol) ol(); 
127         runEvt('rdetail', 'nextPrevDrawn', Number(index), Number(count)); 
128     };
129 }