]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/opac/staff.js
TPac: Disable staff hold place submit button by default
[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             cur_hold_barcode = null;
46             return;
47         }
48         if(barcode == cur_hold_barcode)
49             return;
50         // No submitting until we think the barcode is valid
51         document.getElementById('place_hold_submit').disabled = true;
52         var load_info = xulG.get_barcode_and_settings(window, barcode, only_settings);
53         if(load_info == false || load_info == undefined) {
54             document.getElementById('patron_name').innerHTML = '';
55             cur_hold_barcode = null;
56             return;
57         }
58         cur_hold_barcode = load_info.barcode;
59         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
60         if(load_info.settings['opac.default_pickup_location'])
61             document.getElementById('pickup_lib').value = load_info.settings['opac.default_pickup_location'];
62         if(!load_info.settings['opac.default_phone']) load_info.settings['opac.default_phone'] = '';
63         if(!load_info.settings['opac.default_sms_notify']) load_info.settings['opac.default_sms_notify'] = '';
64         if(!load_info.settings['opac.default_sms_carrier']) load_info.settings['opac.default_sms_carrier'] = '';
65         if(load_info.settings['opac.hold_notify'] || load_info.settings['opac.hold_notify'] === '') {
66             var email = load_info.settings['opac.hold_notify'].indexOf('email') > -1;
67             var phone = load_info.settings['opac.hold_notify'].indexOf('phone') > -1;
68             var sms = load_info.settings['opac.hold_notify'].indexOf('sms') > -1;
69             var update_elements = document.getElementsByName('email_notify');
70             for(var i in update_elements) update_elements[i].checked = (email ? 'checked' : '');
71             update_elements = document.getElementsByName('phone_notify_checkbox');
72             for(var i in update_elements) update_elements[i].checked = (phone ? 'checked' : '');
73             update_elements = document.getElementsByName('sms_notify_checkbox');
74             for(var i in update_elements) update_elements[i].checked = (sms ? 'checked' : '');
75         }
76         update_elements = document.getElementsByName('phone_notify');
77         for(var i in update_elements) update_elements[i].value = load_info.settings['opac.default_phone'];
78         update_elements = document.getElementsByName('sms_notify');
79         for(var i in update_elements) update_elements[i].value = load_info.settings['opac.default_sms_notify'];
80         update_elements = document.getElementsByName('sms_carrier');
81         for(var i in update_elements) update_elements[i].value = load_info.settings['opac.default_sms_carrier'];
82         update_elements = document.getElementsByName('email_notify');
83         for(var i in update_elements) {
84             update_elements[i].disabled = (load_info.user_email ? false : true);
85             if(update_elements[i].disabled) update_elements[i].checked = false;
86         }
87         update_elements = document.getElementsByName('email_address');
88         for(var i in update_elements) update_elements[i].textContent = load_info.user_email;
89         if(!document.getElementById('hold_usr_is_requestor').checked && document.getElementById('hold_usr_input').value) {
90             document.getElementById('patron_name').innerHTML = load_info.patron_name;
91         }
92         // Ok, now we can allow submitting again, unless this is a "true" load, in which case we likely have a blank barcode box active
93         if (isload !== true)
94             document.getElementById('place_hold_submit').disabled = false;
95     }
96 }
97 window.onload = function() {
98     // record details page events
99     var rec = location.href.match(/\/opac\/record\/(\d+)/);
100     if(rec && rec[1]) { 
101         runEvt('rdetail', 'recordRetrieved', rec[1]); 
102         runEvt('rdetail', 'MFHDDrawn');
103     }
104     if(location.href.match(/place_hold/)) {
105         if(xulG.patron_barcode) {
106             staff_hold_usr_barcode_changed(xulG.patron_barcode);
107         } else {
108             staff_hold_usr_barcode_changed(true);
109         }
110     }
111 }
112
113 function rdetail_next_prev_actions(index, count, prev, next, start, end, results) {
114     /*  we mostly get the relative URL from the template:  recid?query_args...
115         replace the recid and args on location.href to get the new URL  */
116     function fullurl(url) {
117         if (url.match(/eg\/opac\/results/)) {
118             return location.href.replace(/eg\/opac\/.+$/, url);
119         } else {
120             return location.href.replace(/\/\d+\??.*/, '/' + url);
121         }
122     }
123
124     if (index > 0) {
125         if(prev) 
126             window.rdetailPrev = function() { location.href = fullurl(prev); }
127         if(start) 
128             window.rdetailStart = function() { location.href = fullurl(start); }
129     }
130
131     if (index < count - 1) {
132         if(next) 
133             window.rdetailNext = function() { location.href = fullurl(next); }
134         if(end) 
135             window.rdetailEnd = function() { location.href = fullurl(end); }
136     }
137
138     window.rdetailBackToResults = function() { location.href = fullurl(results); };
139
140     ol = window.onload;
141     window.onload = function() {
142         if(ol) ol(); 
143         runEvt('rdetail', 'nextPrevDrawn', Number(index), Number(count)); 
144     };
145 }