Add destructor to <messagecatalog>
authorJason Etheridge <jason@esilibrary.com>
Sat, 26 Jan 2013 14:40:47 +0000 (09:40 -0500)
committerJason Etheridge <jason@esilibrary.com>
Sat, 26 Jan 2013 14:40:47 +0000 (09:40 -0500)
And move <help> binding to separate file and just have menu_frame.xul load it
for now.  This really reduces the initial memory footprint of the staff client,
but it doesn't addresses all leaks--after having watched the process list after
many interations since I don't quite grok all the debugging tools.  I wanted to
try replacing messagecatalog with the native stringbundle, which Galen confirmed
works with the oils:// protocol, but I ran into some trouble.  That might be
another experiment worth pursuing.

Signed-off-by: Jason Etheridge <jason@esilibrary.com>
Open-ILS/xul/staff_client/chrome/content/main/bindings.xml
Open-ILS/xul/staff_client/chrome/content/main/help_binding.xml [new file with mode: 0644]
Open-ILS/xul/staff_client/chrome/skin/global.css
Open-ILS/xul/staff_client/server/skin/global.css

index 35f179e..337e8be 100644 (file)
@@ -5,125 +5,6 @@
    xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    xmlns:xbl="http://www.mozilla.org/xbl">
 
-    <binding id="help">
-        <resources/>
-
-        <content>
-            <!-- FIXME: I18N -->
-            <xul:button label="Help" accesskey="H" xbl:inherits="label,accesskey" />
-        </content>
-
-        <implementation>
-
-            <constructor>
-                <![CDATA[
-                try {
-                    // This widget will try to load help content from various static and dynamic URL's, stopping at the
-                    // first one that it finds.  Given an example location.href of '/xul/server/patron/display.xul' and
-                    // a @src of 'foo.html', it will check these URL's in this order:
-                    //
-                    // foo.html
-                    // /xul/server/patron/display.xul.custom_help.html
-                    // /xul/server/patron/display.xul.help.html
-                    // /xul/server/patron/custom_help.html
-                    // /xul/server/patron/help.html
-                    // /xul/server/custom_help.html
-                    // /xul/server/help.html
-                    // /xul/custom_help.html
-                    // /xul/help.html
-                    // /custom_help.html
-                    // /help.html
-                    //
-                    // If @pathname is specified, it will override the value from location.pathname
-                    // If @hostname is specified, it will override the value from location.hostname
-                    // If @port is specified, it will override the value from location.port
-                    // If @protocol is specified, it will override the value from location.protocol
-
-                    this.addEventListener( 'command', function(ev) { this._open_window(); }, false);
-                } catch(E) {
-                    alert('Error constructing help widget in bindings.xml: ' + E);
-                    throw(E);
-                }
-                ]]>
-            </constructor>
-
-            <method name="_open_window">
-                <body>
-                    <![CDATA[
-                    try {
-
-                            var obj = this;
-                            var protocol = obj.getAttribute('protocol') || location.protocol;
-                            var hostname = obj.getAttribute('hostname') || location.hostname;
-                            var port = obj.getAttribute('port') || location.port;
-                            var pathname = obj.getAttribute('pathname') || location.pathname;
-
-                            function test_url(loc) {
-                                if (loc == '/' || !loc) { return false; }
-                                var x = new XMLHttpRequest();
-                                var url = protocol + '//' + hostname + ( port ? ':' + port : '' ) + loc;
-                                dump('help widget: testing <'+url+'>\n');
-                                x.open("HEAD", url, false);
-                                x.send(null);
-                                return x.status == 200;
-                            }
-
-                            function open_url(loc) {
-                                var url = protocol + '//' + hostname + ( port ? ':' + port : '' ) + loc +'?id='+obj.id;
-                                dump('help widget: opening <'+url+'>\n');
-                                window.open(url, obj.getAttribute('label'), 'resizable,scrollbars');
-                            }
-
-                            if (test_url('/'+this.getAttribute('src'))) {
-                                open_url('/'+this.getAttribute('src'));
-                            } else {
-                                if (test_url(pathname + '.custom_help.html')) {
-                                    open_url(pathname + '.custom_help.html');
-                                } else {
-                                    if (test_url(pathname + '.help.html')) {
-                                        open_url(pathname + '.help.html');
-                                    } else {
-                                        var pathparts = pathname.split('/');
-                                        var base_url; var url; var test_result;
-                                        for (var i = pathparts.length - 2; i>0 && !test_result; i--) {
-                                            base_url = ''; url = '';
-                                            for ( j = 1; j <= i; j++ ) { base_url += '/' + pathparts[j]; };
-                                            url = base_url + '/custom_help.html';
-                                            test_result = test_url(url);
-                                            if (!test_result) {
-                                                url = base_url + '/help.html';
-                                                test_result = test_url(url);
-                                            }
-                                        }
-                                        if (test_result) {
-                                            open_url(url);
-                                        } else {
-                                            if (test_url("/custom_help.html")) {
-                                                open_url("/custom_help.html");
-                                            } else {
-                                                if (test_url("/help.html")) {
-                                                    open_url("/help.html");
-                                                } else {
-                                                    /* FIXME - I18N */
-                                                    alert('No Help Found');
-                                                }
-                                            }
-                                        }
-                                    }
-                                }
-                            }
-                    } catch(E) {
-                        alert('Error opening window in help widget in bindings.xml: ' + E);
-                        throw(E);
-                    }
-                    ]]>
-                </body>
-            </method>
-
-        </implementation>
-    </binding>
-
-
        <binding id="messagecatalog">
                <resources/>
 
                                ]]>
                        </constructor>
 
+                       <destructor>
+                               <![CDATA[
+                try {
+                        delete this._props;
+                        delete this.sprintf;
+                } catch(E) {
+                    alert('Error destructing messagecatalog in bindings.xml: ' + E);
+                    throw(E);
+                }
+
+                               ]]>
+                       </destructor>
+
                        <property name="src">
                                <getter>
                                        <![CDATA[
                </implementation>
        </binding>
 
-       <binding id="caption" extends="chrome://global/content/bindings/general.xml#basetext">
-               <resources>
-                       <stylesheet src="chrome://global/skin/groupbox.css"/>
-               </resources>
-
-               <content>
-                       <children>
-                               <xul:image
-                                       onclick="
-                                               var n = document.getAnonymousNodes(parentNode.parentNode)[1];
-                                               if (n.hidden) {
-                                                       n.hidden = false;
-                                                       this.setAttribute('src','chrome://open_ils_staff_client/skin/media/images/opentriangle.gif');
-                                               } else {
-                                                       n.hidden = true;
-                                                       this.setAttribute('src','chrome://open_ils_staff_client/skin/media/images/triangle.gif');
-                                               }
-                                       "
-                               />
-                               <xul:image class="caption-icon" xbl:inherits="src=image"/>
-                               <xul:label class="caption-text" flex="1" xbl:inherits="default,value=label,crop,accesskey" />
-                       </children>
-               </content>
-
-               <implementation>
-                       <constructor>
-                               <![CDATA[
-                                       var n = document.getAnonymousNodes(this)[0];
-                                       n.setAttribute('src','chrome://open_ils_staff_client/skin/media/images/opentriangle.gif');
-                               ]]>
-                       </constructor>
-               </implementation>
-       </binding>
-
 </bindings>
diff --git a/Open-ILS/xul/staff_client/chrome/content/main/help_binding.xml b/Open-ILS/xul/staff_client/chrome/content/main/help_binding.xml
new file mode 100644 (file)
index 0000000..143c755
--- /dev/null
@@ -0,0 +1,126 @@
+<?xml version="1.0"?>
+
+<bindings id="openils_bindings2"
+   xmlns="http://www.mozilla.org/xbl"
+   xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+   xmlns:xbl="http://www.mozilla.org/xbl">
+
+    <binding id="help">
+        <resources/>
+
+        <content>
+            <!-- FIXME: I18N -->
+            <xul:button label="Help" accesskey="H" xbl:inherits="label,accesskey" />
+        </content>
+
+        <implementation>
+
+            <constructor>
+                <![CDATA[
+                try {
+                    // This widget will try to load help content from various static and dynamic URL's, stopping at the
+                    // first one that it finds.  Given an example location.href of '/xul/server/patron/display.xul' and
+                    // a @src of 'foo.html', it will check these URL's in this order:
+                    //
+                    // foo.html
+                    // /xul/server/patron/display.xul.custom_help.html
+                    // /xul/server/patron/display.xul.help.html
+                    // /xul/server/patron/custom_help.html
+                    // /xul/server/patron/help.html
+                    // /xul/server/custom_help.html
+                    // /xul/server/help.html
+                    // /xul/custom_help.html
+                    // /xul/help.html
+                    // /custom_help.html
+                    // /help.html
+                    //
+                    // If @pathname is specified, it will override the value from location.pathname
+                    // If @hostname is specified, it will override the value from location.hostname
+                    // If @port is specified, it will override the value from location.port
+                    // If @protocol is specified, it will override the value from location.protocol
+
+                    this.addEventListener( 'command', function(ev) { this._open_window(); }, false);
+                } catch(E) {
+                    alert('Error constructing help widget in bindings.xml: ' + E);
+                    throw(E);
+                }
+                ]]>
+            </constructor>
+
+            <method name="_open_window">
+                <body>
+                    <![CDATA[
+                    try {
+
+                            var obj = this;
+                            var protocol = obj.getAttribute('protocol') || location.protocol;
+                            var hostname = obj.getAttribute('hostname') || location.hostname;
+                            var port = obj.getAttribute('port') || location.port;
+                            var pathname = obj.getAttribute('pathname') || location.pathname;
+
+                            function test_url(loc) {
+                                if (loc == '/' || !loc) { return false; }
+                                var x = new XMLHttpRequest();
+                                var url = protocol + '//' + hostname + ( port ? ':' + port : '' ) + loc;
+                                dump('help widget: testing <'+url+'>\n');
+                                x.open("HEAD", url, false);
+                                x.send(null);
+                                return x.status == 200;
+                            }
+
+                            function open_url(loc) {
+                                var url = protocol + '//' + hostname + ( port ? ':' + port : '' ) + loc +'?id='+obj.id;
+                                dump('help widget: opening <'+url+'>\n');
+                                window.open(url, obj.getAttribute('label'), 'resizable,scrollbars');
+                            }
+
+                            if (test_url('/'+this.getAttribute('src'))) {
+                                open_url('/'+this.getAttribute('src'));
+                            } else {
+                                if (test_url(pathname + '.custom_help.html')) {
+                                    open_url(pathname + '.custom_help.html');
+                                } else {
+                                    if (test_url(pathname + '.help.html')) {
+                                        open_url(pathname + '.help.html');
+                                    } else {
+                                        var pathparts = pathname.split('/');
+                                        var base_url; var url; var test_result;
+                                        for (var i = pathparts.length - 2; i>0 && !test_result; i--) {
+                                            base_url = ''; url = '';
+                                            for ( j = 1; j <= i; j++ ) { base_url += '/' + pathparts[j]; };
+                                            url = base_url + '/custom_help.html';
+                                            test_result = test_url(url);
+                                            if (!test_result) {
+                                                url = base_url + '/help.html';
+                                                test_result = test_url(url);
+                                            }
+                                        }
+                                        if (test_result) {
+                                            open_url(url);
+                                        } else {
+                                            if (test_url("/custom_help.html")) {
+                                                open_url("/custom_help.html");
+                                            } else {
+                                                if (test_url("/help.html")) {
+                                                    open_url("/help.html");
+                                                } else {
+                                                    /* FIXME - I18N */
+                                                    alert('No Help Found');
+                                                }
+                                            }
+                                        }
+                                    }
+                                }
+                            }
+                    } catch(E) {
+                        alert('Error opening window in help widget in bindings.xml: ' + E);
+                        throw(E);
+                    }
+                    ]]>
+                </body>
+            </method>
+
+        </implementation>
+    </binding>
+
+</bindings>
index 85e3d1f..a47ab8d 100644 (file)
@@ -15,9 +15,8 @@ iframe { background: #CDCED3 url("chrome://browser/skin/icons/box-background.png
 
 .operator_change { background-color: red; }
 
-.shrinkable_groupbox { font-weight: bold; -moz-binding: url('chrome://open_ils_staff_client/content/main/bindings.xml#caption'); }
 messagecatalog { -moz-binding: url('chrome://open_ils_staff_client/content/main/bindings.xml#messagecatalog'); }
-help { -moz-binding: url('chrome://open_ils_staff_client/content/main/bindings.xml#help'); }
+help { -moz-binding: url('chrome://open_ils_staff_client/content/main/help_binding.xml#help'); }
 
 .my_overflow { overflow: auto; }
 
index f8a6ad1..ec95be9 100644 (file)
@@ -4,9 +4,7 @@
 @namespace html url("http://www.w3.org/TR/REC-html40"); 
 @namespace xhtml url("http://www.w3.org/1999/xhtml"); 
 
-help { -moz-binding: url('/xul/server/main/bindings.xml#help'); }
 messagecatalog { -moz-binding: url('/xul/server/main/bindings.xml#messagecatalog'); }
-.shrinkable_groupbox { font-weight: bold; -moz-binding: url('/xul/server/main/bindings.xml#caption'); }
 
 window:not([active="true"]) menubar > menu { color: menutext !important }