From 70cd1772c19fb5f334ecd0cae5aadf6c224a4a07 Mon Sep 17 00:00:00 2001 From: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com> Date: Wed, 2 May 2012 14:01:00 -0400 Subject: [PATCH] Fix date sorting in patron-related XUL interfaces Null time stamps are now converted to dates in the Middle Paleolithic era so they always sort as the lowest date. Seriously, this is the minimum possible date you can express with a JavaScript date object. Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com> Signed-off-by: Jason Etheridge <jason@esilibrary.com> --- Open-ILS/xul/staff_client/chrome/content/util/date.js | 6 ++++-- Open-ILS/xul/staff_client/server/patron/util.js | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Open-ILS/xul/staff_client/chrome/content/util/date.js b/Open-ILS/xul/staff_client/chrome/content/util/date.js index cf176271b9..fb95bee5a9 100644 --- a/Open-ILS/xul/staff_client/chrome/content/util/date.js +++ b/Open-ILS/xul/staff_client/chrome/content/util/date.js @@ -46,8 +46,10 @@ util.date.timer_elapsed = function (id) { } util.date.db_date2Date = function (db_date) { - if (!db_date) { return db_date; } - if (typeof window.dojo != 'undefined') { + if (!db_date) { /* we get stringified null at times */ + return new Date(-8640000000000000); /* minimum possible date. + max is this * -1. */ + } else if (typeof window.dojo != 'undefined') { dojo.require('dojo.date.stamp'); return dojo.date.stamp.fromISOString( db_date.replace( /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[\+-]\d{2})(\d{2})$/, '$1:$2') ); } else { diff --git a/Open-ILS/xul/staff_client/server/patron/util.js b/Open-ILS/xul/staff_client/server/patron/util.js index f6f2cd01b4..f97437d99a 100644 --- a/Open-ILS/xul/staff_client/server/patron/util.js +++ b/Open-ILS/xul/staff_client/server/patron/util.js @@ -570,6 +570,7 @@ patron.util.std_map_row_to_columns = function(error_value) { var my = row.my; var values = []; + var sort_values = []; var cmd = ''; try { for (var i = 0; i < cols.length; i++) { @@ -578,13 +579,28 @@ patron.util.std_map_row_to_columns = function(error_value) { case 'string' : cmd += 'try { ' + cols[i].render + '; values['+i+'] = v; } catch(E) { values['+i+'] = error_value; }'; break; default: cmd += 'values['+i+'] = "??? '+(typeof cols[i].render)+'"; '; } + switch (typeof cols[i].sort_value) { + case 'function': + try { + sort_values[i] = cols[i].sort_value(my,scratch); + } catch(E) { + sort_values[i] = error_value; + obj.error.sdump('D_COLUMN_RENDER_ERROR',E); + } + break; + case 'string' : + sort_values[i] = JSON2js(cols[i].sort_value); + break; + default: + cmd += 'sort_values['+i+'] = values[' + i + '];'; + } } if (cmd) eval( cmd ); } catch(E) { obj.error.sdump('D_WARN','map_row_to_column: ' + E); if (error_value) { value = error_value; } else { value = ' ' }; } - return values; + return {values: values, sort_values: sort_values}; } } -- 2.11.0