XBL for a <help> widget. It will try to load help content from various static and...
authorphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 12 Apr 2010 21:40:54 +0000 (21:40 +0000)
committerphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 12 Apr 2010 21:40:54 +0000 (21:40 +0000)
at the first one that it finds.  If for example, I were to add this to /xul/server/patron/display.xul:

    <help id="bar" src="foo.html" />

We would get a "Help" button that if clicked would then it would test these locations:

    foo.html (if @foo not set, then custom_help.html)
    /xul/server/patron/display.xul.help.html
    /xul/server/patron/help.html
    /xul/server/help.html
    /xul/help.html
    /help.html

and since @id is defined, it would also tack on ?id=bar (for log tracking and/or dynamic use by the content).

It will open the location in a non-modal pop-up window.  Navigation buttons not included.

MAYBE TODO:
    Add an @anchor for dynamically appending a hash component to each URL tested.
    Implement a browser with Back/Forward/Search/Index functionality.

git-svn-id: svn://svn.open-ils.org/ILS/trunk@16220 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/xul/staff_client/chrome/content/main/bindings.xml
Open-ILS/xul/staff_client/chrome/skin/global.css
Open-ILS/xul/staff_client/server/skin/global.css

index 1bf2c10..6e702be 100644 (file)
@@ -5,6 +5,113 @@
    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 (if @foo not set, then custom_help.html)
+                    // /xul/server/patron/display.xul.help.html
+                    // /xul/server/patron/help.html
+                    // /xul/server/help.html
+                    // /xul/help.html
+                    // /help.html
+
+                    this.addEventListener( 'command', function(ev) { this._open_window(); }, false);
+                } catch(E) {
+                    alert('Error constructing help widget in bindings.xml: ' + E);
+                    throw(E);
+                }
+                ]]>
+            </constructor>
+
+            <property name="src">
+                <getter>
+                    <![CDATA[
+                    try {
+                        return this.getAttribute('src');
+                    } catch(E) {
+                        alert('Error getting @src in help widget in bindings.xml: ' + E);
+                        throw(E);
+                    }
+                    ]]>
+                </getter>
+                <setter>
+                    <![CDATA[
+                    try {
+                        this.setAttribute('src',val);
+                        return val;
+                    } catch(E) {
+                        alert('Error setting @src in help widget in bindings.xml: ' + E);
+                        throw(E);
+                    }
+                    ]]>
+                </setter>
+            </property>
+
+            <method name="_open_window">
+                <body>
+                    <![CDATA[
+                    try {
+                            var x = new XMLHttpRequest();
+                            x.open("HEAD",this.src || 'custom_help.html',false);
+                            x.send(null);
+                            if (x.status == 200) {
+                                window.open((this.src || 'custom_help.html')+'?id='+this.id,this.getAttribute('label'),'resizable,scrollbars');
+                            } else {
+                                var pathname = location.pathname;
+                                x.open("HEAD",pathname + '.help.html',false);
+                                x.send(null);
+                                if (x.status == 200) {
+                                    window.open(pathname+'.help.html?id='+this.id,this.getAttribute('label'),'resizable,scrollbars');
+                                } else {
+                                    var pathparts = pathname.split('/');
+                                    var url; 
+                                    for (var i = pathparts.length - 2; i>0 && x.status != 200; i--) {
+                                        url = '';
+                                        for ( j = 1; j <= i; j++ ) { url += '/' + pathparts[j]; };
+                                        url = url + '/help.html';
+                                        x.open("HEAD",url,false);
+                                        x.send(null);
+                                    }
+                                    if (x.status == 200) {
+                                        window.open(url+'?id='+this.id,this.getAttribute('label'),'resizable,scrollbars');
+                                    } else {
+                                        x.open("HEAD","/help.html",false);
+                                        x.send(null);
+                                        if (x.status == 200) {
+                                            window.open('/help.html?id='+this.id,this.getAttribute('label'),'resizable,scrollbars');
+                                        } 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/>
 
index cde1de2..91a56ad 100644 (file)
@@ -17,6 +17,7 @@ iframe { background: #CDCED3 url("chrome://browser/skin/icons/box-background.png
 
 .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'); }
 
 .my_overflow { overflow: auto; }
 
index cdc252d..519cc60 100644 (file)
@@ -3,6 +3,7 @@
 @namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); 
 @namespace html url("http://www.w3.org/TR/REC-html40"); 
 
+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'); }