plugged in audio alerts for selfcheck. local config is managed by TT path overriding...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 24 Nov 2009 22:45:22 +0000 (22:45 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 24 Nov 2009 22:45:22 +0000 (22:45 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@15021 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/js/dojo/openils/Util.js
Open-ILS/web/js/ui/default/circ/selfcheck/selfcheck.js
Open-ILS/web/templates/default/circ/selfcheck/audio_config.tt2 [new file with mode: 0644]
Open-ILS/web/templates/default/circ/selfcheck/main.tt2

index b9e4a49..ce89904 100644 (file)
@@ -256,6 +256,7 @@ if(!dojo._hasResource["openils.Util"]) {
      * that support HTML 5 <audio> element.  E.g. Firefox 3.5
      */
     openils.Util.playAudioUrl = function(urlString) {
+        if(!urlString) return;
         var audio = document.createElement('audio');
         audio.setAttribute('src', urlString);
         audio.setAttribute('autoplay', 'true');
index cb14b4e..483fc37 100644 (file)
@@ -17,6 +17,7 @@ const SET_AUTO_OVERRIDE_EVENTS = 'circ.selfcheck.auto_override_checkout_events';
 const SET_PATRON_PASSWORD_REQUIRED = 'circ.selfcheck.patron_password_required';
 const SET_AUTO_RENEW_INTERVAL = 'circ.checkout_auto_renew_age';
 const SET_WORKSTATION_REQUIRED = 'circ.selfcheck.workstation_required';
+const SET_SOUND_ON_CHECKOUT_EVENT = 'circ.selfcheck.sound_on_checkout_event';
 
 //openils.Util.playAudioUrl('/xul/server/skin/media/audio/bonus.wav');
 
@@ -179,8 +180,10 @@ SelfCheckManager.prototype.loginPatron = function(barcode, passwd) {
 
         if(res == 0) {
             // user-not-found results in login failure
-            dojo.byId('oils-selfck-status-div').innerHTML = 
-                dojo.string.substitute(localeStrings.LOGIN_FAILED, [barcode]);
+            this.handleAlert(
+                dojo.string.substitute(localeStrings.LOGIN_FAILED, [barcode]),
+                false, 'login-failure'
+            );
             this.drawLoginPage();
             return;
         }
@@ -194,20 +197,35 @@ SelfCheckManager.prototype.loginPatron = function(barcode, passwd) {
 
     var evt = openils.Event.parse(this.patron);
     if(evt) {
-
-        dojo.byId('oils-selfck-status-div').innerHTML = 
-            dojo.string.substitute(localeStrings.LOGIN_FAILED, [barcode]);
+        this.handleAlert(
+            dojo.string.substitute(localeStrings.LOGIN_FAILED, [barcode]),
+            false, 'login-failure'
+        );
         this.drawLoginPage();
 
     } else {
 
-        dojo.byId('oils-selfck-status-div').innerHTML = '';
+        this.handleAlert('', false, 'login-success');
         dojo.byId('oils-selfck-user-banner').innerHTML = 'Welcome, ' + this.patron.usrname(); // TODO i18n
         this.drawCircPage();
     }
 }
 
 
+SelfCheckManager.prototype.handleAlert = function(message, shouldPopup, sound) {
+
+    console.log("Handling alert " + message);
+
+    dojo.byId('oils-selfck-status-div').innerHTML = message;
+
+    if(shouldPopup && this.orgSettings[SET_ALERT_ON_CHECKOUT_EVENT]) 
+        alert(message);
+
+    if(sound && this.orgSettings[SET_SOUND_ON_CHECKOUT_EVENT])
+        openils.Util.playAudioUrl(SelfCheckManager.audioConfig[sound]);
+}
+
+
 /**
  * Manages the main input box
  * @param msg The context message to display with the box
@@ -522,6 +540,8 @@ SelfCheckManager.prototype.handleXactResult = function(action, item, result) {
     // an alert() actually occurs, depends on org unit settings
     var popup = false;  
 
+    var sound = '';
+
     // TODO handle lost/missing/etc checkin+checkout override steps
     
     var payload = result.payload || {};
@@ -552,6 +572,7 @@ SelfCheckManager.prototype.handleXactResult = function(action, item, result) {
             this.displayCheckout(result, 'renew');
         }
 
+        sound = 'checkout-success';
         this.updateScanBox();
 
     } else if(result.textcode == 'OPEN_CIRCULATION_EXISTS' && action == 'checkout') {
@@ -574,12 +595,14 @@ SelfCheckManager.prototype.handleXactResult = function(action, item, result) {
             }
 
             popup = true;
+            sound = 'checkout-failure';
             displayText = dojo.string.substitute(localeStrings.ALREADY_OUT, [item]);
 
         } else {
             
             // item is checked out to some other user
             popup = true;
+            sound = 'checkout-failure';
             displayText = dojo.string.substitute(localeStrings.OPEN_CIRCULATION_EXISTS, [item]);
         }
 
@@ -612,6 +635,7 @@ SelfCheckManager.prototype.handleXactResult = function(action, item, result) {
     
         this.updateScanBox({select : true});
         popup = true;
+        sound = 'checkout-failure';
 
         if(result.length) 
             result = result[0];
@@ -646,13 +670,7 @@ SelfCheckManager.prototype.handleXactResult = function(action, item, result) {
         }
     }
 
-    console.log("Updating status with " + displayText);
-
-    dojo.byId('oils-selfck-status-div').innerHTML = displayText;
-
-    if(popup && this.orgSettings[SET_ALERT_ON_CHECKOUT_EVENT]) 
-        alert(displayText);
-
+    this.handleAlert(displayText, popup, sound);
     return {};
 }
 
diff --git a/Open-ILS/web/templates/default/circ/selfcheck/audio_config.tt2 b/Open-ILS/web/templates/default/circ/selfcheck/audio_config.tt2
new file mode 100644 (file)
index 0000000..1f8b957
--- /dev/null
@@ -0,0 +1,13 @@
+[%#
+    Override the audio config values by copying this template into your local templates
+    directory (matching the relative path) and change the values accordingly.
+#%]
+
+<script>
+    SelfCheckManager.audioConfig = {
+        'login-success' : '',
+        'login-failure' : '[% ctx.media_prefix %]/audio/circ/question.wav',
+        'checkout-success' : '[% ctx.media_prefix %]/audio/circ/bonus.wav',
+        'checkout-failure' : '[% ctx.media_prefix %]/audio/circ/question.wav',
+    }
+</script>
index 0a9031c..98751c0 100644 (file)
@@ -2,6 +2,7 @@
 [% WRAPPER default/base.tt2 %]
 <script src='[% ctx.media_prefix %]/js/ui/default/circ/selfcheck/selfcheck.js'> </script>
 <link rel='stylesheet' type='text/css' href='[% ctx.media_prefix %]/css/skin/[% ctx.skin %]/selfcheck.css'></link>
+[% INCLUDE 'default/circ/selfcheck/audio_config.tt2' %]
 
 <div id='oils-selfck-top-div'>
     <div id='oils-selfck-user-banner'></div>