dynamic Record Summary layout based on preference
authorJason Etheridge <jason@esilibrary.com>
Wed, 6 Jul 2011 07:19:09 +0000 (03:19 -0400)
committerBill Erickson <berick@esilibrary.com>
Mon, 18 Jul 2011 15:26:52 +0000 (11:26 -0400)
For now, you could add something like this to server/skin/custom.js to re-configure the display:

try {

    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
    var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces['nsIPrefBranch']);
    prefs.setCharPref(
        'oils.bib_brief.horizontal.dynamic_grid_replacement.data',
        js2JSON([
            ['title',           'edition',  'editor'],
            ['author',          'pubdate',  'edit_date'],
            ['bib_call_number', 'tcn',      'create_date']
        ])
    );

} catch(E) {
    dump('Error in custom.js trying to set oils.bib_brief.horizontal.dynamic_grid_replacement.data: ' + E + '\n');
}

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/locale/en-US/cat.properties

index 930e68c..b7c5c02 100644 (file)
@@ -5,6 +5,8 @@ function my_init(orientation) {
 
         ui_init(); // JSAN, etc.
 
+        if (! orientation) { orientation = 'horizontal'; }
+
         JSAN.use('OpenILS.data');
         g.data = new OpenILS.data();
         g.data.stash_retrieve();
@@ -52,6 +54,7 @@ function my_init(orientation) {
                                 try {
                                     g.meta = req2.getResultObject()[0];
                                     set_caption();
+                                    dynamic_grid_replacement(orientation);
                                     bib_brief_overlay({
                                         'mvr' : g.mods,
                                         'bre' : g.meta
@@ -202,3 +205,101 @@ function ui_init() {
     g.error.sdump('D_TRACE','my_init() for cat_bib_brief.xul');
 }
 
+function dynamic_grid_replacement(orientation) {
+    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+    var prefs = Components.classes[
+        '@mozilla.org/preferences-service;1'
+    ].getService(
+        Components.interfaces['nsIPrefBranch']
+    );
+    if (! prefs.prefHasUserValue(
+            'oils.bib_brief.'+orientation+'.dynamic_grid_replacement.data'
+        )
+    ) {
+        return;
+    }
+
+    var gridData = JSON2js(
+        prefs.getCharPref(
+            'oils.bib_brief.'+orientation+'.dynamic_grid_replacement.data'
+        )
+    );
+
+    var grid = document.getElementById('bib_brief_grid');
+    if (!grid) { return; }
+
+    JSAN.use('util.widgets');
+
+    util.widgets.remove_children(grid);
+
+    var columns = document.createElement('columns');
+    grid.appendChild(columns);
+
+    var maxColumns = 0;
+    for (var i = 0; i < gridData.length; i++) {
+        if (gridData[i].length > maxColumns) {
+            maxColumns = gridData[i].length;
+        }
+    }
+
+    for (var i = 0; i < maxColumns; i++) {
+        var columnA = document.createElement('column');
+        columns.appendChild(columnA);
+        var columnB = document.createElement('column');
+        columns.appendChild(columnB);
+    }
+
+    // Flex the column where the title usually goes
+    columns.firstChild.nextSibling.setAttribute('flex','1');
+
+    var rows = document.createElement('rows');
+    grid.appendChild(rows);
+
+/*
+    <row id="bib_brief_grid_row1" position="1">
+        <label control="title" class="emphasis"
+            value="&staff.cat.bib_brief.title.label;"
+            accesskey="&staff.cat.bib_brief.title.accesskey;"/>
+        <textbox id="title"
+            name="title" readonly="true" context="clipboard"
+            class="plain" onfocus="this.select()"/>
+    </row>
+*/
+
+    var catStrings = document.getElementById('catStrings');
+
+    for (var i = 0; i < gridData.length; i++) {
+        var row = document.createElement('row');
+        row.setAttribute('id','bib_brief_grid_row'+i);
+        rows.appendChild(row);
+
+        for (var j = 0; j < gridData[i].length; j++) {
+            var name = gridData[i][j];
+
+            var label = document.createElement('label');
+            label.setAttribute('control',name);
+            label.setAttribute('class','emphasis');
+            label.setAttribute('value',
+                catStrings.testString('staff.cat.bib_brief.'+name+'.label')
+                ? catStrings.getString('staff.cat.bib_brief.'+name+'.label')
+                : name
+            );
+            label.setAttribute('accesskey',
+                catStrings.testString('staff.cat.bib_brief.'+name+'.accesskey')
+                ? catStrings.getString('staff.cat.bib_brief.'+name+'.accesskey')
+                : name
+            );
+            row.appendChild(label);
+
+            var textbox = document.createElement('textbox');
+            textbox.setAttribute('id',name);
+            textbox.setAttribute('name',name);
+            textbox.setAttribute('readonly','true');
+            textbox.setAttribute('context','clipboard');
+            textbox.setAttribute('class','plain');
+            textbox.setAttribute('onfocus','this.select()');
+            row.appendChild(textbox);
+        }
+    }
+}
+
index f035034..fb389ca 100644 (file)
@@ -516,3 +516,27 @@ staff.cat.z3950.spawn_marc_editor_for_overlay.success_overlay=Record successfull
 staff.cat.z3950.spawn_marc_editor_for_overlay.overlay_error=Record not likely overlaid.
 staff.cat.z3950.load_creds.z3950_cred_error=Error retrieving stored z39.50 credentials
 staff.cat.z3950.save_creds.z3950_cred_error=Problem storing z39.50 credentials.
+staff.cat.bib_brief.title.label=Title:
+staff.cat.bib_brief.title.accesskey=
+staff.cat.bib_brief.author.label=Author:
+staff.cat.bib_brief.author.accesskey=
+staff.cat.bib_brief.edition.label=Edition:
+staff.cat.bib_brief.edition.accesskey=
+staff.cat.bib_brief.pubdate.label=Pub Date:
+staff.cat.bib_brief.pubdate.accesskey=
+staff.cat.bib_brief.bib_call_number.label=Bib Call #:
+staff.cat.bib_brief.bib_call_number.accesskey=
+staff.cat.bib_brief.tcn.label=TCN:
+staff.cat.bib_brief.tcn.accesskey=
+staff.cat.bib_brief.mvr_doc_id.label=Record ID:
+staff.cat.bib_brief.mvr_doc_id.accesskey=
+staff.cat.bib_brief.owner.label=Record Owner:
+staff.cat.bib_brief.owner.accesskey=
+staff.cat.bib_brief.creator.label=Created By:
+staff.cat.bib_brief.creator.accesskey=
+staff.cat.bib_brief.create_date.label=Created On:
+staff.cat.bib_brief.create_date.accesskey=
+staff.cat.bib_brief.editor.label=Last Edited By:
+staff.cat.bib_brief.editor.accesskey=
+staff.cat.bib_brief.edit_date.label=Last Edited On:
+staff.cat.bib_brief.edit_date.accesskey=