Bug 16732 - Add audio alerts (custom sound notifications) to web based self checkout
authorNick Clemens <nick@bywatersolutions.com>
Mon, 15 Aug 2016 19:58:52 +0000 (19:58 +0000)
committerKyle M Hall <kyle@bywatersolutions.com>
Tue, 13 Sep 2016 17:22:33 +0000 (17:22 +0000)
This patch adds the infrastructure needed to allow audio alerts, as
configured in administration, to affect the sco module

This patch allows only for the use of sounds with a full URL to be used
and does not allow for the Koha standard sounds to be accessed via the
SCO

To test:
Ensure you have the preference AudioAlerts enabled
Ensure you can hear normal sounds from the staff module
Define an audio alert such as:
    Selector: .sco_entry
    Sound: https://archive.org/download/Doorbell_1/doorbell.ogg
Load the SCO module
You should hear the doorbell noise (everytime you reload even!)
Test that the default sounds are not activated for the SCO, you must
sepcifically define them

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
koha-tmpl/opac-tmpl/bootstrap/en/modules/sco/sco-main.tt

index 42d2508..11147ae 100644 (file)
@@ -1,5 +1,6 @@
 [% USE Koha %]
 [% USE KohaDates %]
+[% USE AudioAlerts %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>[% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha [% END %] &rsaquo; Self checkout </title>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
             </div> <!-- / .row-fluid -->
         </div> <!-- / .container-fluid -->
     </div> <!-- / .main -->
+    <span id="audio-alert"></span>
+</body>
 
 [% INCLUDE 'opac-bottom.inc' %]
 [% BLOCK jsinclude %]
             }
             return true;
         }
+        [% IF Koha.Preference('AudioAlerts') %]
+            var AUDIO_ALERTS = JSON.parse( '[% AudioAlerts.AudioAlerts | replace( "'", "\\'" ) | replace( '"', '\\"' ) %]' );
+            $( document ).ready(function() {
+                if ( AUDIO_ALERTS ) {
+                    for ( var k in AUDIO_ALERTS ) {
+                        var alert = AUDIO_ALERTS[k];
+                        if ( $( alert.selector ).length ) {
+                            playSound( alert.sound );
+                            break;
+                        }
+                    }
+                }
+            });
+            function playSound( sound ) {
+                if (  ( sound.indexOf('http://') == 0 || sound.indexOf('https://') == 0 )  ) {
+                    document.getElementById("audio-alert").innerHTML = '<audio src="' + sound + '" autoplay="autoplay" autobuffer="autobuffer"></audio>';
+                }
+            }
+        [% END %]
+
 
         $(document).ready(function() {
             dofocus();