2002-06-27 21:59:51 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is OEone Calendar Code, released October 31st, 2001.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* OEone Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2001
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): Garth Smedley <garths@oeone.com>
|
|
|
|
* Mike Potter <mikep@oeone.com>
|
|
|
|
* Chris Charabaruk <coldacid@meldstar.com>
|
|
|
|
* Colin Phillips <colinp@oeone.com>
|
2002-07-30 23:19:50 +04:00
|
|
|
* ArentJan Banck <ajbanck@planet.nl>
|
2003-01-09 18:03:08 +03:00
|
|
|
* Curtis Jewell <csjewell@mail.freeshell.org>
|
2003-02-13 16:59:37 +03:00
|
|
|
* Eric Belhaire <eric.belhaire@ief.u-psud.fr>
|
2003-03-12 21:21:34 +03:00
|
|
|
* Mark Swaffer <swaff@fudo.org>
|
2002-06-27 21:59:51 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------
|
|
|
|
* U N I F I N D E R
|
|
|
|
*
|
|
|
|
* This is a hacked in interface to the unifinder. We will need to
|
|
|
|
* improve this to make it usable in general.
|
|
|
|
*/
|
|
|
|
|
2002-07-31 19:02:35 +04:00
|
|
|
const ToDoUnifinderTreeName = "unifinder-todo-tree";
|
2005-05-24 23:26:11 +04:00
|
|
|
const kStatusOrder = ["NEEDS-ACTION", "IN-PROCESS", "COMPLETED", "CANCELLED"];
|
2002-06-27 21:59:51 +04:00
|
|
|
|
2002-10-30 20:16:52 +03:00
|
|
|
var gTaskArray = new Array();
|
|
|
|
|
2002-06-27 21:59:51 +04:00
|
|
|
/**
|
|
|
|
* Observer for the calendar event data source. This keeps the unifinder
|
|
|
|
* display up to date when the calendar event data is changed
|
|
|
|
*/
|
|
|
|
|
|
|
|
var unifinderToDoDataSourceObserver =
|
|
|
|
{
|
2005-05-11 18:52:00 +04:00
|
|
|
mInBatch: false,
|
|
|
|
|
|
|
|
QueryInterface: function (aIID) {
|
|
|
|
if (!aIID.equals(Components.interfaces.nsISupports) &&
|
|
|
|
!aIID.equals(Components.interfaces.calICompositeObserver) &&
|
|
|
|
!aIID.equals(Components.interfaces.calIObserver))
|
|
|
|
{
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
2005-01-05 01:49:12 +03:00
|
|
|
},
|
2002-06-27 21:59:51 +04:00
|
|
|
|
2005-05-11 18:52:00 +04:00
|
|
|
onStartBatch: function() {
|
|
|
|
this.mInBatch = true;
|
|
|
|
},
|
|
|
|
onEndBatch: function() {
|
|
|
|
this.mInBatch = false;
|
2005-01-05 01:49:12 +03:00
|
|
|
toDoUnifinderRefresh();
|
|
|
|
},
|
2005-05-11 18:52:00 +04:00
|
|
|
onLoad: function() {
|
|
|
|
if (!this.mInBatch)
|
|
|
|
refreshEventTree();
|
|
|
|
},
|
|
|
|
onAddItem: function(aItem) {
|
|
|
|
if (aItem instanceof Components.interfaces.calITodo &&
|
|
|
|
!this.mInBatch)
|
2005-01-05 01:49:12 +03:00
|
|
|
toDoUnifinderRefresh();
|
|
|
|
},
|
2005-05-11 18:52:00 +04:00
|
|
|
onModifyItem: function(aNewItem, aOldItem) {
|
|
|
|
if (aNewItem instanceof Components.interfaces.calITodo &&
|
|
|
|
!this.mInBatch)
|
2005-01-05 01:49:12 +03:00
|
|
|
toDoUnifinderRefresh();
|
|
|
|
},
|
2005-05-11 18:52:00 +04:00
|
|
|
onDeleteItem: function(aDeletedItem) {
|
|
|
|
if (aDeletedItem instanceof Components.interfaces.calITodo &&
|
|
|
|
!this.mInBatch)
|
2005-01-05 01:49:12 +03:00
|
|
|
toDoUnifinderRefresh();
|
|
|
|
},
|
2005-05-11 18:52:00 +04:00
|
|
|
onAlarm: function(aAlarmItem) {},
|
|
|
|
onError: function(aMessage) {},
|
2005-01-05 01:49:12 +03:00
|
|
|
|
2005-05-11 18:52:00 +04:00
|
|
|
onCalendarAdded: function(aDeletedItem) {
|
|
|
|
if (!this.mInBatch)
|
|
|
|
toDoUnifinderRefresh();
|
|
|
|
},
|
|
|
|
onCalendarRemoved: function(aDeletedItem) {
|
|
|
|
if (!this.mInBatch)
|
|
|
|
toDoUnifinderRefresh();
|
|
|
|
},
|
|
|
|
onDefaultCalendarChanged: function(aNewDefaultCalendar) {}
|
2002-06-27 21:59:51 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the calendar is loaded
|
|
|
|
*/
|
|
|
|
|
2005-01-05 01:49:12 +03:00
|
|
|
function prepareCalendarToDoUnifinder()
|
2002-06-27 21:59:51 +04:00
|
|
|
{
|
2005-04-10 22:59:15 +04:00
|
|
|
var ccalendar = getDisplayComposite();
|
2005-04-15 22:51:47 +04:00
|
|
|
ccalendar.addObserver(unifinderToDoDataSourceObserver);
|
2005-01-05 01:49:12 +03:00
|
|
|
toDoUnifinderRefresh();
|
2002-06-27 21:59:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the calendar is unloaded
|
|
|
|
*/
|
|
|
|
|
2005-01-05 01:49:12 +03:00
|
|
|
function finishCalendarToDoUnifinder()
|
2002-06-27 21:59:51 +04:00
|
|
|
{
|
2005-04-10 22:59:15 +04:00
|
|
|
var ccalendar = getDisplayComposite();
|
|
|
|
ccalendar.removeObserver(unifinderToDoDataSourceObserver);
|
2002-06-27 21:59:51 +04:00
|
|
|
}
|
|
|
|
|
2004-08-03 00:54:10 +04:00
|
|
|
/**
|
|
|
|
* Helper function to display todo datetimes in the unifinder
|
|
|
|
*/
|
|
|
|
|
2005-01-05 01:49:12 +03:00
|
|
|
function formatUnifinderToDoDateTime(aDateTime)
|
2004-08-03 00:54:10 +04:00
|
|
|
{
|
2005-01-05 01:49:12 +03:00
|
|
|
// datetime is from todo object, it is not a javascript date
|
|
|
|
if (aDateTime && aDateTime.isValid)
|
|
|
|
return gCalendarWindow.dateFormater.formatDateTime(aDateTime.jsDate, true);
|
2004-08-04 17:10:46 +04:00
|
|
|
return "";
|
2004-08-03 00:54:10 +04:00
|
|
|
}
|
2002-06-27 21:59:51 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by event observers to update the display
|
|
|
|
*/
|
|
|
|
|
2002-08-27 16:34:47 +04:00
|
|
|
function toDoUnifinderRefresh()
|
2002-06-27 21:59:51 +04:00
|
|
|
{
|
2005-01-05 01:49:12 +03:00
|
|
|
var hideCompleted = document.getElementById("hide-completed-checkbox").checked;
|
|
|
|
|
|
|
|
var savedThis = this;
|
|
|
|
var refreshListener = {
|
|
|
|
mTaskArray: new Array(),
|
|
|
|
|
|
|
|
onOperationComplete: function (aCalendar, aStatus, aOperationType, aId, aDateTime) {
|
|
|
|
setTimeout(function () { refreshToDoTree (refreshListener.mTaskArray); }, 0);
|
|
|
|
},
|
|
|
|
|
|
|
|
onGetResult: function (aCalendar, aStatus, aItemType, aDetail, aCount, aItems) {
|
|
|
|
for (var i = 0; i < aCount; i++) {
|
|
|
|
refreshListener.mTaskArray.push(aItems[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2005-04-10 22:59:15 +04:00
|
|
|
var ccalendar = getDisplayComposite();
|
2005-01-05 01:49:12 +03:00
|
|
|
var filter = 0;
|
|
|
|
if (hideCompleted)
|
2005-04-10 22:59:15 +04:00
|
|
|
filter |= ccalendar.ITEM_FILTER_COMPLETED_NO;
|
2005-01-05 01:49:12 +03:00
|
|
|
else
|
2005-04-10 22:59:15 +04:00
|
|
|
filter |= ccalendar.ITEM_FILTER_COMPLETED_ALL;
|
2005-01-05 01:49:12 +03:00
|
|
|
|
2005-04-10 22:59:15 +04:00
|
|
|
filter |= ccalendar.ITEM_FILTER_TYPE_TODO;
|
2005-01-05 01:49:12 +03:00
|
|
|
|
2005-04-10 22:59:15 +04:00
|
|
|
ccalendar.getItems(filter, 0, null, null, refreshListener);
|
2002-06-27 21:59:51 +04:00
|
|
|
}
|
|
|
|
|
2002-07-31 19:02:35 +04:00
|
|
|
function getToDoFromEvent( event )
|
|
|
|
{
|
|
|
|
var tree = document.getElementById( ToDoUnifinderTreeName );
|
|
|
|
|
2004-04-17 09:53:38 +04:00
|
|
|
var row = tree.treeBoxObject.getRowAt( event.clientX, event.clientY );
|
|
|
|
|
|
|
|
if( row != -1 && row < tree.view.rowCount )
|
2002-07-31 19:02:35 +04:00
|
|
|
{
|
2004-04-17 09:53:38 +04:00
|
|
|
return( tree.taskView.getCalendarTaskAtRow( row ) );
|
2002-07-31 19:02:35 +04:00
|
|
|
}
|
2002-11-27 18:20:28 +03:00
|
|
|
return false;
|
2002-07-31 19:02:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function getSelectedToDo()
|
|
|
|
{
|
|
|
|
var tree = document.getElementById( ToDoUnifinderTreeName );
|
|
|
|
// .toDo object sometimes isn't available?
|
2002-10-30 20:16:52 +03:00
|
|
|
return( tree.taskView.getCalendarTaskAtRow(tree.currentIndex) );
|
|
|
|
|
2002-07-31 19:02:35 +04:00
|
|
|
}
|
|
|
|
|
2002-06-27 21:59:51 +04:00
|
|
|
/**
|
|
|
|
* This is attached to the onclik attribute of the to do list shown in the unifinder
|
|
|
|
*/
|
|
|
|
|
2002-10-30 20:16:52 +03:00
|
|
|
function modifyToDoCommand( event )
|
2002-06-27 21:59:51 +04:00
|
|
|
{
|
2003-02-13 18:56:09 +03:00
|
|
|
// we only care about button 0 (left click) events
|
|
|
|
if (event.button != 0) return;
|
|
|
|
|
2002-08-02 18:54:26 +04:00
|
|
|
//open the edit todo dialog box
|
2002-07-31 19:02:35 +04:00
|
|
|
var ThisToDo = getToDoFromEvent( event );
|
2003-02-05 22:38:28 +03:00
|
|
|
|
2002-07-31 19:02:35 +04:00
|
|
|
if( ThisToDo )
|
2002-08-02 18:54:26 +04:00
|
|
|
editToDo( ThisToDo );
|
2003-03-14 23:35:47 +03:00
|
|
|
else
|
|
|
|
newToDoCommand();
|
2002-08-02 18:54:26 +04:00
|
|
|
}
|
2002-06-27 21:59:51 +04:00
|
|
|
|
2002-08-02 18:54:26 +04:00
|
|
|
/**
|
|
|
|
* Set the context menu on mousedown to change it before it is opened
|
|
|
|
*/
|
|
|
|
|
|
|
|
function unifinderMouseDownToDo( event )
|
|
|
|
{
|
|
|
|
var tree = document.getElementById( ToDoUnifinderTreeName );
|
|
|
|
var treechildren = tree.getElementsByTagName( "treechildren" )[0];
|
|
|
|
|
|
|
|
var ThisToDo = getToDoFromEvent( event );
|
|
|
|
if( ThisToDo )
|
|
|
|
{
|
|
|
|
// TODO HACK notifiers should be rewritten to integrate events and todos
|
2003-01-31 21:26:19 +03:00
|
|
|
document.getElementById( "delete_todo_command" ).removeAttribute( "disabled" );
|
2002-08-16 00:14:46 +04:00
|
|
|
document.getElementById( "print_command" ).setAttribute( "disabled", "true" );
|
2002-08-02 18:54:26 +04:00
|
|
|
} else
|
|
|
|
{
|
2004-04-17 09:53:38 +04:00
|
|
|
tree.view.selection.clearSelection();
|
2002-08-02 18:54:26 +04:00
|
|
|
|
|
|
|
// TODO HACK notifiers should be rewritten to integrate events and todos
|
2003-01-31 21:26:19 +03:00
|
|
|
document.getElementById( "delete_todo_command" ).setAttribute( "disabled", "true" );
|
2002-08-16 00:14:46 +04:00
|
|
|
// printing tasks not supported
|
|
|
|
document.getElementById( "print_command" ).setAttribute( "disabled", "true" );
|
2002-08-02 18:54:26 +04:00
|
|
|
}
|
2002-06-27 21:59:51 +04:00
|
|
|
}
|
|
|
|
|
2005-01-05 01:49:12 +03:00
|
|
|
function checkboxClick(thisTodo, completed)
|
2002-06-27 21:59:51 +04:00
|
|
|
{
|
2005-01-05 01:49:12 +03:00
|
|
|
var newTodo = thisTodo.clone().QueryInterface(Components.interfaces.calITodo);
|
|
|
|
if(completed) {
|
2005-07-04 21:06:04 +04:00
|
|
|
newTodo.completedDate = jsDateToDateTime(new Date());
|
2005-01-05 01:49:12 +03:00
|
|
|
newTodo.percentComplete = 100;
|
|
|
|
} else {
|
2005-07-04 21:06:04 +04:00
|
|
|
newTodo.completedDate = null;
|
2005-01-05 01:49:12 +03:00
|
|
|
if (newTodo.percentComplete == 100)
|
|
|
|
newTodo.percentComplete = 0;
|
|
|
|
}
|
|
|
|
|
2005-06-04 00:46:36 +04:00
|
|
|
doTransaction('modify', newTodo, newTodo.calendar, thisTodo, null);
|
2002-06-27 21:59:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-13 16:59:37 +03:00
|
|
|
/*
|
|
|
|
This function return the progress state of a ToDo task :
|
2003-03-12 21:21:34 +03:00
|
|
|
completed, overdue, duetoday, inprogress, future
|
2003-02-13 16:59:37 +03:00
|
|
|
*/
|
2005-01-05 01:49:12 +03:00
|
|
|
function ToDoProgressAtom( aTodo )
|
2002-10-30 20:16:52 +03:00
|
|
|
{
|
2004-08-03 02:23:16 +04:00
|
|
|
var now = new Date();
|
2005-01-05 01:49:12 +03:00
|
|
|
var completed = (aTodo.percentComplete == 100);
|
|
|
|
|
|
|
|
if (completed)
|
|
|
|
return "completed";
|
|
|
|
|
2005-06-16 13:23:41 +04:00
|
|
|
if (aTodo.dueDate && aTodo.dueDate.isValid) {
|
2005-01-05 01:49:12 +03:00
|
|
|
if (aTodo.dueDate.jsDate.getTime() < now.getTime())
|
|
|
|
return "overdue";
|
|
|
|
else if (aTodo.dueDate.year == now.getFullYear() &&
|
|
|
|
aTodo.dueDate.month == now.getMonth() &&
|
|
|
|
aTodo.dueDate.day == now.getDate())
|
|
|
|
return "duetoday";
|
2004-08-03 02:23:16 +04:00
|
|
|
}
|
2005-01-05 01:49:12 +03:00
|
|
|
|
2005-06-16 13:23:41 +04:00
|
|
|
if (aTodo.entryDate && aTodo.entryDate.isValid &&
|
2005-01-05 01:49:12 +03:00
|
|
|
aTodo.entryDate.jsDate.getTime() < now.getTime())
|
2004-08-03 02:23:16 +04:00
|
|
|
return "inprogress";
|
2005-01-05 01:49:12 +03:00
|
|
|
|
2004-08-03 02:23:16 +04:00
|
|
|
return "future";
|
2003-02-13 16:59:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
var toDoTreeView =
|
|
|
|
{
|
2005-01-05 01:49:12 +03:00
|
|
|
rowCount : gTaskArray.length,
|
2003-02-13 16:59:37 +03:00
|
|
|
selectedColumn : null,
|
|
|
|
sortDirection : null,
|
2004-06-11 20:11:08 +04:00
|
|
|
sortStartedTime : new Date().getTime(), // updated just before sort
|
2003-02-13 16:59:37 +03:00
|
|
|
|
|
|
|
isContainer : function(){return false;},
|
|
|
|
// By getCellProperties, the properties defined with
|
|
|
|
// treechildren:-moz-tree-cell-text in CSS are used.
|
|
|
|
// It is use here to color a particular row with a color
|
|
|
|
// given by the progress state of the ToDo task.
|
|
|
|
getCellProperties : function( row,column, props )
|
|
|
|
{
|
|
|
|
calendarToDo = gTaskArray[row];
|
2004-10-26 23:30:50 +04:00
|
|
|
var aserv=Components.classes["@mozilla.org/atom-service;1"].getService(Components.interfaces.nsIAtomService);
|
2003-02-13 16:59:37 +03:00
|
|
|
|
2004-06-15 17:30:43 +04:00
|
|
|
// Moz1.8 trees require column.id, moz1.7 and earlier trees use column.
|
2004-08-03 01:02:30 +04:00
|
|
|
if( (typeof(column)=="object" ? column.id : column) == "unifinder-todo-tree-col-priority" )
|
2003-02-13 16:59:37 +03:00
|
|
|
{
|
2002-07-31 19:02:35 +04:00
|
|
|
if(calendarToDo.priority > 0 && calendarToDo.priority < 5)
|
2002-10-30 20:16:52 +03:00
|
|
|
props.AppendElement(aserv.getAtom("highpriority"));
|
2002-07-31 19:02:35 +04:00
|
|
|
if(calendarToDo.priority > 5 && calendarToDo.priority < 10)
|
2002-10-30 20:16:52 +03:00
|
|
|
props.AppendElement(aserv.getAtom("lowpriority"));
|
2003-02-13 16:59:37 +03:00
|
|
|
}
|
|
|
|
props.AppendElement(aserv.getAtom(ToDoProgressAtom(calendarToDo)));
|
|
|
|
},
|
|
|
|
getColumnProperties : function(){return false;},
|
2003-03-14 23:35:47 +03:00
|
|
|
// By getRowProperties, the properties defined with
|
2003-02-13 16:59:37 +03:00
|
|
|
// treechildren:-moz-tree-row in CSS are used.
|
|
|
|
// It is used here to color the background of a selected
|
|
|
|
// ToDo task with a color
|
|
|
|
// given by the progress state of the ToDo task.
|
|
|
|
getRowProperties : function( row,props ){
|
|
|
|
calendarToDo = gTaskArray[row];
|
|
|
|
|
2004-10-26 23:30:50 +04:00
|
|
|
var aserv=Components.classes["@mozilla.org/atom-service;1"].getService(Components.interfaces.nsIAtomService);
|
2003-02-13 16:59:37 +03:00
|
|
|
props.AppendElement(aserv.getAtom(ToDoProgressAtom( calendarToDo )));
|
2002-10-30 20:16:52 +03:00
|
|
|
},
|
|
|
|
isSorted : function(){return false;},
|
|
|
|
isEditable : function(){return true;},
|
|
|
|
isSeparator : function(){return false;},
|
2003-02-13 16:59:37 +03:00
|
|
|
// Return the empty string in order
|
|
|
|
// to use moz-tree-image pseudoelement :
|
|
|
|
// it is mandatory to return "" and not false :-(
|
|
|
|
getImageSrc : function(){return("");},
|
2004-04-17 09:53:38 +04:00
|
|
|
cycleCell : function(row,col)
|
2003-02-13 16:59:37 +03:00
|
|
|
{
|
2005-07-04 21:06:04 +04:00
|
|
|
calendarToDo = gTaskArray[row];
|
|
|
|
if(!calendarToDo)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Moz1.8 trees require column.id, moz1.7 and earlier trees use column.
|
|
|
|
if (col.id == "unifinder-todo-tree-col-completed") {
|
|
|
|
if (calendarToDo.completedDate)
|
|
|
|
checkboxClick( calendarToDo, false ) ;
|
|
|
|
else
|
|
|
|
checkboxClick( calendarToDo, true ) ;
|
|
|
|
}
|
2003-02-13 16:59:37 +03:00
|
|
|
},
|
2004-06-11 19:59:57 +04:00
|
|
|
cycleHeader : function(col, element) // element parameter used in Moz1.7-
|
|
|
|
{ // not in Moz1.8+
|
2002-10-30 20:16:52 +03:00
|
|
|
var sortActive;
|
|
|
|
var treeCols;
|
|
|
|
|
2004-06-11 19:59:57 +04:00
|
|
|
// Moz1.8 trees require column.id, moz1.7 and earlier trees use column.
|
2004-08-03 01:02:30 +04:00
|
|
|
this.selectedColumn = (typeof(col)=="object" ? col.id : col);
|
2004-06-11 19:59:57 +04:00
|
|
|
if (!element) element = col.element; // in Moz1.8+, get element from col
|
|
|
|
sortActive = element.getAttribute("sortActive");
|
|
|
|
this.sortDirection = element.getAttribute("sortDirection");
|
2002-10-30 20:16:52 +03:00
|
|
|
|
|
|
|
if (sortActive != "true")
|
|
|
|
{
|
|
|
|
treeCols = document.getElementsByTagName("treecol");
|
|
|
|
for (var i = 0; i < treeCols.length; i++)
|
|
|
|
{
|
|
|
|
treeCols[i].removeAttribute("sortActive");
|
|
|
|
treeCols[i].removeAttribute("sortDirection");
|
|
|
|
}
|
|
|
|
sortActive = true;
|
|
|
|
this.sortDirection = "ascending";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sortActive = true;
|
|
|
|
if (this.sortDirection == "" || this.sortDirection == "descending")
|
|
|
|
{
|
|
|
|
this.sortDirection = "ascending";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.sortDirection = "descending";
|
|
|
|
}
|
|
|
|
}
|
2004-06-11 19:59:57 +04:00
|
|
|
element.setAttribute("sortActive", sortActive);
|
|
|
|
element.setAttribute("sortDirection", this.sortDirection);
|
2004-06-11 20:11:08 +04:00
|
|
|
this.sortStartedTime = new Date().getTime(); // for null dates during sort
|
|
|
|
gTaskArray.sort( compareTasks );
|
|
|
|
|
2002-10-30 20:16:52 +03:00
|
|
|
document.getElementById( ToDoUnifinderTreeName ).view = this;
|
|
|
|
},
|
|
|
|
setTree : function( tree ){this.tree = tree;},
|
|
|
|
getCellText : function(row,column)
|
|
|
|
{
|
|
|
|
calendarToDo = gTaskArray[row];
|
|
|
|
if( !calendarToDo )
|
2002-11-27 18:20:28 +03:00
|
|
|
return false;
|
2002-07-02 17:52:07 +04:00
|
|
|
|
2004-05-10 19:02:04 +04:00
|
|
|
// Moz1.8 trees require column.id, moz1.7 and earlier trees use column.
|
2004-08-03 01:02:30 +04:00
|
|
|
switch( typeof(column)=="object" ? column.id : column )
|
2002-10-30 20:16:52 +03:00
|
|
|
{
|
|
|
|
case "unifinder-todo-tree-col-completed":
|
2003-02-13 16:59:37 +03:00
|
|
|
return( "" );
|
2002-10-30 20:16:52 +03:00
|
|
|
|
|
|
|
case "unifinder-todo-tree-col-priority":
|
2003-02-13 16:59:37 +03:00
|
|
|
return( "" );
|
2002-10-30 20:16:52 +03:00
|
|
|
|
|
|
|
case "unifinder-todo-tree-col-title":
|
2004-08-03 02:23:16 +04:00
|
|
|
// return title, or "Untitled" if empty/null
|
|
|
|
return calendarToDo.title || gCalendarBundle.getString( "eventUntitled" );
|
2002-10-30 20:16:52 +03:00
|
|
|
case "unifinder-todo-tree-col-startdate":
|
2004-08-03 02:23:16 +04:00
|
|
|
return( formatUnifinderToDoDateTime( calendarToDo.start ) );
|
2002-10-30 20:16:52 +03:00
|
|
|
case "unifinder-todo-tree-col-duedate":
|
2004-08-03 02:23:16 +04:00
|
|
|
return( formatUnifinderToDoDateTime( calendarToDo.due ) );
|
2002-10-30 20:16:52 +03:00
|
|
|
case "unifinder-todo-tree-col-completeddate":
|
2004-08-03 02:23:16 +04:00
|
|
|
return( formatUnifinderToDoDateTime( calendarToDo.completed ) );
|
2002-10-30 20:16:52 +03:00
|
|
|
case "unifinder-todo-tree-col-percentcomplete":
|
2003-01-13 16:46:34 +03:00
|
|
|
return( calendarToDo.percent+"%" );
|
2002-10-30 20:16:52 +03:00
|
|
|
case "unifinder-todo-tree-col-categories":
|
|
|
|
return( calendarToDo.categories );
|
2005-05-24 23:26:11 +04:00
|
|
|
case "unifinder-todo-tree-col-location":
|
|
|
|
return( calendarToDo.getProperty("LOCATION") );
|
|
|
|
case "unifinder-todo-tree-col-status":
|
|
|
|
return getToDoStatusString(calendarToDo);
|
2005-05-24 23:33:26 +04:00
|
|
|
case "unifinder-todo-tree-col-calendarname":
|
2005-07-04 21:06:04 +04:00
|
|
|
return( calendarToDo.calendar.name );
|
2002-11-27 18:20:28 +03:00
|
|
|
default:
|
|
|
|
return false;
|
2002-10-30 20:16:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-06-27 21:59:51 +04:00
|
|
|
|
2004-06-11 20:11:08 +04:00
|
|
|
function compareTasks( taskA, taskB )
|
2002-10-30 20:16:52 +03:00
|
|
|
{
|
|
|
|
var modifier = 1;
|
|
|
|
if (toDoTreeView.sortDirection == "descending")
|
|
|
|
{
|
|
|
|
modifier = -1;
|
|
|
|
}
|
2002-06-27 21:59:51 +04:00
|
|
|
|
2002-10-30 20:16:52 +03:00
|
|
|
switch(toDoTreeView.selectedColumn)
|
|
|
|
{
|
2004-06-11 20:11:08 +04:00
|
|
|
case "unifinder-todo-tree-col-priority": // 0-9
|
|
|
|
return compareNumber(taskA.priority, taskB.priority) * modifier;
|
2002-10-30 20:16:52 +03:00
|
|
|
|
2002-11-27 18:20:28 +03:00
|
|
|
case "unifinder-todo-tree-col-title":
|
2004-06-11 20:11:08 +04:00
|
|
|
return compareString(taskA.title, taskB.title) * modifier;
|
2002-11-27 18:20:28 +03:00
|
|
|
|
|
|
|
case "unifinder-todo-tree-col-startdate":
|
2004-06-11 20:11:08 +04:00
|
|
|
return compareDate(taskA.start, taskB.start) * modifier;
|
2002-11-27 18:20:28 +03:00
|
|
|
|
|
|
|
case "unifinder-todo-tree-col-duedate":
|
2004-06-11 20:11:08 +04:00
|
|
|
return compareDate(taskA.due, taskB.due) * modifier;
|
2002-10-30 20:16:52 +03:00
|
|
|
|
2004-06-11 20:11:08 +04:00
|
|
|
case "unifinder-todo-tree-col-completed": // checkbox if date exists
|
2002-11-27 18:20:28 +03:00
|
|
|
case "unifinder-todo-tree-col-completeddate":
|
2004-06-11 20:11:08 +04:00
|
|
|
return compareDate(taskA.completed, taskB.completed) * modifier;
|
2002-11-27 18:20:28 +03:00
|
|
|
|
|
|
|
case "unifinder-todo-tree-col-percentcomplete":
|
2004-06-11 20:11:08 +04:00
|
|
|
return compareNumber(taskA.percent, taskB.percent) * modifier;
|
2002-11-27 18:20:28 +03:00
|
|
|
|
|
|
|
case "unifinder-todo-tree-col-categories":
|
2004-06-11 20:11:08 +04:00
|
|
|
return compareString(taskA.categories, taskB.categories) * modifier;
|
|
|
|
|
2005-05-24 23:26:11 +04:00
|
|
|
case "unifinder-todo-tree-col-location":
|
|
|
|
return compareString(taskA.getProperty("LOCATION"), taskB.getProperty("LOCATION")) * modifier;
|
|
|
|
case "unifinder-todo-tree-col-status":
|
|
|
|
return compareNumber(kStatusOrder.indexOf(taskA.status), kStatusOrder.indexOf(taskB.status)) * modifier;
|
2005-05-24 23:33:26 +04:00
|
|
|
case "unifinder-todo-tree-col-calendarname":
|
2005-05-24 23:26:11 +04:00
|
|
|
return compareString(taskA.parent.name, taskB.parent.name) * modifier;
|
|
|
|
|
2002-11-27 18:20:28 +03:00
|
|
|
default:
|
2004-06-11 20:11:08 +04:00
|
|
|
return 0;
|
2002-10-30 20:16:52 +03:00
|
|
|
}
|
2002-07-30 23:19:50 +04:00
|
|
|
}
|
|
|
|
|
2004-06-11 20:11:08 +04:00
|
|
|
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);
|
|
|
|
}
|
2004-11-19 18:15:19 +03:00
|
|
|
function dateToMilliseconds(oeICalDateTime) {
|
|
|
|
// Treat unset time as "time when sort started", so incomplete tasks
|
|
|
|
// stay current. "Time when sort started" is computed once per sort
|
|
|
|
// (just before sort) so sort is stable.
|
|
|
|
if (oeICalDateTime && oeICalDateTime.isSet)
|
|
|
|
return oeICalDateTime.getTime();
|
|
|
|
else
|
2004-06-11 20:11:08 +04:00
|
|
|
return treeView.sortStartedTime;
|
|
|
|
}
|
|
|
|
|
2002-07-31 19:02:35 +04:00
|
|
|
|
2002-10-30 20:16:52 +03:00
|
|
|
function calendarTaskView( taskArray )
|
|
|
|
{
|
|
|
|
this.taskArray = taskArray;
|
|
|
|
}
|
2002-07-30 23:19:50 +04:00
|
|
|
|
2002-10-30 20:16:52 +03:00
|
|
|
calendarTaskView.prototype.getCalendarTaskAtRow = function( i )
|
2002-07-30 23:19:50 +04:00
|
|
|
{
|
2002-10-30 20:16:52 +03:00
|
|
|
return( gTaskArray[ i ] );
|
|
|
|
}
|
2002-09-11 22:29:06 +04:00
|
|
|
|
2002-10-30 20:16:52 +03:00
|
|
|
calendarTaskView.prototype.getRowOfCalendarTask = function( Task )
|
|
|
|
{
|
|
|
|
for( var i = 0; i < this.gTaskArray.length; i++ )
|
|
|
|
{
|
|
|
|
if( this.gTaskArray[i].id == Event.id )
|
|
|
|
return( i );
|
|
|
|
}
|
|
|
|
return( "null" );
|
|
|
|
}
|
2002-07-30 23:19:50 +04:00
|
|
|
|
2002-10-30 20:16:52 +03:00
|
|
|
/**
|
|
|
|
* Redraw the categories unifinder tree
|
|
|
|
*/
|
|
|
|
|
|
|
|
function refreshToDoTree( taskArray )
|
|
|
|
{
|
|
|
|
if( taskArray === false )
|
|
|
|
taskArray = getTaskTable();
|
|
|
|
|
|
|
|
gTaskArray = taskArray;
|
|
|
|
|
|
|
|
toDoTreeView.rowCount = gTaskArray.length;
|
|
|
|
|
2003-08-12 18:12:40 +04:00
|
|
|
var ArrayOfTreeCols = document.getElementById( ToDoUnifinderTreeName ).getElementsByTagName( "treecol" );
|
2002-11-05 21:44:27 +03:00
|
|
|
|
|
|
|
for( var i = 0; i < ArrayOfTreeCols.length; i++ )
|
|
|
|
{
|
|
|
|
if( ArrayOfTreeCols[i].getAttribute( "sortActive" ) == "true" )
|
|
|
|
{
|
2003-01-13 16:46:34 +03:00
|
|
|
toDoTreeView.selectedColumn = ArrayOfTreeCols[i].getAttribute( "id" );
|
|
|
|
toDoTreeView.sortDirection = ArrayOfTreeCols[i].getAttribute("sortDirection");
|
2004-06-11 20:11:08 +04:00
|
|
|
toDoTreeView.sortStartedTime = new Date().getTime(); //for null/0 dates
|
|
|
|
gTaskArray.sort(compareTasks);
|
2002-11-05 21:44:27 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-30 20:16:52 +03:00
|
|
|
document.getElementById( ToDoUnifinderTreeName ).view = toDoTreeView;
|
2002-06-27 21:59:51 +04:00
|
|
|
|
2002-10-30 20:16:52 +03:00
|
|
|
document.getElementById( ToDoUnifinderTreeName ).taskView = new calendarTaskView( gTaskArray );
|
2002-07-30 23:19:50 +04:00
|
|
|
}
|
|
|
|
|
2002-07-31 19:02:35 +04:00
|
|
|
|
2002-09-12 17:16:57 +04:00
|
|
|
function getTaskTable( )
|
|
|
|
{
|
2005-01-05 01:49:12 +03:00
|
|
|
return gTaskArray;
|
2002-09-12 17:16:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-03 22:42:28 +04:00
|
|
|
function contextChangeProgress( event, Progress )
|
2002-08-22 18:33:32 +04:00
|
|
|
{
|
2002-09-03 22:42:28 +04:00
|
|
|
var tree = document.getElementById( ToDoUnifinderTreeName );
|
2005-06-28 01:40:53 +04:00
|
|
|
var start = new Object();
|
|
|
|
var end = new Object();
|
|
|
|
var numRanges = tree.view.selection.getRangeCount();
|
|
|
|
var toDoItem;
|
|
|
|
if(numRanges == 0)
|
|
|
|
return;
|
|
|
|
startBatchTransaction();
|
|
|
|
for (var t = 0; t < numRanges; t++) {
|
|
|
|
tree.view.selection.getRangeAt(t, start, end);
|
|
|
|
for (v = start.value; v <= end.value; v++) {
|
|
|
|
todoItem = tree.taskView.getCalendarTaskAtRow( v );
|
|
|
|
var newItem = todoItem.clone().QueryInterface( Components.interfaces.calITodo );
|
2005-01-05 01:49:12 +03:00
|
|
|
newItem.percentComplete = Progress;
|
2005-06-04 00:46:36 +04:00
|
|
|
doTransaction('modify', newItem, newItem.calendar, todoItem, null);
|
2002-08-22 18:33:32 +04:00
|
|
|
}
|
|
|
|
}
|
2005-06-28 01:40:53 +04:00
|
|
|
endBatchTransaction();
|
2002-08-22 18:33:32 +04:00
|
|
|
}
|
|
|
|
|
2002-09-03 22:42:28 +04:00
|
|
|
function contextChangePriority( event, Priority )
|
2002-08-22 18:33:32 +04:00
|
|
|
{
|
2002-09-03 22:42:28 +04:00
|
|
|
var tree = document.getElementById( ToDoUnifinderTreeName );
|
2005-06-28 01:40:53 +04:00
|
|
|
var start = new Object();
|
|
|
|
var end = new Object();
|
|
|
|
var numRanges = tree.view.selection.getRangeCount();
|
|
|
|
var toDoItem;
|
|
|
|
if(numRanges == 0)
|
|
|
|
return;
|
|
|
|
startBatchTransaction();
|
|
|
|
for (var t = 0; t < numRanges; t++) {
|
|
|
|
tree.view.selection.getRangeAt(t, start, end);
|
|
|
|
for (v = start.value; v <= end.value; v++) {
|
|
|
|
todoItem = tree.taskView.getCalendarTaskAtRow( v );
|
|
|
|
var newItem = todoItem.clone().QueryInterface( Components.interfaces.calITodo );
|
2005-01-05 01:49:12 +03:00
|
|
|
newItem.priority = Priority;
|
2005-06-04 00:46:36 +04:00
|
|
|
doTransaction('modify', newItem, newItem.calendar, todoItem, null);
|
2002-08-22 18:33:32 +04:00
|
|
|
}
|
|
|
|
}
|
2005-06-28 01:40:53 +04:00
|
|
|
endBatchTransaction();
|
2002-08-22 18:33:32 +04:00
|
|
|
}
|
2002-08-28 00:06:09 +04:00
|
|
|
|
2002-10-29 00:37:27 +03:00
|
|
|
function changeContextMenuForToDo( event )
|
|
|
|
{
|
2004-08-27 14:42:12 +04:00
|
|
|
if (event.target.id != "taskitem-context-menu")
|
|
|
|
return;
|
|
|
|
|
2002-10-29 00:37:27 +03:00
|
|
|
var toDoItem = getToDoFromEvent( event );
|
|
|
|
if( toDoItem )
|
|
|
|
{
|
2004-08-27 14:42:12 +04:00
|
|
|
document.getElementById("is_editable").removeAttribute("disabled");
|
2004-05-10 19:30:45 +04:00
|
|
|
var liveList = document.getElementById( "taskitem-context-menu" ).getElementsByAttribute( "checked", "true" );
|
|
|
|
// Delete in reverse order. Moz1.8+ getElementsByAttribute list is
|
|
|
|
// 'live', so when attribute is deleted the indexes of later elements
|
|
|
|
// change, but Moz1.7- is not. Reversed order works with both.
|
|
|
|
for (var i = liveList.length - 1; i >= 0; i-- )
|
|
|
|
{
|
|
|
|
liveList.item(i).removeAttribute( "checked" );
|
|
|
|
}
|
2002-08-28 00:06:09 +04:00
|
|
|
|
2002-10-29 00:37:27 +03:00
|
|
|
if( document.getElementById( "percent-"+toDoItem.percent+"-menuitem" ) )
|
|
|
|
{
|
|
|
|
document.getElementById( "percent-"+toDoItem.percent+"-menuitem" ).setAttribute( "checked", "true" );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( document.getElementById( "priority-"+toDoItem.priority+"-menuitem" ) )
|
|
|
|
{
|
|
|
|
document.getElementById( "priority-"+toDoItem.priority+"-menuitem" ).setAttribute( "checked", "true" );
|
|
|
|
}
|
2004-08-27 14:42:12 +04:00
|
|
|
} else {
|
|
|
|
document.getElementById("is_editable").setAttribute("disabled", "true");
|
2002-10-29 00:37:27 +03:00
|
|
|
}
|
|
|
|
}
|
2002-10-30 21:23:30 +03:00
|
|
|
|