adds a Line# column to all xul lists
authorJason Etheridge <jason@esilibrary.com>
Mon, 12 Mar 2012 20:06:51 +0000 (16:06 -0400)
committerMike Rylander <mrylander@gmail.com>
Mon, 19 Mar 2012 14:05:50 +0000 (10:05 -0400)
displays the ordinal position of the row

Signed-off-by: Jason Etheridge <jason@esilibrary.com>
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/xul/staff_client/chrome/content/util/list.js
Open-ILS/xul/staff_client/chrome/locale/en-US/offline.properties
Open-ILS/xul/staff_client/server/skin/global.css

index 1a270c8..6dcc359 100644 (file)
@@ -51,7 +51,23 @@ util.list.prototype = {
         if (typeof params.prebuilt != 'undefined') obj.prebuilt = params.prebuilt;
 
         if (typeof params.columns == 'undefined') throw('util.list.init: No columns');
-        obj.columns = [];
+        obj.columns = [
+            {
+                'id' : 'lineno',
+                'label' : document.getElementById('offlineStrings').getString('list.line_number'),
+                'flex' : '0',
+                'no_sort' : 'true',
+                'properties' : 'ordinal', // column properties for css styling
+                'hidden' : 'false',
+                'editable' : false,
+                'render' : function(my,scratch) {
+                    // special code will handle this based on the attribute we set
+                    // here.  All cells for this column need to be updated whenever
+                    // a list adds, removes, or sorts rows
+                    return '_';
+                }
+            }
+        ];
         for (var i = 0; i < params.columns.length; i++) {
             if (typeof params.columns[i] == 'object') {
                 obj.columns.push( params.columns[i] );
@@ -611,7 +627,7 @@ util.list.prototype = {
             } catch(E) {
             }
 
-        setTimeout( function() { obj.auto_retrieve(); }, 0 );
+        setTimeout( function() { obj.auto_retrieve(); obj.refresh_ordinals(); }, 0 );
 
         params.treeitem_node = treeitem;
         return params;
@@ -773,7 +789,7 @@ util.list.prototype = {
             } catch(E) {
             }
 
-        setTimeout( function() { obj.auto_retrieve(); }, 0 );
+        setTimeout( function() { obj.auto_retrieve(); obj.refresh_ordinals(); }, 0 );
 
         JSAN.use('util.widgets'); util.widgets.dispatch('select',obj.node);
 
@@ -782,6 +798,37 @@ util.list.prototype = {
         return params;
     },
 
+    'refresh_ordinals' : function() {
+        var obj = this;
+        try {
+            setTimeout( // Otherwise we can miss a row just added
+                function() {
+                    var nl = document.getElementsByAttribute('label','_');
+                    for (var i = 0; i < nl.length; i++) {
+                        nl[i].setAttribute(
+                            'ord_col',
+                            'true'
+                        );
+                        nl[i].setAttribute( // treecell properties for css styling
+                            'properties',
+                            'ordinal'
+                        );
+                    }
+                    nl = document.getElementsByAttribute('ord_col','true');
+                    for (var i = 0; i < nl.length; i++) {
+                        nl[i].setAttribute(
+                            'label',
+                            // we could just use 'i' here if we trust the order of elements
+                            1 + obj.node.contentView.getIndexOfItem(nl[i].parentNode.parentNode) // treeitem
+                        );
+                    }
+                }, 1000
+            );
+        } catch(E) {
+            alert('Error in list.js, refresh_ordinals(): ' + E);
+        }
+    },
+
     'put_retrieving_label' : function(treerow) {
         var obj = this;
         try {
@@ -1512,7 +1559,7 @@ util.list.prototype = {
     '_sort_tree' : function(col,sortDir) {
         var obj = this;
         try {
-            if (obj.node.getAttribute('no_sort')) {
+            if (obj.node.getAttribute('no_sort') || col.getAttribute('no_sort')) {
                 return;
             }
             var col_pos;
@@ -1592,6 +1639,7 @@ util.list.prototype = {
                     } catch(E) {
                         obj.error.standard_unexpected_error_alert('sorting',E); 
                     }
+                    obj.refresh_ordinals();
                 }
             );
         } catch(E) {
index eaef490..71485fc 100644 (file)
@@ -224,6 +224,7 @@ list.actions.csv_to_file.accesskey=F
 list.actions.save_column_configuration.label=Save Column Configuration
 list.actions.save_column_configuration.accesskey=S
 list.dump_extended_format.record_separator==-=-=
+list.line_number=#
 menu.cmd_survey_wizard.inadequate_perm=You are lacking the CREATE_SURVEY permission and/or working locations.
 menu.cmd_local_admin_fonts_and_sounds.tab=Global Font and Sound Settings
 menu.cmd_local_admin_printer.tab=Printer Settings Editor
index 1c9da3e..ee08b6c 100644 (file)
@@ -19,6 +19,13 @@ treechildren::-moz-tree-row(selected) {
     border: thin dashed lightblue ! important;
 }
 
+treechildren::-moz-tree-column(ordinal) {
+    background: -moz-dialog ! important;
+}
+
+treechildren::-moz-tree-cell-text(ordinal) {
+    font-weight: bold ! important;
+}
 /*
 treechildren::-moz-tree-cell-text(selected,focus) {
     color: black;