[open-ils-commits] r12258 - in trunk/Open-ILS/xul/staff_client/chrome/content: main util (phasefx)
svn at svn.open-ils.org
svn at svn.open-ils.org
Sat Feb 21 20:19:56 EST 2009
Author: phasefx
Date: 2009-02-21 20:19:55 -0500 (Sat, 21 Feb 2009)
New Revision: 12258
Modified:
trunk/Open-ILS/xul/staff_client/chrome/content/main/menu.js
trunk/Open-ILS/xul/staff_client/chrome/content/main/menu_frame_overlay.xul
trunk/Open-ILS/xul/staff_client/chrome/content/util/network.js
Log:
backporting from staff-client-experiment: a network progress meter. It's not wired into the HTML interfaces embedded in the staff client
Modified: trunk/Open-ILS/xul/staff_client/chrome/content/main/menu.js
===================================================================
--- trunk/Open-ILS/xul/staff_client/chrome/content/main/menu.js 2009-02-22 01:19:04 UTC (rev 12257)
+++ trunk/Open-ILS/xul/staff_client/chrome/content/main/menu.js 2009-02-22 01:19:55 UTC (rev 12258)
@@ -2,15 +2,30 @@
// vim:noet:sw=4:ts=4:
var offlineStrings;
-offlineStrings = document.getElementById('offlineStrings');
if (typeof main == 'undefined') main = {};
main.menu = function () {
+ netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+ offlineStrings = document.getElementById('offlineStrings');
JSAN.use('util.error'); this.error = new util.error();
JSAN.use('util.window'); this.window = new util.window();
this.w = window;
+ var x = document.getElementById('network_progress');
+ x.setAttribute('count','0');
+ x.addEventListener(
+ 'click',
+ function() {
+ if ( window.confirm(offlineStrings.getString('menu.reset_network_stats')) ) {
+ var y = document.getElementById('network_progress_rows');
+ while(y.firstChild) { y.removeChild( y.lastChild ); }
+ x.setAttribute('mode','determined');
+ x.setAttribute('count','0');
+ }
+ },
+ false
+ );
}
main.menu.prototype = {
@@ -47,11 +62,13 @@
['oncommand'],
function() {
obj.data.stash_retrieve();
- obj.window.open(
+ var mframe = obj.window.open(
obj.url_prefix(urls.XUL_MENU_FRAME)
+ '?server='+window.escape(urls.remote),
'main' + obj.window.window_name_increment(),
'chrome,resizable');
+ netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+ mframe.xulG = xulG;
}
],
'cmd_new_tab' : [
@@ -499,6 +516,7 @@
obj.data.session = obj.data.previous_session;
obj.data.stash('session');
try {
+ netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var ios = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
var cookieUri = ios.newURI("http://" + obj.data.server_unadorned, null, null);
var cookieUriSSL = ios.newURI("https://" + obj.data.server_unadorned, null, null);
@@ -644,7 +662,7 @@
['oncommand'],
function() {
obj.data.stash_retrieve();
- obj.window.open(obj.url_prefix(urls.XUL_SURVEY_WIZARD),'survey_wizard','chrome');
+ xulG.window.open(obj.url_prefix(urls.XUL_SURVEY_WIZARD),'survey_wizard','chrome');
}
],
'cmd_public_opac' : [
@@ -664,6 +682,7 @@
['oncommand'],
function clear_the_cache() {
try {
+ netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var cacheClass = Components.classes["@mozilla.org/network/cache-service;1"];
var cacheService = cacheClass.getService(Components.interfaces.nsICacheService);
cacheService.evictEntries(Components.interfaces.nsICache.STORE_ON_DISK);
@@ -704,6 +723,7 @@
['oncommand'],
function() {
if (window.confirm(offlineStrings.getString('menu.cmd_shutdown.prompt'))) {
+ netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
var enumerator = windowManagerInterface.getEnumerator(null);
@@ -750,6 +770,7 @@
function(p) {
return function() {
try {
+ netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
if (p
&& p.firstChild
&& ( p.firstChild.nodeName == 'iframe' || p.firstChild.nodeName == 'browser' )
@@ -875,6 +896,60 @@
}
},
+ 'network_meter' : {
+ 'inc' : function(app,method) {
+ try {
+ var m = document.getElementById('network_progress');
+ var count = 1 + Number( m.getAttribute('count') );
+ m.setAttribute('mode','undetermined');
+ m.setAttribute('count', count);
+ var rows = document.getElementById('network_progress_rows');
+ var row = document.getElementById('network_progress_tip_'+app+'_'+method);
+ if (!row) {
+ row = document.createElement('row'); row.setAttribute('id','network_progress_tip_'+app+'_'+method);
+ var a = document.createElement('label'); a.setAttribute('value','App:');
+ var b = document.createElement('label'); b.setAttribute('value',app);
+ var c = document.createElement('label'); c.setAttribute('value','Method:');
+ var d = document.createElement('label'); d.setAttribute('value',method);
+ var e = document.createElement('label'); e.setAttribute('value','Total:');
+ var f = document.createElement('label'); f.setAttribute('value','0');
+ f.setAttribute('id','network_progress_tip_total_'+app+'_'+method);
+ var g = document.createElement('label'); g.setAttribute('value','Outstanding:');
+ var h = document.createElement('label'); h.setAttribute('value','0');
+ h.setAttribute('id','network_progress_tip_out_'+app+'_'+method);
+ row.appendChild(a); row.appendChild(b); row.appendChild(c);
+ row.appendChild(d); row.appendChild(e); row.appendChild(f);
+ row.appendChild(g); row.appendChild(h); rows.appendChild(row);
+ }
+ var total = document.getElementById('network_progress_tip_total_'+app+'_'+method);
+ if (total) {
+ total.setAttribute('value', 1 + Number( total.getAttribute('value') ));
+ }
+ var out = document.getElementById('network_progress_tip_out_'+app+'_'+method);
+ if (out) {
+ out.setAttribute('value', 1 + Number( out.getAttribute('value') ));
+ }
+ } catch(E) {
+ dump('network_meter.inc(): ' + E + '\n');
+ }
+ },
+ 'dec' : function(app,method) {
+ try {
+ var m = document.getElementById('network_progress');
+ var count = -1 + Number( m.getAttribute('count') );
+ if (count < 0) count = 0;
+ if (count == 0) m.setAttribute('mode','determined');
+ m.setAttribute('count', count);
+ var out = document.getElementById('network_progress_tip_out_'+app+'_'+method);
+ if (out) {
+ out.setAttribute('value', -1 + Number( out.getAttribute('value') ));
+ }
+ } catch(E) {
+ dump('network_meter.dec(): ' + E + '\n');
+ }
+ }
+ },
+
'set_tab' : function(url,params,content_params) {
var obj = this;
if (!url) url = '/xul/server/';
@@ -891,8 +966,10 @@
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.set_tab_name = function(name) { tab.setAttribute('label',(idx + 1) + ' ' + name); };
- content_params.open_chrome_window = function(a,b,c) { return obj.window.open(a,b,c); };
+ content_params.open_chrome_window = function(a,b,c) { return xulG.window.open(a,b,c); };
content_params.url_prefix = function(url) { return obj.url_prefix(url); };
+ content_params.network_meter = obj.network_meter;
+ content_params.chrome_xulG = xulG;
if (params && params.tab_name) content_params.set_tab_name( params.tab_name );
var frame;
Modified: trunk/Open-ILS/xul/staff_client/chrome/content/main/menu_frame_overlay.xul
===================================================================
--- trunk/Open-ILS/xul/staff_client/chrome/content/main/menu_frame_overlay.xul 2009-02-22 01:19:04 UTC (rev 12257)
+++ trunk/Open-ILS/xul/staff_client/chrome/content/main/menu_frame_overlay.xul 2009-02-22 01:19:55 UTC (rev 12258)
@@ -39,7 +39,28 @@
<tabpanel id="panel_9"><label value="panel_9"/></tabpanel>
</tabpanels>
</tabbox>
- <toolbox id="entity_toolbox"/>
+ <statusbar>
+ <statusbarpanel />
+ <spacer flex="1" />
+ <progressmeter id="network_progress" flex="1" mode="determined" value="0" tooltip="network_progress_tip"/>
+ <statusbarpanel />
+ </statusbar>
+ <tooltip id="network_progress_tip" noautohide="true">
+ <grid>
+ <columns>
+ <column/>
+ <column/>
+ <column/>
+ <column flex="1"/>
+ <column/>
+ <column/>
+ <column/>
+ <column/>
+ </columns>
+ <rows id="network_progress_rows">
+ </rows>
+ </grid>
+ </tooltip>
</box>
<!-- The main top level menubar -->
Modified: trunk/Open-ILS/xul/staff_client/chrome/content/util/network.js
===================================================================
--- trunk/Open-ILS/xul/staff_client/chrome/content/util/network.js 2009-02-22 01:19:04 UTC (rev 12257)
+++ trunk/Open-ILS/xul/staff_client/chrome/content/util/network.js 2009-02-22 01:19:55 UTC (rev 12258)
@@ -89,6 +89,12 @@
'\noverride_params = ' + override_params + '\n_params = ' + _params +
'\nResult #' + (++obj.link_id) + ( f ? ' asynced' : ' synced' ) );
+ if (document.getElementById('network_progress')) {
+ if (g && g.menu && g.menu.network_meter && typeof g.menu.network_meter.inc == 'function') g.menu.network_meter.inc(app,name);
+ } else if (typeof xulG != 'undefined') {
+ if (xulG && xulG.network_meter && typeof xulG.network_meter.inc == 'function') xulG.network_meter.inc(app,name);
+ }
+
var request = new RemoteRequest( app, name );
if (_params && _params.secure) {
request.setSecure(true);
@@ -106,6 +112,13 @@
try {
var duration = ( (new Date).getTime() - start_timer )/1000;
if ( obj.get_result(req) == null && duration > obj.network_timeout ) req.cancelled = true;
+
+ if (document.getElementById('network_progress')) {
+ if (g && g.menu && g.menu.network_meter && typeof g.menu.network_meter.dec == 'function') g.menu.network_meter.dec(app,name);
+ } else if (typeof xulG != 'undefined') {
+ if (xulG && xulG.network_meter && typeof xulG.network_meter.dec == 'function') xulG.network_meter.dec(app,name);
+ }
+
var json_string = js2JSON(obj.get_result(req));
obj.error.sdump('D_SES_RESULT','asynced result #'
+ obj.link_id + '\n\n'
@@ -140,6 +153,13 @@
request.send(true);
var duration = ( (new Date).getTime() - start_timer )/1000;
if ( obj.get_result(request) == null && duration > obj.network_timeout ) request.cancelled = true;
+
+ if (document.getElementById('network_progress')) {
+ if (g && g.menu && g.menu.network_meter && typeof g.menu.network_meter.dec == 'function') g.menu.network_meter.dec(app,name);
+ } else if (typeof xulG != 'undefined') {
+ if (xulG && xulG.network_meter && typeof xulG.network_meter.dec == 'function') xulG.network_meter.dec(app,name);
+ }
+
} catch(E) {
throw(E);
}
@@ -450,7 +470,39 @@
} catch(E) {
throw(E);
}
- }
+ },
+
+ 'ping' : function() {
+ try {
+ JSAN.use('util.file'); JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
+ var file = new util.file('ping.bat');
+ var path = file._file.path;
+ file.write_content('truncate+exec',
+ '#!/bin/sh\n' +
+ 'ping -n 15 ' + data.server_unadorned + ' > "' + path + '.txt"\n' + /* windows */
+ 'ping -c 15 ' + data.server_unadorned + ' >> "' + path + '.txt"\n' /* unix */
+ );
+ file.close();
+ file = new util.file('ping.bat');
+
+ var process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
+ process.init(file._file);
+
+ var args = [];
+
+ dump('process.run = ' + process.run(true, args, args.length) + '\n');
+
+ file.close();
+
+ var file = new util.file('ping.bat.txt');
+ var output = file.get_content();
+ file.close();
+
+ return output;
+ } catch(E) {
+ alert(E);
+ }
+ }
}
/*
More information about the open-ils-commits
mailing list