From 229cf1dfafe65a413b9fa9c73bb1bab1bf3ec120 Mon Sep 17 00:00:00 2001
From: Kyle M Hall <kyle@bywatersolutions.com>
Date: Thu, 19 Jun 2014 09:44:24 -0400
Subject: [PATCH] Bug 11431 [4] - Add the ability to choose the elements that trigger an audio alert

---
 installer/data/mysql/updatedatabase.pl             |    5 ++++-
 .../prog/en/includes/doc-head-close.inc            |   17 ++++++++++-------
 .../en/modules/admin/preferences/circulation.pref  |   15 +++++++++++++++
 3 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl
index d4b8e97..a748e3f 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -8578,7 +8578,10 @@ if ( CheckVersion($DBversion) ) {
         INSERT IGNORE INTO systempreferences ( variable, value, options, explanation, type ) VALUES
         ( 'OverrideAudioAlertWarning', '', NULL, 'URL to an audio file to replace the default warning sound.',           'free' ),
         ( 'OverrideAudioAlertAction',  '', NULL, 'URL to an audio file to replace the default "action required" sound.', 'free' ),
-        ( 'OverrideAudioAlertSuccess', '', NULL, 'URL to an audio file to replace the default success sound.',           'free' )
+        ( 'OverrideAudioAlertSuccess', '', NULL, 'URL to an audio file to replace the default success sound.',           'free' ),
+        ( 'AudioAlertSelectorWarning', '.audio-alert-warning', NULL, 'List of jQuery selectors that should trigger warning alert',  'free' ),
+        ( 'AudioAlertSelectorAction',  '.audio-alert-action',  NULL, 'List of jQuery selectors that should trigger action alert',   'free' ),
+        ( 'AudioAlertSelectorSuccess', '.audio-alert-success', NULL, 'List of jQuery selectors that should trigger successs alert', 'free' )
     });
 
     print "Upgrade to $DBversion done (Bug 11169 - Add OPACAcquisitionDetails syspref)\n";
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc
index 7ef8746..5ef308d 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc
@@ -66,20 +66,23 @@
 [% IF AudioAlerts %]
     <script type="text/javascript">
         //<![CDATA[
-            var AUDIO_ALERT_PATH = "[% interface %]/[% theme %]/sound/";
-            var AUDIO_ALERT_ACTION  = "[% Koha.Preference('OverrideAudioAlertAction')  || 'opening.ogg'  %]";
-            var AUDIO_ALERT_WARNING = "[% Koha.Preference('OverrideAudioAlertWarning') || 'critical.ogg' %]";
-            var AUDIO_ALERT_SUCCESS = "[% Koha.Preference('OverrideAudioAlertSuccess') || 'beep.ogg'     %]";
+            var AUDIO_ALERT_PATH = '[% interface %]/[% theme %]/sound/';
+            var AUDIO_ALERT_ACTION  = '[% Koha.Preference("OverrideAudioAlertAction")  || "opening.ogg"  %]';
+            var AUDIO_ALERT_WARNING = '[% Koha.Preference("OverrideAudioAlertWarning") || "critical.ogg" %]';
+            var AUDIO_ALERT_SUCCESS = '[% Koha.Preference("OverrideAudioAlertSuccess") || "beep.ogg"     %]';
+            var AUDIO_ALERT_SELECTOR_ACTION  = '[% Koha.Preference("AudioAlertSelectorAction")  | replace( "'", "\\'" ) %]';
+            var AUDIO_ALERT_SELECTOR_WARNING = '[% Koha.Preference("AudioAlertSelectorWarning") | replace( "'", "\\'" ) %]';
+            var AUDIO_ALERT_SELECTOR_SUCCESS = '[% Koha.Preference("AudioAlertSelectorSuccess") | replace( "'", "\\'" ) %]';
         //]]>
 
         $( document ).ready(function() {
-            if ( $(".audio-alert-action").length ) {
+            if ( $( AUDIO_ALERT_SELECTOR_ACTION ).length ) {
                 playSoundAction();
             }
-            else if ( $(".audio-alert-warning").length ) {
+            else if ( $( AUDIO_ALERT_SELECTOR_WARNING ).length ) {
                 playSoundWarning();
             }
-            else if ( $(".audio-alert-success").length ) {
+            else if ( $( AUDIO_ALERT_SELECTOR_SUCCESS ).length ) {
                 playSoundSuccess();
             }
         });
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref
index 68b3b81..f422b1e 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref
@@ -635,3 +635,18 @@ Circulation:
             - pref: OverrideAudioAlertSuccess
               class: url
             - (This should be a complete URL, starting with <code>http://</code>)
+        -
+            - Use the following selectors for <i>warning</i> alerts
+            - pref: AudioAlertSelectorWarning
+              class: url
+            - (This should be a list of jQuery selectors, separated by commas)
+        -
+            - Use the following selectors for <i>action</i> alerts
+            - pref: AudioAlertSelectorAction
+              class: url
+            - (This should be a list of jQuery selectors, separated by commas)
+        -
+            - Use the following selectors for <i>success</i> alerts
+            - pref: AudioAlertSelectorSuccess
+              class: url
+            - (This should be a list of jQuery selectors, separated by commas)
-- 
1.7.2.5