]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/opac/staff.js
Merge branch 'new_toolbar_icons'
[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 var cur_hold_barcode = undefined;
23 function staff_hold_usr_barcode_changed(isload) {
24     if(typeof xulG != 'undefined' && xulG.get_barcode_and_settings) {
25         var barcode = document.getElementById('staff_barcode').value;
26         var only_settings = true;
27         if(!document.getElementById('hold_usr_is_requestor').checked) {
28             barcode = document.getElementById('hold_usr_input').value;
29             if(!isload)
30                 only_settings = false;
31             if(barcode && barcode != '' && !document.getElementById('hold_usr_is_requestor_not').checked)
32                 document.getElementById('hold_usr_is_requestor_not').checked = 'checked';
33         }
34         if(barcode == undefined || barcode == '' || barcode == cur_hold_barcode)
35             return;
36         var load_info = xulG.get_barcode_and_settings(window, barcode, only_settings);
37         if(load_info == false || load_info == undefined)
38             return;
39         cur_hold_barcode = load_info.barcode;
40         if(!only_settings) document.getElementById('hold_usr_input').value = load_info.barcode; // Safe at this point as we already set cur_hold_barcode
41         if(load_info.settings['opac.default_pickup_location'])
42             document.getElementById('pickup_lib').value = load_info.settings['opac.default_pickup_location'];
43         if(!load_info.settings['opac.default_phone']) load_info.settings['opac.default_phone'] = '';
44         if(!load_info.settings['opac.default_sms_notify']) load_info.settings['opac.default_sms_notify'] = '';
45         if(!load_info.settings['opac.default_sms_carrier']) load_info.settings['opac.default_sms_carrier'] = '';
46         if(load_info.settings['opac.hold_notify']) {
47             var email = load_info.settings['opac.hold_notify'].indexOf('email') > -1;
48             var phone = load_info.settings['opac.hold_notify'].indexOf('phone') > -1;
49             var sms = load_info.settings['opac.hold_notify'].indexOf('sms') > -1;
50             var update_elements = document.getElementsByName('email_notify');
51             for(var i in update_elements) update_elements[i].checked = (email ? 'checked' : '');
52             update_elements = document.getElementsByName('phone_notify_checkbox');
53             for(var i in update_elements) update_elements[i].checked = (phone ? 'checked' : '');
54             update_elements = document.getElementsByName('sms_notify_checkbox');
55             for(var i in update_elements) update_elements[i].checked = (sms ? 'checked' : '');
56         }
57         update_elements = document.getElementsByName('phone_notify');
58         for(var i in update_elements) update_elements[i].value = load_info.settings['opac.default_phone'];
59         update_elements = document.getElementsByName('sms_notify');
60         for(var i in update_elements) update_elements[i].value = load_info.settings['opac.default_sms_notify'];
61         update_elements = document.getElementsByName('sms_carrier');
62         for(var i in update_elements) update_elements[i].value = load_info.settings['opac.default_sms_carrier'];
63     }
64 }
65 window.onload = function() {
66     // record details page events
67     var rec = location.href.match(/\/opac\/record\/(\d+)/);
68     if(rec && rec[1]) { 
69         runEvt('rdetail', 'recordRetrieved', rec[1]); 
70         runEvt('rdetail', 'MFHDDrawn');
71     }
72     if(location.href.match(/place_hold/)) {
73         staff_hold_usr_barcode_changed(true);
74     }
75 }
76
77 function rdetail_next_prev_actions(index, count, prev, next, start, end, results) {
78     /*  we mostly get the relative URL from the template:  recid?query_args...
79         replace the recid and args on location.href to get the new URL  */
80     function fullurl(url) {
81         if (url.match(/eg\/opac\/results/)) {
82             return location.href.replace(/eg\/opac\/.+$/, url);
83         } else {
84             return location.href.replace(/\/\d+\??.*/, '/' + url);
85         }
86     }
87
88     if (index > 0) {
89         if(prev) 
90             window.rdetailPrev = function() { location.href = fullurl(prev); }
91         if(start) 
92             window.rdetailStart = function() { location.href = fullurl(start); }
93     }
94
95     if (index < count - 1) {
96         if(next) 
97             window.rdetailNext = function() { location.href = fullurl(next); }
98         if(end) 
99             window.rdetailEnd = function() { location.href = fullurl(end); }
100     }
101
102     window.rdetailBackToResults = function() { location.href = fullurl(results); };
103
104     ol = window.onload;
105     window.onload = function() {
106         if(ol) ol(); 
107         runEvt('rdetail', 'nextPrevDrawn', Number(index), Number(count)); 
108     };
109 }