Rework constants for audio to be more dynamic. We can now specify a specific sound...
authorphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 19 Apr 2010 18:28:21 +0000 (18:28 +0000)
committerphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 19 Apr 2010 18:28:21 +0000 (18:28 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@16277 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/xul/staff_client/chrome/content/main/constants.js
Open-ILS/xul/staff_client/chrome/content/util/network.js
Open-ILS/xul/staff_client/chrome/content/util/sound.js

index 0e70afc..52c8b47 100644 (file)
@@ -313,11 +313,12 @@ var urls = {
     'fieldmapper' : '/opac/common/js/fmall.js',
     'xsl_marc2html' : '/opac/extras/xsl/oilsMARC21slim2HTML.xsl',
 
-    'AUDIO_GOOD_SOUND' : '/xul/server/skin/media/audio/bonus.wav',
-    'AUDIO_BAD_SOUND' : '/xul/server/skin/media/audio/question.wav',
-    'AUDIO_HORRIBLE_SOUND' : '/xul/server/skin/media/audio/redalert.wav',
-    'AUDIO_CIRC_GOOD_SOUND' : '/xul/server/skin/media/audio/toggled.wav',
-    'AUDIO_CIRC_BAD_SOUND' : '/xul/server/skin/media/audio/question.wav',
+    'AUDIO_good' : '/xul/server/skin/media/audio/bonus.wav',
+    'AUDIO_bad' : '/xul/server/skin/media/audio/question.wav',
+    'AUDIO_horrible' : '/xul/server/skin/media/audio/redalert.wav',
+    'AUDIO_circ_good' : '/xul/server/skin/media/audio/toggled.wav',
+    'AUDIO_circ_bad' : '/xul/server/skin/media/audio/question.wav',
+    'AUDIO_event_ASSET_COPY_NOT_FOUND' : '/xul/server/skin/media/audio/redalert.wav',
 
     'XUL_AUTH_SIMPLE' : '/xul/server/main/simple_auth.xul',
     'XUL_BIB_BRIEF' : '/xul/server/cat/bib_brief.xul',
index 60a9bf4..8d7cc36 100644 (file)
@@ -133,6 +133,7 @@ util.network.prototype = {
                                 + (json_string.length > 80 ? obj.error.pretty_print(json_string) : json_string) 
                                 + '\n\nOriginal Request:\n\n' 
                                 + 'request '+app+' '+name+' '+ sparams.slice(1,sparams.length-1));
+                            obj.play_sounds( request );
                             req = obj.rerequest_on_session_timeout(app,name,params,req,override_params,_params);
                             req = obj.rerequest_on_perm_failure(app,name,params,req,override_params,_params);
                             if (override_params) {
@@ -177,6 +178,7 @@ util.network.prototype = {
                     + obj.link_id + '\n\n' + ( json_string.length > 80 ? obj.error.pretty_print(json_string) : json_string ) 
                     + '\n\nOriginal Request:\n\n' 
                     + 'request '+app+' '+name+' '+ sparams.slice(1,sparams.length-1));
+                obj.play_sounds( request );
                 request = obj.rerequest_on_session_timeout(app,name,params,request,override_params,_params);
                 request = obj.rerequest_on_perm_failure(app,name,params,request,override_params,_params);
                 if (override_params) {
@@ -359,7 +361,7 @@ util.network.prototype = {
         try {
             var obj = this;
             var robj = obj.get_result(req);
-            if (robj != null && robj.ilsevent && robj.ilsevent == 1001) {
+            if (robj != null && robj.ilsevent && robj.ilsevent == 1001 /* NO_SESSION */) {
 
                 if (obj.get_new_session(name,undefined,true)) {
                     JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
@@ -548,6 +550,27 @@ util.network.prototype = {
         } catch(E) {
             alert(E);
         }
+    },
+
+    'play_sounds' : function(req) {
+        var obj = this;
+        try {
+            var result = req.getResultObject();
+            if (result == null) { return; }
+            if (typeof result.textcode != 'undefined') {
+                obj.sound.event( result );
+            } else {
+                if (typeof result.length != 'undefined') {
+                    for (var i = 0; i < result.length; i++) {
+                        if (typeof result[i].textcode != 'undefined') {
+                            obj.sound.event( result[i] );
+                        }
+                    }
+                }
+            }
+        } catch(E) {
+            dump('Error in network.js, play_sounds() : ' + E + '\n');
+        }
     }
 }
 
index 5be324e..0b1bb9e 100644 (file)
@@ -8,6 +8,7 @@ util.sound = function () {
         var SOUNDContractID = "@mozilla.org/sound;1";
         var SOUNDIID        = Components.interfaces.nsISound;
         this.SOUND          = Components.classes[SOUNDContractID].createInstance(SOUNDIID);
+        this.SOUND.init(); // not necessary, but helps avoid delays?
 
     } catch(E) {
         dump('util.sound constructor: ' + E + '\n');
@@ -35,12 +36,14 @@ util.sound.prototype = {
 
     'play_url' : function(url) {
 
+        if (!url) { return; /* sound of silence */ }
+
         var obj = this;
         try {
             netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
             JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
             var url2 = obj.xp_url_init( data.server + url );
-            dump('url = ' + url2 + '\n');
+            dump('SOUND: file = ' + url + '\n');
             if (typeof data.no_sound == 'undefined' || data.no_sound == false || data.no_sound == 'false') obj.SOUND.play( url2 );
         } catch(E) {
             try { if (data.no_sound == 'undefined' || data.no_sound == false || data.no_sound == 'false') obj.SOUND.beep(); } catch(F) { 
@@ -48,28 +51,43 @@ util.sound.prototype = {
             }
             dump('play_url(): ' + E + '\n');
         }
-
     },
 
-    'good' : function(e){
-        this.play_url( urls.AUDIO_GOOD_SOUND );
+    'event' : function event(evt) {
+        var key = 'AUDIO_' + arguments.callee.name + '_' + evt.textcode;
+        dump('SOUND: key = ' + key + '\n');
+        this.play_url( urls[key] );
     },
 
-    'bad' : function(e){
-        this.play_url( urls.AUDIO_BAD_SOUND );
+    'good' : function good(e){
+        var key = 'AUDIO_' + arguments.callee.name;
+        dump('SOUND: key = ' + key + '\n');
+        this.play_url( urls[key] );
     },
 
-    'horrible' : function(e){
-        this.play_url( urls.AUDIO_HORRIBLE_SOUND );
+    'bad' : function bad(e){
+        var key = 'AUDIO_' + arguments.callee.name;
+        dump('SOUND: key = ' + key + '\n');
+        this.play_url( urls[key] );
     },
 
-    'circ_good' : function(e){
-        this.play_url( urls.AUDIO_CIRC_GOOD_SOUND );
+    'horrible' : function horrible(e){
+        var key = 'AUDIO_' + arguments.callee.name;
+        dump('SOUND: key = ' + key + '\n');
+        this.play_url( urls[key] );
     },
 
-    'circ_bad' : function(e){
-        this.play_url( urls.AUDIO_CIRC_BAD_SOUND );
+    'circ_good' : function circ_good(e){
+        var key = 'AUDIO_' + arguments.callee.name;
+        dump('SOUND: key = ' + key + '\n');
+        this.play_url( urls[key] );
     },
+
+    'circ_bad' : function circ_bad(e){
+        var key = 'AUDIO_' + arguments.callee.name;
+        dump('SOUND: key = ' + key + '\n');
+        this.play_url( urls[key] );
+    }
 }
 
 dump('exiting util/sound.js\n');