From 57d3c9ae491d215e7247e9a7e3d7dca814039617 Mon Sep 17 00:00:00 2001 From: phasefx Date: Tue, 7 Dec 2010 16:58:06 +0000 Subject: [PATCH] tab lock infrastructure. call xulG.lock_tab() and then any attempt to close or replace the tab will give staff a confirmation dialog. multiple locks may be placed on a given tab, and an identical number of xulG.unlock_tab() invocations will unlock it git-svn-id: svn://svn.open-ils.org/ILS/trunk@18925 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../xul/staff_client/chrome/content/cat/opac.js | 6 +++ .../xul/staff_client/chrome/content/main/menu.js | 48 ++++++++++++++++++++++ .../staff_client/chrome/content/util/browser.js | 4 ++ .../chrome/locale/en-US/offline.properties | 2 + 4 files changed, 60 insertions(+) diff --git a/Open-ILS/xul/staff_client/chrome/content/cat/opac.js b/Open-ILS/xul/staff_client/chrome/content/cat/opac.js index 28da88245..a3bc8e8b9 100644 --- a/Open-ILS/xul/staff_client/chrome/content/cat/opac.js +++ b/Open-ILS/xul/staff_client/chrome/content/cat/opac.js @@ -458,6 +458,9 @@ function set_opac() { content_params.new_tab = xulG.new_tab; content_params.set_tab = xulG.set_tab; content_params.close_tab = xulG.close_tab; + content_params.lock_tab = xulG.lock_tab; + content_params.unlock_tab = xulG.unlock_tab; + content_params.inspect_tab = xulG.inspect_tab; content_params.new_patron_tab = xulG.new_patron_tab; content_params.set_patron_tab = xulG.set_patron_tab; content_params.volume_item_creator = xulG.volume_item_creator; @@ -582,6 +585,9 @@ function bib_in_new_tab() { content_params.new_tab = xulG.new_tab; content_params.set_tab = xulG.set_tab; content_params.close_tab = xulG.close_tab; + content_params.lock_tab = xulG.lock_tab; + content_params.unlock_tab = xulG.unlock_tab; + content_params.inspect_tab = xulG.inspect_tab; content_params.new_patron_tab = xulG.new_patron_tab; content_params.set_patron_tab = xulG.set_patron_tab; content_params.volume_item_creator = xulG.volume_item_creator; diff --git a/Open-ILS/xul/staff_client/chrome/content/main/menu.js b/Open-ILS/xul/staff_client/chrome/content/main/menu.js index f731d989c..c12038136 100644 --- a/Open-ILS/xul/staff_client/chrome/content/main/menu.js +++ b/Open-ILS/xul/staff_client/chrome/content/main/menu.js @@ -1336,6 +1336,17 @@ main.menu.prototype = { 'close_tab' : function (specific_idx) { var idx = specific_idx || this.controller.view.tabs.selectedIndex; var panel = this.controller.view.panels.childNodes[ idx ]; + + var tab = this.controller.view.tabs.getItemAtIndex( idx ); + var id = tab.getAttribute('id'); + if (typeof this.tab_semaphores[id] != 'undefined') { + if (this.tab_semaphores[id] > 0) { + var confirmation = window.confirm(offlineStrings.getString('menu.close_tab.unsaved_data_warning')); + if (!confirmation) { return; } + delete this.tab_semaphores[id]; + } + } + this.controller.view.tabs.removeItemAt(idx); this.controller.view.panels.removeChild(panel); if(this.controller.view.tabs.childNodes.length > idx) { @@ -1588,6 +1599,9 @@ main.menu.prototype = { if (params.src) { help_btn.setAttribute('src', params.src); } } }, + + 'tab_semaphores' : {}, + 'set_tab' : function(url,params,content_params) { var obj = this; if (!url) url = '/xul/server/'; @@ -1597,10 +1611,44 @@ main.menu.prototype = { var idx = this.controller.view.tabs.selectedIndex; if (params && typeof params.index != 'undefined') idx = params.index; var tab = this.controller.view.tabs.childNodes[ idx ]; + + var id = tab.getAttribute('id'); + if (id) { + if (typeof obj.tab_semaphores[id] != 'undefined') { + if (obj.tab_semaphores[id] > 0) { + var confirmation = window.confirm(offlineStrings.getString('menu.replace_tab.unsaved_data_warning')); + if (!confirmation) { return; } + delete obj.tab_semaphores[id]; + } + } + } + var unique_id = idx + ':' + new Date(); + tab.setAttribute('id',unique_id); if (params.focus) tab.focus(); var panel = this.controller.view.panels.childNodes[ idx ]; while ( panel.lastChild ) panel.removeChild( panel.lastChild ); + content_params.lock_tab = function() { + var id = tab.getAttribute('id'); + if (typeof obj.tab_semaphores[id] == 'undefined') { + obj.tab_semaphores[id] = 0; + } + obj.tab_semaphores[id]++; + return obj.tab_semaphores[id]; + }; + content_params.unlock_tab = function() { + var id = tab.getAttribute('id'); + if (typeof obj.tab_semaphores[id] == 'undefined') { + obj.tab_semaphores[id] = 0; + } + obj.tab_semaphores[id]--; + if (obj.tab_semaphores[id] < 0) { obj.tab_semaphores[id] = 0; } + return obj.tab_semaphores[id]; + }; + content_params.inspect_tab = function() { + var id = tab.getAttribute('id'); + return 'id = ' + id + ' semaphore = ' + obj.tab_semaphores[id]; + } content_params.new_tab = function(a,b,c) { return obj.new_tab(a,b,c); }; content_params.set_tab = function(a,b,c) { return obj.set_tab(a,b,c); }; content_params.close_tab = function() { return obj.close_tab(); }; diff --git a/Open-ILS/xul/staff_client/chrome/content/util/browser.js b/Open-ILS/xul/staff_client/chrome/content/util/browser.js index 22652d678..a2d2a354e 100644 --- a/Open-ILS/xul/staff_client/chrome/content/util/browser.js +++ b/Open-ILS/xul/staff_client/chrome/content/util/browser.js @@ -257,6 +257,10 @@ util.browser.prototype = { cw.xulG = obj.passthru_content_params || {}; if (!cw.xulG.set_tab) { cw.xulG.set_tab = function(a,b,c) { return window.xulG.set_tab(a,b,c); }; } if (!cw.xulG.new_tab) { cw.xulG.new_tab = function(a,b,c) { return window.xulG.new_tab(a,b,c); }; } + if (!cw.xulG.close_tab) { cw.xulG.close_tab = function(a) { return window.xulG.close_tab(a); }; } + if (!cw.xulG.lock_tab) { cw.xulG.lock_tab = function() { return window.xulG.lock_tab(); }; } + if (!cw.xulG.unlock_tab) { cw.xulG.unlock_tab = function() { return window.xulG.unlock_tab(); }; } + if (!cw.xulG.inspect_tab) { cw.xulG.inspect_tab = function() { return window.xulG.inspect_tab(); }; } if (!cw.xulG.new_patron_tab) { cw.xulG.new_patron_tab = function(a,b) { return window.xulG.new_patron_tab(a,b); }; } if (!cw.xulG.set_patron_tab) { cw.xulG.set_patron_tab = function(a,b) { return window.xulG.set_patron_tab(a,b); }; } if (!cw.xulG.volume_item_creator) { cw.xulG.volume_item_creator = function(a) { return window.xulG.volume_item_creator(a); }; } diff --git a/Open-ILS/xul/staff_client/chrome/locale/en-US/offline.properties b/Open-ILS/xul/staff_client/chrome/locale/en-US/offline.properties index ba7a470e3..b94d60a9f 100644 --- a/Open-ILS/xul/staff_client/chrome/locale/en-US/offline.properties +++ b/Open-ILS/xul/staff_client/chrome/locale/en-US/offline.properties @@ -280,3 +280,5 @@ menu.tab7.accesskey=7 menu.tab8.accesskey=8 menu.tab9.accesskey=9 menu.tab10.accesskey=0 +menu.close_tab.unsaved_data_warning=This tab may have unsaved data. Close it anyway? +menu.replace_tab.unsaved_data_warning=This tab may have unsaved data. Replace it anyway? -- 2.11.0