-<script>
+<script type="text/javascript">
var vendors_requiring_password = [];
[% IF !loc_value; PROCESS get_library; END; %]
vendors_requiring_password.push('overdrive');
[% END %]
+var pw_cache_count = 0;
+
dojo.addOnLoad(function() {
- var handle = dojo.connect(dojo.byId('#login-form-box'), 'onclick', function(evt) {
+ var handle = dojo.connect(dojo.byId('login-form'), 'onsubmit', function(evt) {
+ // Prevent the form submission from happening until after we have
+ // handled any ebook vendor interactions
+ evt.preventDefault();
+
// disconnect this event since it's one-time-only
// (when we switch to jQuery, we can use .one() here)
dojo.disconnect(handle);
// we cache the username (and password) for now, but will
// replace that with the patron's active barcode later
- vendors_requiring_password.forEach(function(v) {
- if (vendor_list.includes(v)) {
- checkSession(v, function(v,ses) {
- var username = dojo.byId('#username_field').value;
- var password = dojo.byId('#password_field').value;
- new OpenSRF.ClientSession('open-ils.ebook_api').request({
- method: 'open-ils.ebook_api.patron.cache_password',
- params: [ ses, password ],
- async: true,
- oncomplete: function(r) {
- var resp = r.recv();
- if (resp) {
- console.log('patron password has been cached');
- return;
+ if (vendors_requiring_password.length > 0) {
+ vendors_requiring_password.forEach(function(v) {
+ pw_cache_count++;
+ if (vendor_list.includes(v)) {
+ checkSession(v, function(v,ses) {
+ var username = dojo.byId('username_field').value;
+ var password = dojo.byId('password_field').value;
+ new OpenSRF.ClientSession('open-ils.ebook_api').request({
+ method: 'open-ils.ebook_api.patron.cache_password',
+ params: [ ses, password ],
+ async: true,
+ oncomplete: function(r) {
+ var resp = r.recv();
+ if (resp) {
+ // Success, now submit the form
+ console.log('patron password has been cached');
+ if (pw_cache_count >= vendors_requiring_password.length) {
+ document.getElementById('login-form').submit();
+ return;
+ }
+ }
}
- }
- }).send();
- });
- }
- });
+ }).send();
+ });
+ }
+ });
+ } else {
+ document.getElementById('login-form').submit();
+ }
});
});
</script>