sort_type (number, money) hints for list columns
authorphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 14 Aug 2006 13:57:59 +0000 (13:57 +0000)
committerphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 14 Aug 2006 13:57:59 +0000 (13:57 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@5485 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/xul/staff_client/chrome/content/util/list.js
Open-ILS/xul/staff_client/server/circ/util.js
Open-ILS/xul/staff_client/server/patron/util.js

index 5aeab1b..7214c27 100644 (file)
@@ -832,6 +832,7 @@ util.list.prototype = {
                        obj.on_all_fleshed =
                                function() {
                                        try {
+                                               JSAN.use('util.money');
                                                var rows = [];
                                                var treeitems = obj.treechildren.childNodes;
                                                for (var i = 0; i < treeitems.length; i++) {
@@ -843,7 +844,23 @@ util.list.prototype = {
                                                        //alert('value = ' + value.value + ' node = ' + value.node);
                                                        rows.push( value );
                                                }
-                                               rows = rows.sort( function(a,b) { a = a.value; b = b.value; if (a < b) return -1; if (a > b) return 1; return 0; } );
+                                               rows = rows.sort( function(a,b) { 
+                                                       a = a.value; b = b.value; 
+                                                       if (col.getAttribute('sort_type')) {
+                                                               switch(col.getAttribute('sort_type')) {
+                                                                       case 'number' :
+                                                                               a = Number(a); b = Number(b);
+                                                                       break;
+                                                                       case 'money' :
+                                                                               a = util.money.dollars_float_to_cents_integer(a);
+                                                                               b = util.money.dollars_float_to_cents_integer(b);
+                                                                       break;
+                                                               }
+                                                       }
+                                                       if (a < b) return -1; 
+                                                       if (a > b) return 1; 
+                                                       return 0; 
+                                               } );
                                                if (sortDir == 'asc') rows = rows.reverse();
                                                while(obj.treechildren.lastChild) obj.treechildren.removeChild( obj.treechildren.lastChild );
                                                for (var i = 0; i < rows.length; i++) {
index 878a7aa..fd142f9 100644 (file)
@@ -134,7 +134,7 @@ circ.util.offline_checkout_columns = function(modify,params) {
                },
                {
                        'id' : 'noncat_count',
-                       'label' : 'Count',
+                       'label' : 'Count', 'sort_type' : 'number',
                        'flex' : 1, 'primary' : false, 'hidden' : false,
                        'render' : 'my.noncat_count'
                },
@@ -311,7 +311,7 @@ circ.util.offline_inhouse_use_columns = function(modify,params) {
                },
                {
                        'id' : 'count',
-                       'label' : 'Count',
+                       'label' : 'Count', 'sort_type' : 'number',
                        'flex' : 1, 'primary' : false, 'hidden' : false,
                        'render' : 'my.count'
                },
@@ -378,7 +378,7 @@ circ.util.columns = function(modify,params) {
                        'render' : 'if (Number(my.acn.owning_lib())>=0) obj.data.hash.aou[ my.acn.owning_lib() ].shortname(); else my.acn.owning_lib().shortname();', 'persist' : 'hidden width ordinal',
                },
                {
-                       'id' : 'copy_number', 'label' : getString('staff.acp_label_copy_number'), 'flex' : 1,
+                       'id' : 'copy_number', 'label' : getString('staff.acp_label_copy_number'), 'flex' : 1, 'sort_type' : 'number',
                        'primary' : false, 'hidden' : true, 'render' : 'my.acp.copy_number()', 'persist' : 'hidden width ordinal',
                },
                {
@@ -421,11 +421,11 @@ circ.util.columns = function(modify,params) {
                },
                {
                        'persist' : 'hidden width ordinal', 'id' : 'deposit_amount', 'label' : getString('staff.acp_label_deposit_amount'), 'flex' : 1,
-                       'primary' : false, 'hidden' : true, 'render' : 'my.acp.deposit_amount()'
+                       'primary' : false, 'hidden' : true, 'render' : 'util.money.sanitize(my.acp.deposit_amount())', 'sort_type' : 'money',
                },
                {
                        'persist' : 'hidden width ordinal', 'id' : 'price', 'label' : getString('staff.acp_label_price'), 'flex' : 1,
-                       'primary' : false, 'hidden' : true, 'render' : 'my.acp.price()'
+                       'primary' : false, 'hidden' : true, 'render' : 'util.money.sanitize(my.acp.price())', 'sort_type' : 'money',
                },
                {
                        'persist' : 'hidden width ordinal', 'id' : 'circ_as_type', 'label' : getString('staff.acp_label_circ_as_type'), 'flex' : 1,
@@ -481,7 +481,7 @@ circ.util.columns = function(modify,params) {
                },
                {
                        'persist' : 'hidden width ordinal', 'id' : 'renewal_remaining', 'label' : getString('staff.circ_label_renewal_remaining'), 'flex' : 0,
-                       'primary' : false, 'hidden' : true, 'render' : 'my.circ.renewal_remaining()'
+                       'primary' : false, 'hidden' : true, 'render' : 'my.circ.renewal_remaining()', 'sort_type' : 'number',
                },
                {
                        'persist' : 'hidden width ordinal', 'id' : 'stop_fines', 'label' : 'Fines Stopped', 'flex' : 0,
@@ -501,7 +501,7 @@ circ.util.columns = function(modify,params) {
                },
                {
                        'persist' : 'hidden width ordinal', 'id' : 'uses', 'label' : '# of Uses', 'flex' : 1,
-                       'primary' : false, 'hidden' : true, 'render' : 'my.uses'
+                       'primary' : false, 'hidden' : true, 'render' : 'my.uses', 'sort_type' : 'number',
                },
                {
                        'persist' : 'hidden width ordinal', 'id' : 'alert_message', 'label' : 'Alert Message', 'flex' : 1,
@@ -741,6 +741,7 @@ circ.util.std_map_row_to_column = function(error_value) {
                JSAN.use('util.error'); obj.error = new util.error();
                JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
                JSAN.use('util.network'); obj.network = new util.network();
+               JSAN.use('util.money');
 
                var my = row.my;
                var value;
index 0c2f957..a988059 100644 (file)
@@ -30,15 +30,18 @@ patron.util.mbts_columns = function(modify,params) {
                },
                {
                        'persist' : 'hidden width ordinal', 'id' : 'balance_owed', 'label' : 'Balance Owed', 'flex' : 1,
-                       'primary' : false, 'hidden' : false, 'render' : 'util.money.sanitize( my.mbts.balance_owed() )'
+                       'primary' : false, 'hidden' : false, 'render' : 'util.money.sanitize( my.mbts.balance_owed() )',
+                       'sort_type' : 'money',
                },
                {
                        'persist' : 'hidden width ordinal', 'id' : 'total_owed', 'label' : 'Total Billed', 'flex' : 1,
-                       'primary' : false, 'hidden' : false, 'render' : 'util.money.sanitize( my.mbts.total_owed() )'
+                       'primary' : false, 'hidden' : false, 'render' : 'util.money.sanitize( my.mbts.total_owed() )',
+                       'sort_type' : 'money',
                },
                {
                        'persist' : 'hidden width ordinal', 'id' : 'total_paid', 'label' : 'Total Paid', 'flex' : 1,
-                       'primary' : false, 'hidden' : false, 'render' : 'util.money.sanitize( my.mbts.total_paid() )'
+                       'primary' : false, 'hidden' : false, 'render' : 'util.money.sanitize( my.mbts.total_paid() )',
+                       'sort_type' : 'money',
                },
                {
                        'persist' : 'hidden width ordinal', 'id' : 'last_billing_note', 'label' : 'Last Billing Note', 'flex' : 2,
@@ -120,7 +123,8 @@ patron.util.mb_columns = function(modify,params) {
                },
                {
                        'persist' : 'hidden width ordinal', 'id' : 'amount', 'label' : 'Amount', 'flex' : 1,
-                       'primary' : false, 'hidden' : false, 'render' : 'util.money.sanitize( my.mb.amount() )'
+                       'primary' : false, 'hidden' : false, 'render' : 'util.money.sanitize( my.mb.amount() )',
+                       'sort_type' : 'money',
                },
                {
                        'persist' : 'hidden width ordinal', 'id' : 'billing_type', 'label' : 'Type', 'flex' : 1,
@@ -174,7 +178,8 @@ patron.util.mp_columns = function(modify,params) {
                },
                {
                        'persist' : 'hidden width ordinal', 'id' : 'amount', 'label' : 'Amount', 'flex' : 1,
-                       'primary' : false, 'hidden' : false, 'render' : 'util.money.sanitize( my.mp.amount() )'
+                       'primary' : false, 'hidden' : false, 'render' : 'util.money.sanitize( my.mp.amount() )',
+                       'sort_type' : 'money',
                },
                {
                        'persist' : 'hidden width ordinal', 'id' : 'payment_type', 'label' : 'Type', 'flex' : 1,
@@ -271,7 +276,8 @@ patron.util.columns = function(modify,params) {
                },
                { 
                        'persist' : 'hidden width ordinal', 'id' : 'claims_returned_count', 'label' : 'Returns Claimed', 'flex' : 1, 
-                       'primary' : false, 'hidden' : true, 'render' : 'my.au.claims_returned_count()'
+                       'primary' : false, 'hidden' : true, 'render' : 'my.au.claims_returned_count()',
+                       'sort_type' : 'number',
                },
                { 
                        'persist' : 'hidden width ordinal', 'id' : 'create_date', 'label' : 'Created On', 'flex' : 1, 
@@ -287,7 +293,8 @@ patron.util.columns = function(modify,params) {
                },
                { 
                        'persist' : 'hidden width ordinal', 'id' : 'credit_forward_balance', 'label' : 'Credit', 'flex' : 1, 
-                       'primary' : false, 'hidden' : true, 'render' : 'my.au.credit_forward_balance()'
+                       'primary' : false, 'hidden' : true, 'render' : 'my.au.credit_forward_balance()',
+                       'sort_type' : 'money',
                },
                { 
                        'persist' : 'hidden width ordinal', 'id' : 'day_phone', 'label' : 'Day Phone', 'flex' : 1,