From af0de0714325acc9323d76b062940fcf2f3a2b99 Mon Sep 17 00:00:00 2001
From: erickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Date: Tue, 10 Nov 2009 18:43:19 +0000
Subject: [PATCH] Patch from Lebbeous Fogle-Weekley to support configured staff
 client idle timeout delays.  When staff has been idle for X amount of time
 (per org unit setting), the staff client display will minimize.  Staff is not
 logged out of the server based on this setting.  Use this in environments
 where unattended staff clients should be minimized for privacy reasons.

git-svn-id: svn://svn.open-ils.org/ILS/trunk@14855 dcc99617-32d9-48b4-a31d-7c20da2025e4
---
 Open-ILS/src/sql/Pg/002.schema.config.sql          |  2 +-
 Open-ILS/src/sql/Pg/950.data.seed-values.sql       |  8 +++----
 ...ust.ui_circ_patron_display_timeout_interval.sql | 13 +++++++++++
 .../chrome/content/main/menu_frame.xul             | 27 ++++++++++++++++++++--
 4 files changed, 43 insertions(+), 7 deletions(-)
 create mode 100644 Open-ILS/src/sql/Pg/upgrade/0076.data.coust.ui_circ_patron_display_timeout_interval.sql

diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql
index c20594797e..8cc430ddf4 100644
--- a/Open-ILS/src/sql/Pg/002.schema.config.sql
+++ b/Open-ILS/src/sql/Pg/002.schema.config.sql
@@ -51,7 +51,7 @@ CREATE TABLE config.upgrade_log (
     install_date    TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
 );
 
-INSERT INTO config.upgrade_log (version) VALUES ('0075'); -- dbs
+INSERT INTO config.upgrade_log (version) VALUES ('0076'); -- senator
 
 CREATE TABLE config.bib_source (
 	id		SERIAL	PRIMARY KEY,
diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql
index 033cc3f47d..fa3fb09837 100644
--- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql
+++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql
@@ -1622,10 +1622,10 @@ INSERT into config.org_unit_setting_type
   'If enabled and a patron has outstanding bills and the alert page is not required, show the billing tab by default, instead of the checkout tab, when a patron is loaded',
   'bool' ),
 
-( 'ui.circ.patron_display_timeout_interval',
-  'GUI: Patron display timeout interval',
-  'Set this if you would like patron displays in the staff client to be closed after a certain interval of inactivity.  Example ''5 minutes''',
-  'interval' ),
+( 'ui.general.idle_timeout',
+    'GUI: Idle timeout',
+    'If you want staff client windows to be minimized after a certain amount of system idle time, set this to the number of seconds of idle time that you want to allow before minimizing (requires staff client restart).',
+    'integer' ),
 
 ( 'ui.circ.in_house_use.entry_cap',
   'GUI: Record In-House Use: Maximum # of uses allowed per entry.',
diff --git a/Open-ILS/src/sql/Pg/upgrade/0076.data.coust.ui_circ_patron_display_timeout_interval.sql b/Open-ILS/src/sql/Pg/upgrade/0076.data.coust.ui_circ_patron_display_timeout_interval.sql
new file mode 100644
index 0000000000..671879c284
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/upgrade/0076.data.coust.ui_circ_patron_display_timeout_interval.sql
@@ -0,0 +1,13 @@
+-- Correct the description of the org unit setting to match its use.
+
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0076'); -- senator
+
+DELETE FROM config.org_unit_setting_type WHERE name = 'ui.circ.patron_display_timeout_interval';
+
+INSERT INTO config.org_unit_setting_type
+    (name, label, description, datatype) VALUES
+    ('ui.general.idle_timeout', 'GUI: Idle timeout', 'If you want staff client windows to be minimized after a certain amount of system idle time, set this to the number of seconds of idle time that you want to allow before minimizing (requires staff client restart).', 'integer');
+
+COMMIT;
diff --git a/Open-ILS/xul/staff_client/chrome/content/main/menu_frame.xul b/Open-ILS/xul/staff_client/chrome/content/main/menu_frame.xul
index 24b2845e56..786e018940 100644
--- a/Open-ILS/xul/staff_client/chrome/content/main/menu_frame.xul
+++ b/Open-ILS/xul/staff_client/chrome/content/main/menu_frame.xul
@@ -35,16 +35,37 @@
 
     <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
     <!-- BEHAVIOR -->
-        <script type="text/javascript">var myPackageDir = 'open_ils_staff_client'; var IAMXUL = true; var g = {};</script>
-        <scripts id="openils_util_scripts"/>
+    <script type="text/javascript">var myPackageDir = 'open_ils_staff_client'; var IAMXUL = true; var g = {}; var idleService = null; var idleObserver = null;</script>
+    <scripts id="openils_util_scripts"/>
 
     <script type="text/javascript" src="JSAN.js"/>
     <script type="text/javascript" src="constants.js"/>
     <script type="text/javascript" src="../OpenILS/util/fmall.js"/>
     <script type="text/javascript">
     <![CDATA[
+        function setup_idle_observer(delay) {
+            dump("will minimize after " + delay + " idle seconds\n");
+            idleService = Components.classes[
+                "@mozilla.org/widget/idleservice;1"
+            ].getService(Components.interfaces.nsIIdleService);
+            idleObserver = {
+                observe: function(subject, topic, data) {
+                    if (topic == "idle") {
+                        window.minimize();
+                        dump("minimizing window; subject: " + subject +
+                            ", topic: " + topic +
+                            ", data: " + data + "\n");
+                    }
+                }
+            };
+            idleService.addIdleObserver(idleObserver, delay); // seconds
+            // You could remove the IdleObserver with the following line...
+            // idleService.removeIdleObserver(idleObserver, delay);
+            // ... but why would we?
+        }
         function my_init() {
             try {
+
                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                 if (typeof JSAN == 'undefined') { throw(document.getElementById('offlineStrings').getString('common.jsan.missing')); }
                 JSAN.errorLevel = "die"; // none, warn, or die
@@ -69,6 +90,8 @@
 
                 document.title = g.window.appshell_name_increment() + ': ' + g.data.list.au[0].usrname() + '@' + g.data.ws_name + '.' + g.data.server_unadorned;
 
+                var delay = g.data.hash.aous["ui.general.idle_timeout"];
+                if (delay) setup_idle_observer(delay);
             } catch(E) {
                 var err_msg = document.getElementById("offlineStrings").getFormattedString("common.exception", ["menu_frame.xul", E]);
                 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
-- 
2.11.0