Updating code, doing a little bit of clean up.

This commit is contained in:
mikep%oeone.com 2002-06-19 15:00:38 +00:00
Родитель 41ebe0592b
Коммит 6c39f03f3d
8 изменённых файлов: 154 добавлений и 187 удалений

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

@ -78,7 +78,7 @@ h1 {
<td id="mozver">
<h1>
<a id="mozlink" href="http://www.mozilla.org/projects/calendar/" target="_new">Mozilla Calendar 2002060511-cal</a>
<a id="mozlink" href="http://www.mozilla.org/projects/calendar/" target="_new">Mozilla Calendar 2002061709-cal</a>
</h1>
<script type="application/x-javascript">
// using try..catch to handle empty useragents and other cases where the regex fails to apply

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

@ -163,7 +163,7 @@ function calendarInit()
// Set the date and time on the clock and set up a timeout to refresh the clock when the
// next minute ticks over
function update_date( Refresh )
function update_date( )
{
// get the current time
var now = new Date();
@ -183,7 +183,7 @@ function update_date( Refresh )
function calendarFinish()
{
finishCalendarUnifinder( gEventSource );
finishCalendarUnifinder( );
gCalendarWindow.close( );
}
@ -417,10 +417,51 @@ function newEventCommand()
}
/**
* Called when the new event button is clicked
*/
function newToDoCommand()
{
var calendarEvent = createToDo();
var dueDate = gCalendarWindow.currentView.getNewEventDate();
var Minutes = Math.ceil( dueDate.getMinutes() / 5 ) * 5 ;
dueDate = new Date( dueDate.getFullYear(),
dueDate.getMonth(),
dueDate.getDate(),
dueDate.getHours(),
Minutes,
0);
calendarEvent.due.setTime( dueDate );
var args = new Object();
args.mode = "new";
args.onOk = self.addToDoDialogResponse;
args.calendarEvent = calendarEvent;
// open the dialog modally
openDialog("chrome://calendar/content/calendarToDoDialog.xul", "caEditEvent", "chrome,modal", args );
}
function createEvent ()
{
var iCalEventComponent = Components.classes["@mozilla.org/icalevent;1"].createInstance();
var iCalEvent = iCalEventComponent.QueryInterface(Components.interfaces.oeIICalEvent);
var iCalToDoComponent = Components.classes["@mozilla.org/icalevent;1"].createInstance();
var iCalToDo = iCalToDoComponent.QueryInterface(Components.interfaces.oeIICalEvent);
return iCalToDo;
}
function createToDo ()
{
var iCalEventComponent = Components.classes["@mozilla.org/icaltodo;1"].createInstance();
var iCalEvent = iCalEventComponent.QueryInterface(Components.interfaces.oeIICalTodo);
return iCalEvent;
}
@ -492,6 +533,17 @@ function addEventDialogResponse( calendarEvent, ArrayOfExceptionDates )
}
/**
* Called when the user clicks OK in the new to do item dialog
*
*/
function addToDoDialogResponse( calendarToDo )
{
gICalLib.addToDo( calendarToDo );
}
/**
* Helper function to launch the event composer to edit an event.
* When the user clicks OK "modifyEventDialogResponse" is called
@ -512,6 +564,26 @@ function editEvent( calendarEvent )
}
/**
* Helper function to launch the event composer to edit an event.
* When the user clicks OK "modifyEventDialogResponse" is called
*/
function editToDo( calendarToDo )
{
// set up a bunch of args to pass to the dialog
var args = new Object();
args.mode = "edit";
args.onOk = self.modifyToDoDialogResponse;
args.calendarToDo = calendarToDo;
// open the dialog modally
openDialog("chrome://calendar/content/calendarToDoDialog.xul", "caEditToDo", "chrome,modal", args );
}
/**
* Called when the user clicks OK in the edit event dialog
*
@ -534,6 +606,19 @@ function modifyEventDialogResponse( calendarEvent, ArrayOfExceptionDates )
}
/**
* Called when the user clicks OK in the edit event dialog
*
* Update the data source, the unifinder views and the calendar views will be
* notified of the change through their respective observers
*/
function modifyToDoDialogResponse( calendarToDo )
{
gICalLib.modifyToDo( calendarToDo );
}
/**
* Called when a user hovers over an element and the text for the mouse over is changed.
*/
@ -571,11 +656,6 @@ function alertCalendarVersion()
window.openDialog( getBrowserURL(), "_blank", "chrome,all,dialog=no", 'chrome://calendar/content/about.html' );
}
function reloadApplication()
{
gCalendarWindow.currentView.refreshEvents( );
}
function playSound( ThisURL )
{
ThisURL = "chrome://calendar/content/sound.wav";
@ -591,134 +671,6 @@ function playSound( ThisURL )
sample.play( url );
}
/*
**
*/
function openImportFileDialog()
{
const nsIFilePicker = Components.interfaces.nsIFilePicker;
const nsILocalFile = Components.interfaces.nsILocalFile;
var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
// caller can force disable of sand box, even if ON globally
fp.init(window, "Open File", nsIFilePicker.modeOpen);
fp.defaultString = "My Mozilla Calendar.ics";
fp.appendFilter( "Calendar Files", "*.ics" );
/*
* Setup the initial directory to be the home directory
*/
const dirSvc = Components
.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties);
var baseFile = dirSvc.get("Home", nsILocalFile);
const dir = baseFile.clone().QueryInterface(nsILocalFile);
fp.displayDirectory = dir;
try {
fp.show();
/* need to handle cancel (uncaught exception at present) */
}
catch (ex) {
dump("filePicker.chooseInputFile threw an exception\n");
}
/* This checks for already open window and activates it...
* note that we have to test the native path length
* since fileURL.spec will be "file:///" if no filename picked (Cancel button used)
*/
if (fp.file && fp.file.path.length > 0)
{
doImportEvents( fp.file.path );
}
return false;
}
function doImportEvents( FilePath )
{
alert( "I should import files to "+FilePath );
}
function openExportFileDialog()
{
const nsIFilePicker = Components.interfaces.nsIFilePicker;
const nsILocalFile = Components.interfaces.nsILocalFile;
var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
// caller can force disable of sand box, even if ON globally
fp.init(window, "Open File", nsIFilePicker.modeSave);
fp.defaultString = "My Mozilla Calendar.ics";
fp.appendFilter( "Calendar Files", "*.ics" );
/*
* Setup the initial directory to be the home directory
*/
const dirSvc = Components
.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties);
var baseFile = dirSvc.get("Home", nsILocalFile);
const dir = baseFile.clone().QueryInterface(nsILocalFile);
fp.displayDirectory = dir;
try {
fp.show();
/* need to handle cancel (uncaught exception at present) */
}
catch (ex) {
dump("filePicker.chooseInputFile threw an exception\n");
}
/* This checks for already open window and activates it...
* note that we have to test the native path length
* since fileURL.spec will be "file:///" if no filename picked (Cancel button used)
*/
if (fp.file && fp.file.path.length > 0)
{
doExportEvents( fp.file.path );
}
return false;
}
function doExportEvents( FilePath )
{
//get all the selected events;
var SelectedEvents = gCalendarWindow.EventSelection.selectedEvents;
//send this to the back end, it should return a string.
//write that string out to the new file with path 'FilePath';
var aFile = Components.classes["@mozilla.org/file/local;1"].createInstance();
aLocalFile=aFile.QueryInterface(Components.interfaces.nsILocalFile);
aLocalFile.initWithPath( FilePath );
aLocalFile.create( 0, 0755 );
//write to the file.
alert( "I should export files to "+FilePath );
}
function selectAllEvents()
{
gCalendarWindow.EventSelection.setArrayToSelection( gCalendarWindow.eventSource.getCurrentEvents() );

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

@ -82,6 +82,7 @@
<commandset>
<command id="new_command" oncommand="newEventCommand()"/>
<command id="new_todo_command" oncommand="newToDoCommand()"/>
<command id="delete_command" oncommand="unifinderDeleteCommand( true )" disabled="true"/>
<command id="modify_command" oncommand="unifinderEditCommand()" disabled="true"/>
<command id="send_event_command" oncommand="sendEvent()" disabled="true"/>
@ -234,6 +235,36 @@
</box>
<listbox id="unifinder-search-results-listbox" seltype="multiple" onselect="unifinderClickEvent( this )"
class="unifinder-tree-class" flex="1" ondragover="return( false );"/>
<splitter collapse="after" persist="state hidden collapsed"
class="chromeclass-extrachrome" orient="vertical">
<grippy/>
</splitter>
<vbox flex="1">
<box align="left">
<label style="font-weight: bold" value="To Do Items"/>
</box>
<listbox allowevents="true" id="unifinder-todo-listbox" flex="1">
<listcols>
<listcol/>
<listcol flex="1"/>
<listcol flex="3"/>
</listcols>
<listitem id="sample-todo-listitem" allowevents="true">
<listcell name="checkbox-listcell">
<checkbox name="firstcheckbox"/>
</listcell>
<listcell name="priority-listcell">
</listcell>
<listcell name="title-listcell" onclick="switchDeck( this )">
<deck name="editdeck" selectedIndex="0">
<label name="title-label" />
<textbox id="thistextbox" flex="1"/>
</deck>
</listcell>
</listitem>
</listbox>
</vbox>
</vbox>
<splitter id="calendar-splitter" collapse="before" persist="state hidden collapsed"

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

@ -100,6 +100,7 @@
<menu id="menu_File">
<menupopup id="menu_FilePopup">
<menuitem id="calendar-new-event-menu" key="new_event_key" label="&event.new.event;" observes="new_command"/>
<menuitem id="calendar-new-todo-menu" key="new_event_key" label="New To Do Item" observes="new_todo_command"/>
<menuitem id="unifinder-modify-menu" key="modify_event_key" label="&event.edit.event;" observes="modify_command"/>
<menuseparator/>
<menuitem id="calendar-import-menu" key="import_key" label="&calendar.import.label;" accesskey="&calendar.import.accesskey;" observes="import_command"/>

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

@ -203,7 +203,7 @@ function MonthView( calendarWindow )
*/
MonthView.prototype.refreshEvents = function( )
{
// get this month's events and display them
// get this month's events and display them
var monthEventList = this.calendarWindow.eventSource.getEventsForMonth( this.calendarWindow.getSelectedDate() );

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

@ -100,6 +100,7 @@
<menu id="menu_File">
<menupopup id="menu_FilePopup">
<menuitem id="calendar-new-event-menu" key="new_event_key" label="&event.new.event;" observes="new_command"/>
<menuitem id="calendar-new-todo-menu" key="new_event_key" label="New To Do Item" observes="new_todo_command"/>
<menuitem id="unifinder-modify-menu" key="modify_event_key" label="&event.edit.event;" observes="modify_command"/>
<menuseparator/>
<menuitem id="calendar-import-menu" key="import_key" label="&calendar.import.label;" accesskey="&calendar.import.accesskey;" observes="import_command"/>

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

@ -203,7 +203,7 @@ function MonthView( calendarWindow )
*/
MonthView.prototype.refreshEvents = function( )
{
// get this month's events and display them
// get this month's events and display them
var monthEventList = this.calendarWindow.eventSource.getEventsForMonth( this.calendarWindow.getSelectedDate() );

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

@ -44,6 +44,8 @@
* improve this to make it usable in general.
*/
const UnifinderTreeName = "unifinder-search-results-listbox";
function calendarUnifinderInit( )
{
var unifinderEventSelectionObserver =
@ -75,9 +77,6 @@ function calendarUnifinderInit( )
gCalendarWindow.EventSelection.addObserver( unifinderEventSelectionObserver );
}
var gSearchEventTable = new Array();
/**
* Observer for the calendar event data source. This keeps the unifinder
* display up to date when the calendar event data is changed
@ -154,7 +153,7 @@ function prepareCalendarUnifinder( )
* Called when the calendar is unloaded
*/
function finishCalendarUnifinder( eventSource )
function finishCalendarUnifinder( )
{
gICalLib.removeObserver( unifinderEventDataSourceObserver );
}
@ -176,9 +175,7 @@ function formatUnifinderEventDate( date )
function formatUnifinderEventTime( time )
{
var timeString = gCalendarWindow.dateFormater.getFormatedTime( time );
return timeString;
return( gCalendarWindow.dateFormater.getFormatedTime( time ) );
}
/**
@ -189,26 +186,10 @@ function unifinderRefesh()
{
gEventSource.onlyFutureEvents = (document.getElementById( 'unifinder-future-events' ).getAttribute( "checked" ) == "true" );
var eventTable = gEventSource.getCurrentEvents();
refreshSearchTree( eventTable );
unifinderSearchKeyPress( document.getElementById( 'unifinder-search-field' ), null );
}
/**
* Redraw the search tree
*/
function refreshSearchTree( SearchEventTable )
{
gSearchEventTable = SearchEventTable;
refreshEventTree( gSearchEventTable, "unifinder-search-results-listbox", false );
}
/**
* This is attached to the ondblclik attribute of the events shown in the unifinder
*/
@ -224,7 +205,6 @@ function unifinderDoubleClickEvent( id )
// go to day view, of the day of the event, select the event
editEvent( calendarEvent );
}
}
@ -235,26 +215,26 @@ function unifinderDoubleClickEvent( id )
function unifinderClickEvent( CallingListBox )
{
var ListBox = CallingListBox;
var ArrayOfEvents = new Array();
for( i = 0; i < ListBox.selectedItems.length; i++ )
for( i = 0; i < CallingListBox.selectedItems.length; i++ )
{
var calendarEvent = ListBox.selectedItems[i].event;
var calendarEvent = CallingListBox.selectedItems[i].event;
ArrayOfEvents[ ArrayOfEvents.length ] = calendarEvent;
}
gCalendarWindow.EventSelection.setArrayToSelection( ArrayOfEvents );
if( ListBox.selectedItems.length == 1 )
if( CallingListBox.selectedItems.length == 1 )
{
//start date is either the next or last occurence, or the start date of the event
/*start date is either the next or last occurence, or the start date of the event */
var eventStartDate = getNextOrPreviousRecurrence( calendarEvent );
/* you need this in case the current day is not visible. */
gCalendarWindow.currentView.goToDay( eventStartDate, true);
}
}
}
/**
@ -349,11 +329,13 @@ function unifinderDeleteCommand( DoNotConfirm )
function unifinderSearchKeyPress( searchTextItem, event )
{
var eventTable = new Array();
var searchText = searchTextItem.value;
if ( searchTextItem.value == '' )
{
gSearchEventTable = gEventSource.getCurrentEvents();
eventTable = gEventSource.getCurrentEvents();
}
else if ( searchTextItem.value == " " )
{
@ -362,7 +344,7 @@ function unifinderSearchKeyPress( searchTextItem, event )
else
{
var FieldsToSearch = new Array( "title", "description", "location" );
gSearchEventTable = gEventSource.search( searchText, FieldsToSearch );
eventTable = gEventSource.search( searchText, FieldsToSearch );
}
if( document.getElementById( "unifinder-clear-results-button" ) )
@ -372,15 +354,16 @@ function unifinderSearchKeyPress( searchTextItem, event )
else
document.getElementById( "unifinder-clear-results-button" ).removeAttribute( "disabled" );
}
refreshSearchTree( gSearchEventTable );
refreshEventTree( eventTable );
}
function unifinderShowEventsWithAlarmsOnly()
{
gSearchEventTable = gEventSource.getEventsWithAlarms();
var eventTable = gEventSource.getEventsWithAlarms();
refreshSearchTree( gSearchEventTable );
refreshEventTree( eventTable );
}
@ -388,9 +371,11 @@ function unifinderShowFutureEventsOnly( event )
{
gEventSource.onlyFutureEvents = (event.target.getAttribute( "checked" ) == "true" );
gSearchEventTable = gEventSource.getCurrentEvents();
var eventTable = gEventSource.getCurrentEvents();
refreshSearchTree( gSearchEventTable );
refreshEventTree( eventTable );
/* The following isn't exactly right. It should reload after the next event happens. */
// get the current time
var now = new Date();
@ -399,18 +384,18 @@ function unifinderShowFutureEventsOnly( event )
var milliSecsTillTomorrow = tomorrow.getTime() - now.getTime();
setTimeout( "refreshEventTree( gSearchEventTable )", milliSecsTillTomorrow );
setTimeout( "refreshEventTree( eventTable )", milliSecsTillTomorrow );
}
/**
* Redraw the categories unifinder tree
*/
function refreshEventTree( eventArray, childrenName, Categories )
function refreshEventTree( eventArray )
{
// get the old tree children item and remove it
var oldTreeChildren = document.getElementById( childrenName );
var oldTreeChildren = document.getElementById( UnifinderTreeName );
while( oldTreeChildren.hasChildNodes() )
oldTreeChildren.removeChild( oldTreeChildren.lastChild );
@ -424,10 +409,7 @@ function refreshEventTree( eventArray, childrenName, Categories )
var treeItem = document.createElement( "listitem" );
if( Categories != false )
treeItem.setAttribute( "id", "unifinder-treeitem-"+calendarEvent.id );
else
treeItem.setAttribute( "id", "search-unifinder-treeitem-"+calendarEvent.id );
treeItem.setAttribute( "id", "search-unifinder-treeitem-"+calendarEvent.id );
treeItem.event = calendarEvent;
@ -515,9 +497,9 @@ function unifinderClearSearchCommand()
{
document.getElementById( "unifinder-search-field" ).value = "";
gSearchEventTable = gEventSource.getCurrentEvents();
var eventTable = gEventSource.getCurrentEvents();
refreshSearchTree( gSearchEventTable );
refreshEventTree( eventTable );
}