some refactoring in prep for dynamic Record Summary layout
authorJason Etheridge <jason@esilibrary.com>
Wed, 6 Jul 2011 06:32:01 +0000 (02:32 -0400)
committerBill Erickson <berick@esilibrary.com>
Mon, 18 Jul 2011 15:26:47 +0000 (11:26 -0400)
Signed-off-by: Jason Etheridge <jason@esilibrary.com>
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/xul/staff_client/server/cat/bib_brief.js
Open-ILS/xul/staff_client/server/cat/bib_brief_overlay.xul
Open-ILS/xul/staff_client/server/cat/bib_brief_vertical.xul

index 44bc145..930e68c 100644 (file)
@@ -1,21 +1,24 @@
 var docid;
 
-function my_init() {
+function my_init(orientation) {
     try {
-        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-        if (typeof JSAN == 'undefined') { throw( document.getElementById("commonStrings").getString('common.jsan.missing') ); }
-        JSAN.errorLevel = "die"; // none, warn, or die
-        JSAN.addRepository('/xul/server/');
-        JSAN.use('util.error'); g.error = new util.error();
-        g.error.sdump('D_TRACE','my_init() for cat_bib_brief.xul');
 
-        JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
+        ui_init(); // JSAN, etc.
+
+        JSAN.use('OpenILS.data');
+        g.data = new OpenILS.data();
+        g.data.stash_retrieve();
 
         docid = xul_param('docid');
 
+        // hackery if modal and invoked with util.window
         var key = location.pathname + location.search + location.hash;
-        if (!docid && typeof g.data.modal_xulG_stack != 'undefined' && typeof g.data.modal_xulG_stack[key] != 'undefined') {
-            var xulG = g.data.modal_xulG_stack[key][ g.data.modal_xulG_stack[key].length - 1 ];
+        if (!docid
+            && typeof g.data.modal_xulG_stack != 'undefined'
+            && typeof g.data.modal_xulG_stack[key] != 'undefined'
+        ) {
+            var xulG = g.data.modal_xulG_stack[key][
+                g.data.modal_xulG_stack[key].length - 1 ];
             if (typeof xulG == 'object') {
                 docid = xulG.docid;
             }
@@ -24,7 +27,12 @@ function my_init() {
         JSAN.use('util.network'); g.network = new util.network();
         JSAN.use('util.date');
 
-        document.getElementById('caption').setAttribute('tooltiptext',document.getElementById('catStrings').getFormattedString('staff.cat.bib_brief.record_id', [docid]));
+        document.getElementById('caption').setAttribute(
+            'tooltiptext',
+            document.getElementById('catStrings').getFormattedString(
+                'staff.cat.bib_brief.record_id', [docid]
+            )
+        );
 
         if (docid > -1) {
 
@@ -34,48 +42,36 @@ function my_init() {
                 'MODS_SLIM_RECORD_RETRIEVE.authoritative',
                 [ docid ],
                 function (req) {
-                    var mods = req.getResultObject();
-                    
-                    if (window.xulG && typeof window.xulG.set_tab_name == 'function') {
-                        try {
-                            window.xulG.set_tab_name(mods.tcn());
-                        } catch(E) {
-                            g.error.sdump('D_ERROR','bib_brief.xul, set_tab: ' + E);
-                        }
-                    }
-
-                    g.network.simple_request(
-                        'FM_BRE_RETRIEVE_VIA_ID.authoritative',
-                        [ ses(), [ docid ] ],
-                        function (req) {
-                            try {
-                                var meta = req.getResultObject();
-                                if (typeof meta.ilsevent != 'undefined') throw(meta);
-                                meta = meta[0];
-                                var t = document.getElementById('caption').getAttribute('label');
-                                if (get_bool( meta.deleted() )) { 
-                                    t += ' ' + document.getElementById('catStrings').getString('staff.cat.bib_brief.deleted') + ' '; 
-                                    document.getElementById('caption').setAttribute('style','background: red; color: white;');
+                    try {
+                        g.mods = req.getResultObject();
+                        set_tab_name();
+                        g.network.simple_request(
+                            'FM_BRE_RETRIEVE_VIA_ID.authoritative',
+                            [ ses(), [ docid ] ],
+                            function (req2) {
+                                try {
+                                    g.meta = req2.getResultObject()[0];
+                                    set_caption();
+                                    bib_brief_overlay({
+                                        'mvr' : g.mods,
+                                        'bre' : g.meta
+                                    });
+                                } catch(E) {
+                                    alert('Error in bib_brief.js, '
+                                        + 'req handler 2: ' + E + '\n');
                                 }
-                                if ( ! get_bool( meta.active() ) ) { 
-                                    t += ' ' + document.getElementById('catStrings').getString('staff.cat.bib_brief.inactive') + ' '; 
-                                    document.getElementById('caption').setAttribute('style','background: red; color: white;');
-                                }
-                                document.getElementById('caption').setAttribute('label',t);
-
-                                bib_brief_overlay( { 'mvr' : mods, 'bre' : meta } );
-
-                            } catch(E) {
-                                g.error.standard_unexpected_error_alert('meta retrieve',E);
                             }
-                        }
-                    );
+                        );
+                    } catch(E) {
+                        alert('Error in bib_brief.js, req handler 1: '
+                            + E + '\n');
+                    }
                 }
             );
 
         } else {
             var t = document.getElementById('caption').getAttribute('label');
-            t += ' ' + document.getElementById('catStrings').getString('staff.cat.bib_brief.noncat') + ' '; 
+            t += ' ' + document.getElementById('catStrings').getString('staff.cat.bib_brief.noncat') + ' ';
             document.getElementById('caption').setAttribute('style','background: red; color: white;');
             document.getElementById('caption').setAttribute('label',t);
         }
@@ -87,6 +83,32 @@ function my_init() {
     }
 }
 
+function set_tab_name() {
+    try {
+        window.xulG.set_tab_name(g.mods.tcn());
+    } catch(E) {
+        dump('Error in bib_brief.js, set_tab_name(): ' + E + '\n');
+    }
+}
+
+function set_caption() {
+    try {
+        var t = document.getElementById('caption').getAttribute('label');
+        if (get_bool( g.meta.deleted() )) {
+            t += ' ' + document.getElementById('catStrings').getString('staff.cat.bib_brief.deleted') + ' ';
+            document.getElementById('caption').setAttribute('style','background: red; color: white;');
+        }
+        if ( ! get_bool( g.meta.active() ) ) {
+            t += ' ' + document.getElementById('catStrings').getString('staff.cat.bib_brief.inactive') + ' ';
+            document.getElementById('caption').setAttribute('style','background: red; color: white;');
+        }
+        document.getElementById('caption').setAttribute('label',t);
+
+    } catch(E) {
+        dump('Error in bib_brief.js, set_caption(): ' + E + '\n');
+    }
+}
+
 function unhide_add_volumes_button() {
     if (xulG && typeof xulG == 'object' && typeof xulG['new_tab'] == 'function') {
         document.getElementById('add_volumes').hidden = false;
@@ -164,3 +186,19 @@ function add_volumes() {
         alert('Error in server/cat/bib_brief.js, add_volumes(): ' + E);
     }
 }
+
+function ui_init() {
+    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+    if (typeof JSAN == 'undefined') {
+        throw(
+            document.getElementById("commonStrings").getString(
+                'common.jsan.missing'
+            )
+        );
+    }
+    JSAN.errorLevel = "die"; // none, warn, or die
+    JSAN.addRepository('/xul/server/');
+    JSAN.use('util.error'); g.error = new util.error();
+    g.error.sdump('D_TRACE','my_init() for cat_bib_brief.xul');
+}
+
index 7d89b69..f2a1939 100644 (file)
@@ -8,7 +8,7 @@
         <script type="text/javascript" src="/xul/server/cat/bib_brief_overlay.js"/>
 
         <grid id="bib_brief_grid" flex="0">
-            <columns>
+            <columns id="bib_brief_grid_columns">
                 <column />
                 <column flex="1" />
                 <column />
@@ -29,7 +29,7 @@
                     <label value="&staff.cat.bib_brief.created_by.label;" accesskey="&staff.cat.bib_brief.created_by.accesskey;" control="creator" class="emphasis"/>
                     <textbox id="creator" name="creator" readonly="true" context="clipboard" class="plain" onfocus="this.select()"/>
                 </row>
-                <row position="2">
+                <row id="bib_brief_grid_row2" position="2">
                     <label value="&staff.cat.bib_brief.author.label;" accesskey="&staff.cat.bib_brief.author.accesskey;" control="author" class="emphasis"/>
                     <textbox id="author" name="author" readonly="true" context="clipboard" class="plain" onfocus="this.select()"/>
                     <label value="&staff.cat.bib_brief.pub_date.label;" accesskey="&staff.cat.bib_brief.pub_date.accesskey;" control="pubdate" class="emphasis"/>
index 15ed851..b742d20 100644 (file)
@@ -22,7 +22,7 @@ vim: noet:sw=4:ts=4:
 <?xul-overlay href="/xul/server/cat/bib_brief_overlay_vertical.xul"?>
 
 <window id="cat_bib_brief_win" 
-    onload="try { my_init(); font_helper(); persist_helper(); } catch(E) { alert(E); }"
+    onload="try { my_init('vertical'); font_helper(); persist_helper(); } catch(E) { alert(E); }"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
     <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->