From 68e1a82d3dcd8f96646d55990aa4c733543079bb Mon Sep 17 00:00:00 2001
From: phasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Date: Mon, 26 Apr 2010 03:54:08 +0000
Subject: [PATCH] don't let util.error create sound objects (trying to reduce
 proliferation of such objects for easier debugging), and give fancy_prompt
 the ability to handle its own sounds, to prevent blocking of sounds due to
 the modal window dialog.  Have util.error and util.network make fancy_prompt
 do this

git-svn-id: svn://svn.open-ils.org/ILS/trunk@16295 dcc99617-32d9-48b4-a31d-7c20da2025e4
---
 Open-ILS/xul/staff_client/chrome/content/util/error.js  | 17 +++++++----------
 .../staff_client/chrome/content/util/fancy_prompt.xul   |  5 +++++
 .../xul/staff_client/chrome/content/util/network.js     |  3 +--
 3 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/Open-ILS/xul/staff_client/chrome/content/util/error.js b/Open-ILS/xul/staff_client/chrome/content/util/error.js
index 7521c9e507..adbab36763 100644
--- a/Open-ILS/xul/staff_client/chrome/content/util/error.js
+++ b/Open-ILS/xul/staff_client/chrome/content/util/error.js
@@ -18,7 +18,10 @@ util.error = function () {
 
         this.OpenILS = {};
 
-        JSAN.use('util.sound'); this.sound = new util.sound();
+        // Only use sounds if the context window has already created a sound object
+        if (typeof xulG != 'undefined' && xulG._sound) {
+            this.sound = xulG._sound;
+        }
 
     } catch(E) {
         alert('Error in util.error constructor: ' + E);
@@ -340,9 +343,6 @@ util.error.prototype = {
         dump('yns_alert:\n\ts = ' + s + '\n\ttitle = ' + title + '\n\tb1 = ' + b1 + '\n\tb2 = ' + b2 + '\n\tb3 = ' + b3 + '\n\tc = ' + c + '\n');
         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect UniversalBrowserWrite");
 
-        this.sound.bad();
-
-
         //FIXME - is that good enough of an escape job?
         s = s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
 
@@ -374,7 +374,7 @@ util.error.prototype = {
         if (typeof xulG != 'undefined') if (typeof xulG.url_prefix == 'function') url = xulG.url_prefix( url );
         JSAN.use('util.window'); var win = new util.window();
         var fancy_prompt_data = win.open(
-            url, 'fancy_prompt', 'chrome,resizable,modal,width=700,height=500', { 'xml' : xml, 'title' : title }
+            url, 'fancy_prompt', 'chrome,resizable,modal,width=700,height=500', { 'xml' : xml, 'title' : title, 'sound' : 'bad' }
         );
         if (fancy_prompt_data.fancy_status == 'complete') {
             switch(fancy_prompt_data.fancy_submit) {
@@ -417,9 +417,6 @@ util.error.prototype = {
         dump('yns_alert_formatted:\n\ts = ' + s + '\n\ttitle = ' + title + '\n\tb1 = ' + b1 + '\n\tb2 = ' + b2 + '\n\tb3 = ' + b3 + '\n\tc = ' + c + '\n');
         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect UniversalBrowserWrite");
 
-        this.sound.bad();
-
-
         //FIXME - is that good enough of an escape job?
         s = s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
 
@@ -451,7 +448,7 @@ util.error.prototype = {
         if (typeof xulG != 'undefined') if (typeof xulG.url_prefix == 'function') url = xulG.url_prefix( url );
         JSAN.use('util.window'); var win = new util.window();
         var fancy_prompt_data = win.open(
-            url, 'fancy_prompt', 'chrome,resizable,modal,width=700,height=500', { 'xml' : xml, 'title' : title }
+            url, 'fancy_prompt', 'chrome,resizable,modal,width=700,height=500', { 'xml' : xml, 'title' : title, 'sound' : 'bad' }
         );
         if (fancy_prompt_data.fancy_status == 'complete') {
             switch(fancy_prompt_data.fancy_submit) {
@@ -486,7 +483,7 @@ util.error.prototype = {
         dump('yns_alert_original:\n\ts = ' + s + '\n\ttitle = ' + title + '\n\tb1 = ' + b1 + '\n\tb2 = ' + b2 + '\n\tb3 = ' + b3 + '\n\tc = ' + c + '\n');
         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
 
-        this.sound.bad();
+        if (this.sound) { this.sound.bad(); }
 
         // get a reference to the prompt service component.
         var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
diff --git a/Open-ILS/xul/staff_client/chrome/content/util/fancy_prompt.xul b/Open-ILS/xul/staff_client/chrome/content/util/fancy_prompt.xul
index 5a7aeea396..50981b087a 100644
--- a/Open-ILS/xul/staff_client/chrome/content/util/fancy_prompt.xul
+++ b/Open-ILS/xul/staff_client/chrome/content/util/fancy_prompt.xul
@@ -98,6 +98,11 @@
                     if (focus_element) focus_element.focus();
                 }
 
+                var snd = xul_param('sound',{'modal_xulG':true});
+                if (snd) {
+                    try { JSAN.use('util.sound'); var sound = new util.sound(); sound[ snd ](); } catch(E) { alert(E); }
+                }
+
                 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
                 xulG.fancy_status = 'incomplete';
                 var key = location.pathname + location.search + location.hash;
diff --git a/Open-ILS/xul/staff_client/chrome/content/util/network.js b/Open-ILS/xul/staff_client/chrome/content/util/network.js
index 8d7cc3610b..b84644a96c 100644
--- a/Open-ILS/xul/staff_client/chrome/content/util/network.js
+++ b/Open-ILS/xul/staff_client/chrome/content/util/network.js
@@ -447,7 +447,6 @@ util.network.prototype = {
                     }
 
                     netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
-                    obj.sound.bad();
                     var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">' + 
                         '<groupbox><caption label="' + offlineStrings.getString('network.override.exceptions') + '"/>' + 
                         '<grid><columns><column/><column/></columns><rows>';
@@ -474,7 +473,7 @@ util.network.prototype = {
                         //+ '?xml_in_stash=temp_override_xml'
                         //+ '&title=' + window.escape(override_params.title),
                         'fancy_prompt', 'chrome,resizable,modal,width=700,height=500',
-                        { 'xml' : xml, 'title' : override_params.title }
+                        { 'xml' : xml, 'title' : override_params.title, 'sound' : 'bad' }
                     );
                     if (fancy_prompt_data.fancy_status == 'complete') {
                         req = obj._request(app,name + '.override',params);
-- 
2.11.0