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