Checked in patch for bug 245849

This commit is contained in:
mostafah%oeone.com 2004-06-11 16:11:08 +00:00
Родитель 2a3de33335
Коммит b3587f5e87
2 изменённых файлов: 95 добавлений и 27 удалений

Просмотреть файл

@ -471,6 +471,7 @@ var treeView =
rowCount : gEventArray.length,
selectedColumn : null,
sortDirection : null,
sortStartedTime : new Date().getTime(), // updated just before sort
isContainer : function(){return false;},
getCellProperties : function(){return false;},
@ -517,9 +518,9 @@ var treeView =
}
element.setAttribute("sortActive", sortActive);
element.setAttribute("sortDirection", this.sortDirection);
//dump( "\nabout to sort events "+gEventArray.length );
gEventArray.sort( sortEvents );
//dump( "\nSORTED!");
this.sortStartedTime = new Date().getTime(); // for null/0 dates in sort
gEventArray.sort( compareEvents );
document.getElementById( UnifinderTreeName ).view = this;
},
setTree : function( tree ){this.tree = tree;},
@ -596,7 +597,7 @@ var treeView =
}
}
function sortEvents( EventA, EventB )
function compareEvents( eventA, eventB )
{
var modifier = 1;
if (treeView.sortDirection == "descending")
@ -607,28 +608,56 @@ function sortEvents( EventA, EventB )
switch(treeView.selectedColumn)
{
case "unifinder-search-results-tree-col-title":
return( ((EventA.title > EventB.title) ? 1 : -1) * modifier );
return compareString(eventA.title, eventB.title) * modifier;
case "unifinder-search-results-tree-col-startdate":
return( ((EventA.start.getTime() > EventB.start.getTime()) ? 1 : -1) * modifier );
return compareDate(eventA.start, eventB.start) * modifier;
case "unifinder-search-results-tree-col-enddate":
return( ((EventA.end.getTime() > EventB.end.getTime()) ? 1 : -1) * modifier );
return compareDate(eventA.end, eventB.end) * modifier;
case "unifinder-search-results-tree-col-categories":
return( ((EventA.categories > EventB.categories) ? 1 : -1) * modifier );
return compareString(eventA.categories, eventB.categories) * modifier;
case "unifinder-search-results-tree-col-location":
return( ((EventA.location > EventB.location) ? 1 : -1) * modifier );
return compareString(eventA.location, eventB.location) * modifier;
case "unifinder-search-results-tree-col-status":
return( ((EventA.status > EventB.status) ? 1 : -1) * modifier );
return compareString(eventA.status, eventB.status) * modifier;
default:
return true;
return 0;
}
}
function compareString(a, b) {
a = nullToEmpty(a);
b = nullToEmpty(b);
return ((a < b) ? -1 :
(a > b) ? 1 : 0);
}
function nullToEmpty(value) {
return value == null? "" : value;
}
function compareDate(a, b) {
a = dateToMilliseconds(a);
b = dateToMilliseconds(b);
return ((a < b) ? -1 : // avoid underflow problems of subtraction
(a > b) ? 1 : 0);
}
function dateToMilliseconds(date) {
// Treat null/0 as 'now' when sort started, so incomplete tasks stay current.
// Time is computed once per sort (just before sort) so sort is stable.
if (date == null)
return treeView.sortStartedTime;
var ms = date.getTime(); // note: date is not a javascript date.
if (ms == -62171262000000) // ms value for (0000/00/00 00:00:00)
return treeView.sortStartedTime;
return ms;
}
function calendarEventView( eventArray )
{
@ -664,7 +693,8 @@ function refreshEventTree( eventArray )
{
treeView.selectedColumn = ArrayOfTreeCols[i].getAttribute( "id" );
treeView.sortDirection = ArrayOfTreeCols[i].getAttribute("sortDirection");
gEventArray.sort(sortEvents);
treeView.sortStartedTime = new Date().getTime(); //for null/0 dates
gEventArray.sort(compareEvents);
break;
}
}

Просмотреть файл

@ -282,6 +282,7 @@ var toDoTreeView =
rowCount : gEventArray.length,
selectedColumn : null,
sortDirection : null,
sortStartedTime : new Date().getTime(), // updated just before sort
isContainer : function(){return false;},
// By getCellProperties, the properties defined with
@ -372,7 +373,9 @@ var toDoTreeView =
}
element.setAttribute("sortActive", sortActive);
element.setAttribute("sortDirection", this.sortDirection);
gTaskArray.sort( sortTasks );
this.sortStartedTime = new Date().getTime(); // for null dates during sort
gTaskArray.sort( compareTasks );
document.getElementById( ToDoUnifinderTreeName ).view = this;
},
setTree : function( tree ){this.tree = tree;},
@ -414,7 +417,7 @@ var toDoTreeView =
}
}
function sortTasks( TaskA, TaskB )
function compareTasks( taskA, taskB )
{
var modifier = 1;
if (toDoTreeView.sortDirection == "descending")
@ -424,34 +427,68 @@ function sortTasks( TaskA, TaskB )
switch(toDoTreeView.selectedColumn)
{
case "unifinder-todo-tree-col-completed":
return( ((TaskA.completed.getTime() > TaskB.completed.getTime()) ? 1 : -1) * modifier );
case "unifinder-todo-tree-col-priority":
return( ((TaskA.priority > TaskB.priority) ? 1 : -1) * modifier );
case "unifinder-todo-tree-col-priority": // 0-9
return compareNumber(taskA.priority, taskB.priority) * modifier;
case "unifinder-todo-tree-col-title":
return( ((TaskA.title > TaskB.title) ? 1 : -1) * modifier );
return compareString(taskA.title, taskB.title) * modifier;
case "unifinder-todo-tree-col-startdate":
return( ((TaskA.start.getTime() > TaskB.start.getTime()) ? 1 : -1) * modifier );
return compareDate(taskA.start, taskB.start) * modifier;
case "unifinder-todo-tree-col-duedate":
return( ((TaskA.due.getTime() > TaskB.due.getTime()) ? 1 : -1) * modifier );
return compareDate(taskA.due, taskB.due) * modifier;
case "unifinder-todo-tree-col-completed": // checkbox if date exists
case "unifinder-todo-tree-col-completeddate":
return( ((TaskA.completed.getTime() > TaskB.completed.getTime()) ? 1 : -1) * modifier );
return compareDate(taskA.completed, taskB.completed) * modifier;
case "unifinder-todo-tree-col-percentcomplete":
return( ((TaskA.percent > TaskB.percent) ? 1 : -1) * modifier );
return compareNumber(taskA.percent, taskB.percent) * modifier;
case "unifinder-todo-tree-col-categories":
return( ((TaskA.categories > TaskB.categories) ? 1 : -1) * modifier );
return compareString(taskA.categories, taskB.categories) * modifier;
default:
return true;
return 0;
}
}
function compareString(a, b) {
a = nullToEmpty(a);
b = nullToEmpty(b);
return ((a < b) ? -1 :
(a > b) ? 1 : 0);
}
function nullToEmpty(value) {
return value == null? "" : value;
}
function compareNumber(a, b) {
// Number converts a date to msecs since 1970, and converts a null to 0.
a = Number(a);
b = Number(b);
return ((a < b) ? -1 : // avoid underflow problems of subtraction
(a > b) ? 1 : 0);
}
function compareDate(a, b) {
a = dateToMilliseconds(a);
b = dateToMilliseconds(b);
return ((a < b) ? -1 : // avoid underflow problems of subtraction
(a > b) ? 1 : 0);
}
function dateToMilliseconds(date) {
// Treat null/0 as 'now' when sort started, so incomplete tasks stay current.
// Time is computed once per sort (just before sort) so sort is stable.
if (date == null)
return treeView.sortStartedTime;
var ms = date.getTime(); // note: date is not a javascript date.
if (ms == -62171262000000) // ms value for (0000/00/00 00:00:00)
return treeView.sortStartedTime;
return ms;
}
function calendarTaskView( taskArray )
{
@ -494,7 +531,8 @@ function refreshToDoTree( taskArray )
{
toDoTreeView.selectedColumn = ArrayOfTreeCols[i].getAttribute( "id" );
toDoTreeView.sortDirection = ArrayOfTreeCols[i].getAttribute("sortDirection");
gTaskArray.sort(sortTasks);
toDoTreeView.sortStartedTime = new Date().getTime(); //for null/0 dates
gTaskArray.sort(compareTasks);
break;
}
}