diff --git a/mozilla/calendar/resources/content/calendar.xul b/mozilla/calendar/resources/content/calendar.xul index aa6e8bb0b32..dceb2d05447 100644 --- a/mozilla/calendar/resources/content/calendar.xul +++ b/mozilla/calendar/resources/content/calendar.xul @@ -410,8 +410,8 @@ - - + + + + + + + + + + + diff --git a/mozilla/calendar/resources/content/calendarImportExport.js b/mozilla/calendar/resources/content/calendarImportExport.js index 2f26845998d..ed0401813b4 100644 --- a/mozilla/calendar/resources/content/calendarImportExport.js +++ b/mozilla/calendar/resources/content/calendarImportExport.js @@ -124,7 +124,7 @@ function loadEventsFromFile() var buttonPressed = promptService.confirmEx(window, - "Import", "About to import " + calendarEventArray.length + " event(s). Do you want to open all events to import before importing?", + "Import", "About to import " + calendarEventArray.length + " item(s). Do you want to open all items to import before importing?", (promptService.BUTTON_TITLE_YES * promptService.BUTTON_POS_0) + (promptService.BUTTON_TITLE_NO * promptService.BUTTON_POS_1) + (promptService.BUTTON_TITLE_CANCEL * promptService.BUTTON_POS_2), @@ -169,29 +169,69 @@ function createUniqueID() function addEventsToCalendar( calendarEventArray, silent ) { + var defaultServer = gCalendarWindow.calendarManager.calendars[0]; for(var i = 0; i < calendarEventArray.length; i++) { - calendarEvent = calendarEventArray[i] + if( isEvent( calendarEventArray[i] ) ) + { + var calendarEvent = calendarEventArray[i]; - // Check if event with same ID already in Calendar. If so, import event with new ID. - if( gICalLib.fetchEvent( calendarEvent.id ) != null ) { - calendarEvent.id = createUniqueID( ); + // Check if event with same ID already in Calendar. If so, import event with new ID. + if( gICalLib.fetchEvent( calendarEvent.id ) != null ) { + calendarEvent.id = createUniqueID( ); + } + + // the start time is in zulu time, need to convert to current time + if(calendarEvent.allDay != true) + convertZuluToLocal( calendarEvent ); + + // open the event dialog with the event to add + if( silent ) + gICalLib.addEvent( calendarEvent, defaultServer.path ); + else + editNewEvent( calendarEvent ); + } + else if( isToDo( calendarEventArray[i] ) ) + { + // + calendarTodo = calendarEventArray[i]; + + // Check if task with same ID already in Calendar. If so, import task with new ID. + if( gICalLib.fetchTodo( calendarTodo.id ) != null ) { + calendarTodo.id = createUniqueID( ); + } + + // open the todo dialog with the task to add + if( silent ){alert(defaultServer.path); + gICalLib.addTodo( calendarTodo, defaultServer.path );} + else + gICalLib.addTodo( calendarTodo, defaultServer.path ); + // XXX TODO: add support to add todo using dialog + // editToDo( calendarTodo ); } - - // the start time is in zulu time, need to convert to current time - if(calendarEvent.allDay != true) - convertZuluToLocal( calendarEvent ); - - // open the event dialog with the event to add - if( silent ) - gICalLib.addEvent( calendarEvent ); - else - editNewEvent( calendarEvent ); } } const ZULU_OFFSET_MILLIS = new Date().getTimezoneOffset() * 60 * 1000; +function convertToUTC( aLocalTime ) +{ + if( calendarEvent.start.utc == false ) + { + aLocalTime.setTime( aLocalTime.getTime() + ZULU_OFFSET_MILLIS ); + aLocalTime.utc = true; + } +} + +function convertFromUTC( aUtcTime ) +{ + if( aUtcTime.utc == true ) + { + aUtcTime.setTime( aUtcTime.getTime() - ZULU_OFFSET_MILLIS ); + aUtcTime.utc = false; + } +} + function convertZuluToLocal( calendarEvent ) { if( calendarEvent.start.utc == true ) @@ -278,19 +318,20 @@ function initCalendarEvent( calendarEvent ) * Parses those events and returns an array of calendarEvents. */ -function parseIcalData( icalStr ) +function parseIcalData( icalendarString ) { var calendarEventArray = new Array(); var i,j; + var icalStr = icalendarString; while( icalStr.indexOf("BEGIN:VEVENT") != -1 ) { // try to find the begin and end of an event. ParseIcalString does not support VCALENDAR i = icalStr.indexOf("BEGIN:VEVENT"); j = icalStr.indexOf("END:VEVENT") + 10; - eventData = icalStr.substring(i, j); + var eventData = icalStr.substring(i, j); - calendarEvent = createEvent(); + var calendarEvent = createEvent(); // if parsing import iCalendar failed, add date as description if ( !calendarEvent.parseIcalString(eventData) ) @@ -306,7 +347,29 @@ function parseIcalData( icalStr ) // remove the parsed VEVENT from the calendar data to parse icalStr = icalStr.substring(j+1); } - + + icalStr = icalendarString; + while( icalStr.indexOf("BEGIN:VTODO") != -1 ) + { + // try to find the begin and end of an task. ParseIcalString does not support VCALENDAR + i = icalStr.indexOf("BEGIN:VTODO"); + j = icalStr.indexOf("END:VTODO") + 9; + var todoData = icalStr.substring(i, j); + + var calendarTodo = createToDo(); + + // if parsing import iCalendar failed, add date as description + if ( !calendarTodo.parseTodoIcalString(todoData) ) + { + // Save the parsed text as description. + calendarTodo.description = icalStr; + } + + calendarEventArray[ calendarEventArray.length ] = calendarTodo; + // remove the parsed VTODO from the calendar data to parse + icalStr = icalStr.substring(j+1); + } + return calendarEventArray; } @@ -344,18 +407,18 @@ function readDataFromFile( aFilePath, charset ) var scriptableInputStream; var tmp; // not sure what the use is for this - LocalFileInstance = Components.classes[LOCALFILE_CTRID].createInstance( nsILocalFile ); - LocalFileInstance.initWithPath( aFilePath ); + localFileInstance = Components.classes[LOCALFILE_CTRID].createInstance( nsILocalFile ); + localFileInstance.initWithPath( aFilePath ); inputStream = Components.classes[FILEIN_CTRID].createInstance( nsIFileInputStream ); try { - inputStream.init( LocalFileInstance, MODE_RDONLY, 0444, tmp ); + inputStream.init( localFileInstance, MODE_RDONLY, 0444, tmp ); scriptableInputStream = Components.classes[SCRIPTSTREAM_CTRID].createInstance( nsIScriptableInputStream); scriptableInputStream.init( inputStream ); - aDataStream = scriptableInputStream.read( -1 ); + var aDataStream = scriptableInputStream.read( -1 ); scriptableInputStream.close(); inputStream.close(); @@ -473,22 +536,27 @@ function eventArrayToICalString( calendarEventArray, doPatchForExport ) var sTextiCalendar = ""; for( var eventArrayIndex = 0; eventArrayIndex < calendarEventArray.length; ++eventArrayIndex ) { - var calendarEvent = calendarEventArray[ eventArrayIndex ].clone(); + var calendarObject = calendarEventArray[ eventArrayIndex ].clone(); // convert time to represent local to produce correct DTSTART and DTEND - if(calendarEvent.allDay != true) - convertLocalToZulu( calendarEvent ); + if( isEvent(calendarObject) && calendarObject.allDay != true ) + convertLocalToZulu( calendarObject ); // check if all required properties are available - if( calendarEvent.method == 0 ) - calendarEvent.method = calendarEvent.ICAL_METHOD_PUBLISH; - if( calendarEvent.stamp.year == 0 ) - calendarEvent.stamp.setTime( new Date() ); + if( calendarObject.method == 0 ) + calendarObject.method = calendarObject.ICAL_METHOD_PUBLISH; + if( calendarObject.stamp.year == 0 ) + calendarObject.stamp.setTime( new Date() ); - if ( doPatchForExport ) - sTextiCalendar += patchICalStringForExport( calendarEvent.getIcalString() ); + if ( isEvent(calendarObject) && doPatchForExport ) + sTextiCalendar += patchICalStringForExport( calendarObject.getIcalString() ); else - sTextiCalendar += calendarEvent.getIcalString() ; + { + if( isEvent(calendarObject) ) + sTextiCalendar += calendarObject.getIcalString(); + else + sTextiCalendar += calendarObject.getTodoIcalString(); + } } return sTextiCalendar; @@ -525,11 +593,11 @@ function patchICalStringForExport( sTextiCalendar ) function eventArrayToHTML( calendarEventArray ) { - sHTMLHeader = + const sHTMLHeader = "\n" + "\n" + "Mozilla Calendar\n" + "\n" + "\n"+ "\n"; - sHTMLFooter = + const sHTMLFooter = "\n\n\n"; var sHTMLText = sHTMLHeader; @@ -639,6 +707,7 @@ function eventArrayToXCS( calendarEventArray ) // XXX MAJOR UGLY HACK!! Serializer doesn't insert XML Declaration // http://bugzilla.mozilla.org/show_bug.cgi?id=63558 + // Fixed in Mozilla 1.2 var serialDocument = serializer.serializeToString ( xcsDoc ); if( serialDocument.indexOf( " + + + + + + + + + diff --git a/mozilla/calendar/resources/content/importExport.js b/mozilla/calendar/resources/content/importExport.js index 2f26845998d..ed0401813b4 100644 --- a/mozilla/calendar/resources/content/importExport.js +++ b/mozilla/calendar/resources/content/importExport.js @@ -124,7 +124,7 @@ function loadEventsFromFile() var buttonPressed = promptService.confirmEx(window, - "Import", "About to import " + calendarEventArray.length + " event(s). Do you want to open all events to import before importing?", + "Import", "About to import " + calendarEventArray.length + " item(s). Do you want to open all items to import before importing?", (promptService.BUTTON_TITLE_YES * promptService.BUTTON_POS_0) + (promptService.BUTTON_TITLE_NO * promptService.BUTTON_POS_1) + (promptService.BUTTON_TITLE_CANCEL * promptService.BUTTON_POS_2), @@ -169,29 +169,69 @@ function createUniqueID() function addEventsToCalendar( calendarEventArray, silent ) { + var defaultServer = gCalendarWindow.calendarManager.calendars[0]; for(var i = 0; i < calendarEventArray.length; i++) { - calendarEvent = calendarEventArray[i] + if( isEvent( calendarEventArray[i] ) ) + { + var calendarEvent = calendarEventArray[i]; - // Check if event with same ID already in Calendar. If so, import event with new ID. - if( gICalLib.fetchEvent( calendarEvent.id ) != null ) { - calendarEvent.id = createUniqueID( ); + // Check if event with same ID already in Calendar. If so, import event with new ID. + if( gICalLib.fetchEvent( calendarEvent.id ) != null ) { + calendarEvent.id = createUniqueID( ); + } + + // the start time is in zulu time, need to convert to current time + if(calendarEvent.allDay != true) + convertZuluToLocal( calendarEvent ); + + // open the event dialog with the event to add + if( silent ) + gICalLib.addEvent( calendarEvent, defaultServer.path ); + else + editNewEvent( calendarEvent ); + } + else if( isToDo( calendarEventArray[i] ) ) + { + // + calendarTodo = calendarEventArray[i]; + + // Check if task with same ID already in Calendar. If so, import task with new ID. + if( gICalLib.fetchTodo( calendarTodo.id ) != null ) { + calendarTodo.id = createUniqueID( ); + } + + // open the todo dialog with the task to add + if( silent ){alert(defaultServer.path); + gICalLib.addTodo( calendarTodo, defaultServer.path );} + else + gICalLib.addTodo( calendarTodo, defaultServer.path ); + // XXX TODO: add support to add todo using dialog + // editToDo( calendarTodo ); } - - // the start time is in zulu time, need to convert to current time - if(calendarEvent.allDay != true) - convertZuluToLocal( calendarEvent ); - - // open the event dialog with the event to add - if( silent ) - gICalLib.addEvent( calendarEvent ); - else - editNewEvent( calendarEvent ); } } const ZULU_OFFSET_MILLIS = new Date().getTimezoneOffset() * 60 * 1000; +function convertToUTC( aLocalTime ) +{ + if( calendarEvent.start.utc == false ) + { + aLocalTime.setTime( aLocalTime.getTime() + ZULU_OFFSET_MILLIS ); + aLocalTime.utc = true; + } +} + +function convertFromUTC( aUtcTime ) +{ + if( aUtcTime.utc == true ) + { + aUtcTime.setTime( aUtcTime.getTime() - ZULU_OFFSET_MILLIS ); + aUtcTime.utc = false; + } +} + function convertZuluToLocal( calendarEvent ) { if( calendarEvent.start.utc == true ) @@ -278,19 +318,20 @@ function initCalendarEvent( calendarEvent ) * Parses those events and returns an array of calendarEvents. */ -function parseIcalData( icalStr ) +function parseIcalData( icalendarString ) { var calendarEventArray = new Array(); var i,j; + var icalStr = icalendarString; while( icalStr.indexOf("BEGIN:VEVENT") != -1 ) { // try to find the begin and end of an event. ParseIcalString does not support VCALENDAR i = icalStr.indexOf("BEGIN:VEVENT"); j = icalStr.indexOf("END:VEVENT") + 10; - eventData = icalStr.substring(i, j); + var eventData = icalStr.substring(i, j); - calendarEvent = createEvent(); + var calendarEvent = createEvent(); // if parsing import iCalendar failed, add date as description if ( !calendarEvent.parseIcalString(eventData) ) @@ -306,7 +347,29 @@ function parseIcalData( icalStr ) // remove the parsed VEVENT from the calendar data to parse icalStr = icalStr.substring(j+1); } - + + icalStr = icalendarString; + while( icalStr.indexOf("BEGIN:VTODO") != -1 ) + { + // try to find the begin and end of an task. ParseIcalString does not support VCALENDAR + i = icalStr.indexOf("BEGIN:VTODO"); + j = icalStr.indexOf("END:VTODO") + 9; + var todoData = icalStr.substring(i, j); + + var calendarTodo = createToDo(); + + // if parsing import iCalendar failed, add date as description + if ( !calendarTodo.parseTodoIcalString(todoData) ) + { + // Save the parsed text as description. + calendarTodo.description = icalStr; + } + + calendarEventArray[ calendarEventArray.length ] = calendarTodo; + // remove the parsed VTODO from the calendar data to parse + icalStr = icalStr.substring(j+1); + } + return calendarEventArray; } @@ -344,18 +407,18 @@ function readDataFromFile( aFilePath, charset ) var scriptableInputStream; var tmp; // not sure what the use is for this - LocalFileInstance = Components.classes[LOCALFILE_CTRID].createInstance( nsILocalFile ); - LocalFileInstance.initWithPath( aFilePath ); + localFileInstance = Components.classes[LOCALFILE_CTRID].createInstance( nsILocalFile ); + localFileInstance.initWithPath( aFilePath ); inputStream = Components.classes[FILEIN_CTRID].createInstance( nsIFileInputStream ); try { - inputStream.init( LocalFileInstance, MODE_RDONLY, 0444, tmp ); + inputStream.init( localFileInstance, MODE_RDONLY, 0444, tmp ); scriptableInputStream = Components.classes[SCRIPTSTREAM_CTRID].createInstance( nsIScriptableInputStream); scriptableInputStream.init( inputStream ); - aDataStream = scriptableInputStream.read( -1 ); + var aDataStream = scriptableInputStream.read( -1 ); scriptableInputStream.close(); inputStream.close(); @@ -473,22 +536,27 @@ function eventArrayToICalString( calendarEventArray, doPatchForExport ) var sTextiCalendar = ""; for( var eventArrayIndex = 0; eventArrayIndex < calendarEventArray.length; ++eventArrayIndex ) { - var calendarEvent = calendarEventArray[ eventArrayIndex ].clone(); + var calendarObject = calendarEventArray[ eventArrayIndex ].clone(); // convert time to represent local to produce correct DTSTART and DTEND - if(calendarEvent.allDay != true) - convertLocalToZulu( calendarEvent ); + if( isEvent(calendarObject) && calendarObject.allDay != true ) + convertLocalToZulu( calendarObject ); // check if all required properties are available - if( calendarEvent.method == 0 ) - calendarEvent.method = calendarEvent.ICAL_METHOD_PUBLISH; - if( calendarEvent.stamp.year == 0 ) - calendarEvent.stamp.setTime( new Date() ); + if( calendarObject.method == 0 ) + calendarObject.method = calendarObject.ICAL_METHOD_PUBLISH; + if( calendarObject.stamp.year == 0 ) + calendarObject.stamp.setTime( new Date() ); - if ( doPatchForExport ) - sTextiCalendar += patchICalStringForExport( calendarEvent.getIcalString() ); + if ( isEvent(calendarObject) && doPatchForExport ) + sTextiCalendar += patchICalStringForExport( calendarObject.getIcalString() ); else - sTextiCalendar += calendarEvent.getIcalString() ; + { + if( isEvent(calendarObject) ) + sTextiCalendar += calendarObject.getIcalString(); + else + sTextiCalendar += calendarObject.getTodoIcalString(); + } } return sTextiCalendar; @@ -525,11 +593,11 @@ function patchICalStringForExport( sTextiCalendar ) function eventArrayToHTML( calendarEventArray ) { - sHTMLHeader = + const sHTMLHeader = "\n" + "\n" + "Mozilla Calendar\n" + "\n" + "\n"+ "\n"; - sHTMLFooter = + const sHTMLFooter = "\n\n\n"; var sHTMLText = sHTMLHeader; @@ -639,6 +707,7 @@ function eventArrayToXCS( calendarEventArray ) // XXX MAJOR UGLY HACK!! Serializer doesn't insert XML Declaration // http://bugzilla.mozilla.org/show_bug.cgi?id=63558 + // Fixed in Mozilla 1.2 var serialDocument = serializer.serializeToString ( xcsDoc ); if( serialDocument.indexOf( " 0 ) { @@ -75,7 +75,7 @@ function calendarUnifinderInit( ) SearchTree.treeBoxObject.ensureRowIsVisible( Index ); - SearchTree.treeBoxObject.selection.select( Index ); + SearchTree.treeBoxObject.selection.toggleSelect( Index ); } } } @@ -251,19 +251,25 @@ function getCalendarEventFromEvent( event ) } } -/** -* This is attached to the onclik attribute of the events shown in the unifinder -*/ - -function unifinderClickEvent( event ) +function unifinderOnSelect( event ) { - // only change checkbox on left mouse-button click - if( event.button != 0) - return; - var tree = document.getElementById( UnifinderTreeName ); - var ThisEvent = getCalendarEventFromEvent( event ); - var ArrayOfEvents = new Array( ThisEvent ); + var start = new Object(); + var end = new Object(); + var numRanges = tree.view.selection.getRangeCount(); + var ArrayOfEvents = new Array( ); + + for (var t=0; t