2001-11-07 20:29:04 +00:00
/ * * * * * * B E G I N L I C E N S E B L O C K * * * * *
2001-11-07 19:18:46 +00:00
* 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 .
*
2001-11-07 20:29:04 +00:00
* The Original Code is OEone Calendar Code , released October 31 st , 2001.
2001-11-07 19:18:46 +00:00
*
* The Initial Developer of the Original Code is
* OEone Corporation .
2001-11-07 20:29:04 +00:00
* Portions created by the Initial Developer are Copyright ( C ) 2001
* the Initial Developer . All Rights Reserved .
2001-11-07 19:18:46 +00:00
*
2001-11-07 20:29:04 +00:00
* Contributor ( s ) : Garth Smedley < garths @ oeone . com >
* Mike Potter < mikep @ oeone . com >
2002-03-28 19:47:17 +00:00
* Colin Phillips < colinp @ oeone . com >
2002-03-05 13:59:24 +00:00
* Chris Charabaruk < coldacid @ meldstar . com >
2001-11-07 19:18:46 +00: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 .
*
2001-11-07 20:29:04 +00:00
* * * * * * END LICENSE BLOCK * * * * * * /
2001-11-07 19:18:46 +00:00
2001-11-07 20:59:04 +00:00
/ * * * * * c a l e n d a r / c a l e n d a r E v e n t D i a l o g . j s
2001-11-07 19:18:46 +00:00
* AUTHOR
* Garth Smedley
* REQUIRED INCLUDES
2001-12-20 16:09:18 +00:00
* < script type = "application/x-javascript" src = "chrome://calendar/content/dateUtils.js" / >
* < script type = "application/x-javascript" src = "chrome://calendar/content/calendarEvent.js" / >
2001-11-07 19:18:46 +00:00
*
* NOTES
* Code for the calendar ' s new / e d i t e v e n t d i a l o g .
*
* Invoke this dialog to create a new event as follows :
var args = new Object ( ) ;
args . mode = "new" ; // "new" or "edit"
args . onOk = < function > ; // funtion to call when OK is clicked
args . calendarEvent = calendarEvent ; // newly creatd calendar event to be editted
*
* Invoke this dialog to edit an existing event as follows :
*
var args = new Object ( ) ;
args . mode = "edit" ; // "new" or "edit"
args . onOk = < function > ; // funtion to call when OK is clicked
args . calendarEvent = calendarEvent ; // javascript object containin the event to be editted
* When the user clicks OK the onOk function will be called with a calendar event object .
*
*
* IMPLEMENTATION NOTES
* * * * * * * * * *
* /
/ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* W I N D O W V A R I A B L E S
* /
var gEvent ; // event being edited
var gOnOkFunction ; // function to be called when user clicks OK
var gTimeDifference = 3600000 ; //when editing an event, we change the end time if the start time is changing. This is the difference for the event time.
2002-01-30 15:22:19 +00:00
var gDefaultAlarmLength = 15 ; //number of minutes to default the alarm to
2002-01-30 15:45:39 +00:00
var gCategoryManager ;
2001-11-07 19:18:46 +00:00
var gMode = '' ; //what mode are we in? new or edit...
2001-12-20 20:13:53 +00:00
const kRepeatDay _0 = 1 ; //Sunday
const kRepeatDay _1 = 2 ; //Monday
const kRepeatDay _2 = 4 ; //Tuesday
const kRepeatDay _3 = 8 ; //Wednesday
const kRepeatDay _4 = 16 ; //Thursday
const kRepeatDay _5 = 32 ; //Friday
const kRepeatDay _6 = 64 ; //Saturday
2001-11-07 19:18:46 +00:00
/ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* W I N D O W F U N C T I O N S
* /
/ * *
* Called when the dialog is loaded .
* /
function loadCalendarEventDialog ( )
{
// Get arguments, see description at top of file
var args = window . arguments [ 0 ] ;
gMode = args . mode ;
gOnOkFunction = args . onOk ;
gEvent = args . calendarEvent ;
2002-03-27 21:53:29 +00:00
// mode is "new or "edit" - show proper header
2002-01-30 15:45:39 +00:00
var titleDataItem = null ;
2001-11-07 19:18:46 +00:00
if ( "new" == args . mode )
{
2002-01-30 15:45:39 +00:00
titleDataItem = document . getElementById ( "data-event-title-new" ) ;
2001-11-07 19:18:46 +00:00
}
else
{
2002-01-30 15:45:39 +00:00
titleDataItem = document . getElementById ( "data-event-title-edit" ) ;
2001-11-07 19:18:46 +00:00
}
var titleString = titleDataItem . getAttribute ( "value" ) ;
2002-02-06 14:16:07 +00:00
document . getElementById ( "calendar-new-eventwindow" ) . setAttribute ( "title" , titleString ) ;
2002-01-30 15:22:19 +00:00
2001-11-07 19:18:46 +00:00
// fill in fields from the event
2001-12-20 20:13:53 +00:00
var startDate = new Date ( gEvent . start . getTime ( ) ) ;
var endDate = new Date ( gEvent . end . getTime ( ) ) ;
setDateFieldValue ( "start-date-text" , startDate ) ;
2002-04-03 17:25:32 +00:00
setDateFieldValue ( "end-date-text" , endDate ) ;
2001-12-20 20:13:53 +00:00
setTimeFieldValue ( "start-time-text" , startDate ) ;
setTimeFieldValue ( "end-time-text" , endDate ) ;
gTimeDifference = gEvent . end . getTime ( ) - gEvent . start . getTime ( ) ; //the time difference in ms
if ( gEvent . recurForever )
2001-11-07 19:18:46 +00:00
{
2001-12-20 20:13:53 +00:00
var today = new Date ( ) ;
2002-04-10 18:23:40 +00:00
gEvent . recurEnd . setTime ( endDate ) ;
2001-11-07 19:18:46 +00:00
}
2002-03-27 21:53:29 +00:00
2001-12-20 20:13:53 +00:00
var recurEndDate = new Date ( gEvent . recurEnd . getTime ( ) ) ;
setDateFieldValue ( "repeat-end-date-text" , recurEndDate ) ;
2001-11-07 19:18:46 +00:00
setFieldValue ( "title-field" , gEvent . title ) ;
setFieldValue ( "description-field" , gEvent . description ) ;
setFieldValue ( "location-field" , gEvent . location ) ;
setFieldValue ( "all-day-event-checkbox" , gEvent . allDay , "checked" ) ;
setFieldValue ( "private-checkbox" , gEvent . privateEvent , "checked" ) ;
2002-01-30 15:22:19 +00:00
if ( gEvent . alarm === false && gEvent . alarmLength == 0 )
{
gEvent . alarmLength = gDefaultAlarmLength ;
}
2001-11-07 19:18:46 +00:00
setFieldValue ( "alarm-checkbox" , gEvent . alarm , "checked" ) ;
setFieldValue ( "alarm-length-field" , gEvent . alarmLength ) ;
2002-01-31 19:00:00 +00:00
setFieldValue ( "alarm-length-units" , gEvent . alarmUnits ) ;
2001-11-07 19:18:46 +00:00
if ( gEvent . alarmEmailAddress && gEvent . alarmEmailAddress != "" )
{
setFieldValue ( "alarm-email-checkbox" , true , "checked" ) ;
setFieldValue ( "alarm-email-field" , gEvent . alarmEmailAddress ) ;
}
else
{
setFieldValue ( "invite-checkbox" , false , "checked" ) ;
}
if ( gEvent . inviteEmailAddress != undefined && gEvent . inviteEmailAddress != "" )
{
setFieldValue ( "invite-checkbox" , true , "checked" ) ;
setFieldValue ( "invite-email-field" , gEvent . inviteEmailAddress ) ;
}
else
{
setFieldValue ( "invite-checkbox" , false , "checked" ) ;
}
2001-12-20 20:13:53 +00:00
setFieldValue ( "repeat-checkbox" , gEvent . recur , "checked" ) ;
2001-11-07 19:18:46 +00:00
setFieldValue ( "repeat-length-field" , gEvent . recurInterval ) ;
2002-04-03 18:09:08 +00:00
if ( gEvent . recurUnits )
setFieldValue ( "repeat-length-units" , gEvent . recurUnits ) ; //don't put the extra "value" element here, or it won't work.
else
setFieldValue ( "repeat-length-units" , "weeks" ) ;
2002-03-05 13:59:24 +00:00
setFieldValue ( "repeat-forever-radio" , ( gEvent . recurForever != undefined && gEvent . recurForever != false ) , "selected" ) ;
2002-05-06 19:11:19 +00:00
2002-03-05 13:59:24 +00:00
setFieldValue ( "repeat-until-radio" , ( gEvent . recurForever == undefined || gEvent . recurForever == false ) , "selected" ) ;
2001-11-07 19:18:46 +00:00
// update enabling and disabling
updateRepeatItemEnabled ( ) ;
updateStartEndItemEnabled ( ) ;
updateAlarmItemEnabled ( ) ;
updateInviteItemEnabled ( ) ;
2001-12-20 20:13:53 +00:00
2002-01-31 19:00:00 +00:00
//updateAlarmEmailItemEnabled();
2001-12-20 20:13:53 +00:00
/ *
* * set the advanced weekly repeating stuff
* /
setAdvancedWeekRepeat ( ) ;
2002-04-01 21:02:06 +00:00
setFieldValue ( "advanced-repeat-dayofmonth" , ( gEvent . recurWeekNumber == 0 || gEvent . recurWeekNumber == undefined ) , "selected" ) ;
setFieldValue ( "advanced-repeat-dayofweek" , ( gEvent . recurWeekNumber > 0 ) , "selected" ) ;
2001-11-07 19:18:46 +00:00
// set up OK, Cancel
doSetOKCancel ( onOKCommand , 0 ) ;
2002-05-06 19:11:19 +00:00
2001-11-07 19:18:46 +00:00
// start focus on title
var firstFocus = document . getElementById ( "title-field" ) ;
firstFocus . focus ( ) ;
}
/ * *
* Called when the OK button is clicked .
* /
function onOKCommand ( )
{
// get values from the form and put them into the event
gEvent . title = getFieldValue ( "title-field" ) ;
gEvent . description = getFieldValue ( "description-field" ) ;
gEvent . location = getFieldValue ( "location-field" ) ;
gEvent . allDay = getFieldValue ( "all-day-event-checkbox" , "checked" ) ;
2001-12-20 20:13:53 +00:00
var startDate = getDateTimeFieldValue ( "start-date-text" ) ;
gEvent . start . year = startDate . getYear ( ) + 1900 ;
gEvent . start . month = startDate . getMonth ( ) ;
gEvent . start . day = startDate . getDate ( ) ;
var startTime = getDateTimeFieldValue ( "start-time-text" ) ;
gEvent . start . hour = startTime . getHours ( ) ;
gEvent . start . minute = startTime . getMinutes ( ) ;
2001-11-07 19:18:46 +00:00
2002-04-03 17:25:32 +00:00
var endDate = getDateTimeFieldValue ( "end-date-text" ) ;
2001-11-07 19:18:46 +00:00
//do this because the end date is always the same as the start date.
2002-04-03 17:25:32 +00:00
gEvent . end . year = endDate . getYear ( ) + 1900 ;
gEvent . end . month = endDate . getMonth ( ) ;
gEvent . end . day = endDate . getDate ( ) ;
2001-12-20 20:13:53 +00:00
var endTime = getDateTimeFieldValue ( "end-time-text" ) ;
gEvent . end . hour = endTime . getHours ( ) ;
gEvent . end . minute = endTime . getMinutes ( ) ;
2001-11-07 19:18:46 +00:00
gEvent . privateEvent = getFieldValue ( "private-checkbox" , "checked" ) ;
if ( getFieldValue ( "invite-checkbox" , "checked" ) )
{
gEvent . inviteEmailAddress = getFieldValue ( "invite-email-field" , "value" ) ;
}
else
{
gEvent . inviteEmailAddress = "" ;
}
gEvent . alarm = getFieldValue ( "alarm-checkbox" , "checked" ) ;
gEvent . alarmLength = getFieldValue ( "alarm-length-field" ) ;
gEvent . alarmUnits = getFieldValue ( "alarm-length-units" , "value" ) ;
2001-12-20 20:13:53 +00:00
2002-05-06 19:11:19 +00:00
debug ( "!!!-->in calendarEventDialog.js, alarmUnits is " + gEvent . alarmUnits ) ;
2001-11-07 19:18:46 +00:00
if ( getFieldValue ( "alarm-email-checkbox" , "checked" ) )
{
gEvent . alarmEmailAddress = getFieldValue ( "alarm-email-field" , "value" ) ;
2002-05-06 19:11:19 +00:00
debug ( "!!!-->in calendarEventDialog.js, alarmEmailAddress is " + gEvent . alarmEmailAddress ) ;
2001-11-07 19:18:46 +00:00
}
else
{
gEvent . alarmEmailAddress = "" ;
}
2001-12-20 20:13:53 +00:00
gEvent . recur = getFieldValue ( "repeat-checkbox" , "checked" ) ;
2002-01-31 19:00:00 +00:00
gEvent . recurUnits = getFieldValue ( "repeat-length-units" , "value" ) ;
2002-01-31 19:40:44 +00:00
gEvent . recurForever = getFieldValue ( "repeat-forever-radio" , "selected" ) ;
2001-11-07 19:18:46 +00:00
gEvent . recurInterval = getFieldValue ( "repeat-length-field" ) ;
if ( gEvent . recurInterval == 0 )
2001-12-20 20:13:53 +00:00
gEvent . recur = false ;
2001-11-07 19:18:46 +00:00
2001-12-20 20:13:53 +00:00
var recurEndDate = getDateTimeFieldValue ( "repeat-end-date-text" ) ;
2001-11-07 19:18:46 +00:00
2001-12-20 20:13:53 +00:00
gEvent . recurEnd . setTime ( recurEndDate ) ;
gEvent . recurEnd . hour = gEvent . start . hour ;
gEvent . recurEnd . minute = gEvent . start . minute ;
2001-11-07 19:18:46 +00:00
2002-01-31 19:29:02 +00:00
if ( gEvent . recur == true )
2001-12-20 20:13:53 +00:00
{
2002-01-31 19:29:02 +00:00
//check that the repeat end time is later than the end time
if ( gEvent . recurUnits == "weeks" )
{
/ *
* * advanced weekly repeating , choosing the days to repeat
* /
gEvent . recurWeekdays = getAdvancedWeekRepeat ( ) ;
}
else if ( gEvent . recurUnits == "months" )
{
/ *
* * advanced month repeating , either every day or every date
* /
2002-04-01 20:59:48 +00:00
if ( getFieldValue ( "advanced-repeat-dayofweek" , "selected" ) == true )
2002-01-31 19:29:02 +00:00
{
gEvent . recurWeekNumber = getWeekNumberOfMonth ( ) ;
}
else
gEvent . recurWeekNumber = 0 ;
2001-12-20 20:13:53 +00:00
}
}
2002-01-31 19:29:02 +00:00
2001-12-20 20:13:53 +00:00
// :TODO: REALLY only do this if the alarm or start settings change.?
2001-11-07 19:18:46 +00:00
//if the end time is later than the start time... alert the user using text from the dtd.
2002-04-10 18:23:40 +00:00
// call caller's on OK function
gOnOkFunction ( gEvent ) ;
// tell standard dialog stuff to close the dialog
return true ;
}
function checkEndTime ( )
{
var endDate = getDateTimeFieldValue ( "end-time-text" ) ;
var startDate = getDateTimeFieldValue ( "start-time-text" ) ;
var AllDayEvent = getFieldValue ( "all-day-event-checkbox" , "checked" ) ;
if ( endDate . getTime ( ) < startDate . getTime ( ) && ! AllDayEvent )
2001-11-07 19:18:46 +00:00
{
2002-05-06 19:11:19 +00:00
document . getElementById ( "end-time-warning" ) . removeAttribute ( "collapsed" ) ;
2002-04-10 18:23:40 +00:00
2001-11-07 19:18:46 +00:00
return ( false ) ;
}
else
{
2002-04-10 18:23:40 +00:00
document . getElementById ( "end-time-warning" ) . setAttribute ( "collapsed" , "true" ) ;
return ( true ) ;
}
}
function checkRecurTime ( )
{
var recurEndDate = getDateTimeFieldValue ( "repeat-end-date-text" ) ;
var endDate = getDateTimeFieldValue ( "end-time-text" ) ;
var recurForever = getFieldValue ( "repeat-forever-radio" , "selected" ) ;
if ( recurEndDate . getTime ( ) < endDate . getTime ( ) && recurForever == false )
{
2002-05-06 19:11:19 +00:00
document . getElementById ( "repeat-time-warning" ) . removeAttribute ( "collapsed" ) ;
2001-11-07 19:18:46 +00:00
2002-04-10 18:23:40 +00:00
return ( false ) ;
}
else
{
document . getElementById ( "repeat-time-warning" ) . setAttribute ( "collapsed" , "true" ) ;
return ( true ) ;
2001-11-07 19:18:46 +00:00
}
}
2002-04-10 18:23:40 +00:00
function updateOKButton ( )
{
var CheckEndTime = checkEndTime ( ) ;
var CheckRecurTime = checkRecurTime ( ) ;
document . getElementById ( "ok" ) . setAttribute ( "disabled" , ! ( CheckEndTime && CheckRecurTime ) ) ;
}
2001-11-07 19:18:46 +00:00
/ * *
* Called when an item with a datepicker is clicked , BEFORE the picker is shown .
* /
function prepareDatePicker ( dateFieldName )
{
// get the popup and the field we are editing
var datePickerPopup = document . getElementById ( "oe-date-picker-popup" ) ;
var dateField = document . getElementById ( dateFieldName ) ;
// tell the date picker the date to edit.
2002-01-30 15:22:19 +00:00
setFieldValue ( "oe-date-picker-popup" , dateField . editDate , "value" ) ;
2001-11-07 19:18:46 +00:00
// remember the date field that is to be updated by adding a
// property "dateField" to the popup.
datePickerPopup . dateField = dateField ;
}
/ * *
* Called when a datepicker is finished , and a date was picked .
* /
function onDatePick ( datepopup )
{
// display the new date in the textbox
datepopup . dateField . value = formatDate ( datepopup . value ) ;
// remember the new date in a property, "editDate". we created on the date textbox
datepopup . dateField . editDate = datepopup . value ;
var Now = new Date ( ) ;
2002-03-27 21:53:29 +00:00
//change the end date of recurring events to today, if the new date is after today and repeat is not checked.
if ( datepopup . value > Now && ! getFieldValue ( "repeat-checkbox" , "checked" ) )
2001-11-07 19:18:46 +00:00
{
document . getElementById ( "repeat-end-date-text" ) . value = formatDate ( datepopup . value ) ;
2002-03-27 21:53:29 +00:00
document . getElementById ( "repeat-end-date-text" ) . editDate = datepopup . value ;
2001-11-07 19:18:46 +00:00
}
2001-12-20 20:13:53 +00:00
updateAdvancedWeekRepeat ( ) ;
updateAdvancedRepeatDayOfMonth ( ) ;
2002-04-10 18:23:40 +00:00
updateOKButton ( ) ;
2001-11-07 19:18:46 +00:00
}
/ * *
* Called when an item with a time picker is clicked , BEFORE the picker is shown .
* /
function prepareTimePicker ( timeFieldName )
{
// get the popup and the field we are editing
var timePickerPopup = document . getElementById ( "oe-time-picker-popup" ) ;
var timeField = document . getElementById ( timeFieldName ) ;
// tell the time picker the time to edit.
2002-01-30 15:22:19 +00:00
setFieldValue ( "oe-time-picker-popup" , timeField . editDate , "value" ) ;
2001-11-07 19:18:46 +00:00
// remember the time field that is to be updated by adding a
// property "timeField" to the popup.
timePickerPopup . timeField = timeField ;
}
/ * *
* Called when a timepicker is finished , and a time was picked .
* /
function onTimePick ( timepopup )
{
//get the new end time by adding on the time difference to the start time.
newEndDate = timepopup . value . getTime ( ) + gTimeDifference ;
newEndDate = new Date ( newEndDate ) ;
if ( newEndDate . getDate ( ) != timepopup . value . getDate ( ) ) //if this moves us to tomorrow...
{
//put us back at today, with a time of 11:55 PM.
newEndDate = new Date ( timepopup . value . getFullYear ( ) ,
timepopup . value . getMonth ( ) ,
timepopup . value . getDate ( ) ,
23 ,
55 ,
0 ) ;
}
2002-04-10 18:23:40 +00:00
2001-11-07 19:18:46 +00:00
if ( timepopup . timeField . id != "end-time-text" )
{
2002-04-10 14:38:06 +00:00
setTimeFieldValue ( "end-time-text" , newEndDate ) ;
2001-11-07 19:18:46 +00:00
}
if ( ( timepopup . timeField . id == "end-time-text" ) )
{
//if we are changing the end time, change the global duration.
var EndTime = new Date ( timepopup . value . getTime ( ) ) ;
var StartTimeElement = document . getElementById ( "start-time-text" ) ;
var StartTime = StartTimeElement . editDate ;
gTimeDifference = EndTime - StartTime ; //the time difference in ms
if ( gTimeDifference < 0 )
{
gTimeDifference = 0 ;
}
}
// display the new time in the textbox
timepopup . timeField . value = formatTime ( timepopup . value ) ;
// remember the new date in a property, "editDate". we created on the time textbox
timepopup . timeField . editDate = timepopup . value ;
2002-04-10 18:23:40 +00:00
updateOKButton ( ) ;
2001-11-07 19:18:46 +00:00
}
/ * *
* Called when the repeat checkbox is clicked .
* /
function commandRepeat ( )
{
updateRepeatItemEnabled ( ) ;
}
/ * *
* Called when the until radio is clicked .
* /
function commandUntil ( )
{
updateUntilItemEnabled ( ) ;
2002-04-10 18:23:40 +00:00
updateOKButton ( ) ;
2001-11-07 19:18:46 +00:00
}
/ * *
* Called when the all day checkbox is clicked .
* /
function commandAllDay ( )
{
updateStartEndItemEnabled ( ) ;
}
/ * *
* Called when the alarm checkbox is clicked .
* /
function commandAlarm ( )
{
updateAlarmItemEnabled ( ) ;
}
/ * *
* Enable / Disable Alarm items
* /
function updateAlarmItemEnabled ( )
{
2002-01-30 15:22:19 +00:00
var alarmCheckBox = "alarm-checkbox" ;
2001-11-07 19:18:46 +00:00
2002-01-30 15:22:19 +00:00
var alarmField = "alarm-length-field" ;
var alarmMenu = "alarm-length-units" ;
var alarmLabel = "alarm-length-text" ;
2001-11-07 19:18:46 +00:00
2002-01-30 15:22:19 +00:00
var alarmEmailCheckbox = "alarm-email-checkbox" ;
var alarmEmailField = "alarm-email-field" ;
2001-11-07 19:18:46 +00:00
2002-01-30 15:22:19 +00:00
if ( getFieldValue ( alarmCheckBox , "checked" ) )
2001-11-07 19:18:46 +00:00
{
// call remove attribute beacuse some widget code checks for the presense of a
// disabled attribute, not the value.
2002-01-30 15:22:19 +00:00
setFieldValue ( alarmField , false , "disabled" ) ;
setFieldValue ( alarmMenu , false , "disabled" ) ;
setFieldValue ( alarmLabel , false , "disabled" ) ;
setFieldValue ( alarmEmailCheckbox , false , "disabled" ) ;
2001-11-07 19:18:46 +00:00
}
else
{
2002-01-30 15:22:19 +00:00
setFieldValue ( alarmField , true , "disabled" ) ;
setFieldValue ( alarmMenu , true , "disabled" ) ;
setFieldValue ( alarmLabel , true , "disabled" ) ;
setFieldValue ( alarmEmailField , true , "disabled" ) ;
setFieldValue ( alarmEmailCheckbox , true , "disabled" ) ;
setFieldValue ( alarmEmailCheckbox , false , "checked" ) ;
2001-11-07 19:18:46 +00:00
}
}
/ * *
* Called when the alarm checkbox is clicked .
* /
function commandAlarmEmail ( )
{
updateAlarmEmailItemEnabled ( ) ;
}
/ * *
* Enable / Disable Alarm items
* /
function updateAlarmEmailItemEnabled ( )
{
2002-01-30 15:22:19 +00:00
var alarmCheckBox = "alarm-email-checkbox" ;
2001-11-07 19:18:46 +00:00
2002-01-30 15:22:19 +00:00
var alarmEmailField = "alarm-email-field" ;
2001-11-07 19:18:46 +00:00
2002-01-30 15:22:19 +00:00
if ( getFieldValue ( alarmCheckBox , "checked" ) )
2001-11-07 19:18:46 +00:00
{
// call remove attribute beacuse some widget code checks for the presense of a
// disabled attribute, not the value.
2002-01-30 15:22:19 +00:00
setFieldValue ( alarmEmailField , false , "disabled" ) ;
2001-11-07 19:18:46 +00:00
}
else
{
2002-01-30 15:22:19 +00:00
setFieldValue ( alarmEmailField , true , "disabled" ) ;
2001-11-07 19:18:46 +00:00
}
}
/ * *
* Called when the alarm checkbox is clicked .
* /
function commandInvite ( )
{
updateInviteItemEnabled ( ) ;
}
/ * *
* Enable / Disable Alarm items
* /
function updateInviteItemEnabled ( )
{
var inviteCheckBox = document . getElementById ( "invite-checkbox" ) ;
var inviteField = document . getElementById ( "invite-email-field" ) ;
2002-01-30 15:22:19 +00:00
2001-11-07 19:18:46 +00:00
if ( inviteCheckBox . checked )
{
// call remove attribute beacuse some widget code checks for the presense of a
// disabled attribute, not the value.
inviteField . removeAttribute ( "disabled" ) ;
}
else
{
inviteField . setAttribute ( "disabled" , "true" ) ;
}
}
/ * *
* Enable / Disable Repeat items
* /
function updateRepeatItemEnabled ( )
{
var repeatCheckBox = document . getElementById ( "repeat-checkbox" ) ;
2001-12-20 20:13:53 +00:00
var repeatDisableList = document . getElementsByAttribute ( "disable-controller" , "repeat" ) ;
2001-11-07 19:18:46 +00:00
if ( repeatCheckBox . checked )
{
// call remove attribute beacuse some widget code checks for the presense of a
// disabled attribute, not the value.
2001-12-20 20:13:53 +00:00
for ( var i = 0 ; i < repeatDisableList . length ; ++ i )
{
2002-01-30 15:22:19 +00:00
if ( repeatDisableList [ i ] . getAttribute ( "today" ) != "true" )
repeatDisableList [ i ] . removeAttribute ( "disabled" ) ;
2001-12-20 20:13:53 +00:00
}
2001-11-07 19:18:46 +00:00
}
else
{
2001-12-20 20:13:53 +00:00
for ( var j = 0 ; j < repeatDisableList . length ; ++ j )
{
repeatDisableList [ j ] . setAttribute ( "disabled" , "true" ) ;
}
2001-11-07 19:18:46 +00:00
}
2001-12-20 20:13:53 +00:00
// udpate plural/singular
updateRepeatPlural ( ) ;
updateAlarmPlural ( ) ;
2001-11-07 19:18:46 +00:00
// update until items whenever repeat changes
updateUntilItemEnabled ( ) ;
2001-12-20 20:13:53 +00:00
// extra interface depending on units
2002-01-31 19:00:00 +00:00
2002-01-30 15:22:19 +00:00
updateRepeatUnitExtensions ( ) ;
2001-12-20 20:13:53 +00:00
}
/ * *
* Update plural singular menu items
* /
function updateRepeatPlural ( )
{
updateMenuPlural ( "repeat-length-field" , "repeat-length-units" ) ;
}
/ * *
* Update plural singular menu items
* /
function updateAlarmPlural ( )
{
updateMenuPlural ( "alarm-length-field" , "alarm-length-units" ) ;
2001-11-07 19:18:46 +00:00
}
2001-12-20 20:13:53 +00:00
/ * *
* Update plural singular menu items
* /
function updateMenuPlural ( lengthFieldId , menuId )
{
var field = document . getElementById ( lengthFieldId ) ;
var menu = document . getElementById ( menuId ) ;
// figure out whether we should use singular or plural
var length = field . value ;
var newLabelNumber ;
if ( Number ( length ) > 1 )
{
newLabelNumber = "labelplural"
}
else
{
newLabelNumber = "labelsingular"
}
// see what we currently show and change it if required
var oldLabelNumber = menu . getAttribute ( "labelnumber" ) ;
if ( newLabelNumber != oldLabelNumber )
{
// remember what we are showing now
menu . setAttribute ( "labelnumber" , newLabelNumber ) ;
// update the menu items
var items = menu . getElementsByTagName ( "menuitem" ) ;
for ( var i = 0 ; i < items . length ; ++ i )
{
var menuItem = items [ i ] ;
var newLabel = menuItem . getAttribute ( newLabelNumber ) ;
menuItem . label = newLabel ;
menuItem . setAttribute ( "label" , newLabel ) ;
}
// force the menu selection to redraw
var saveSelectedIndex = menu . selectedIndex ;
menu . selectedIndex = - 1 ;
menu . selectedIndex = saveSelectedIndex ;
}
}
2001-11-07 19:18:46 +00:00
/ * *
* Enable / Disable Until items
* /
function updateUntilItemEnabled ( )
{
var repeatUntilRadio = document . getElementById ( "repeat-until-radio" ) ;
var repeatCheckBox = document . getElementById ( "repeat-checkbox" ) ;
var repeatEndText = document . getElementById ( "repeat-end-date-text" ) ;
var repeatEndPicker = document . getElementById ( "repeat-end-date-button" ) ;
2002-01-31 19:00:00 +00:00
2002-01-30 15:22:19 +00:00
if ( repeatCheckBox . checked && repeatUntilRadio . selected )
2001-11-07 19:18:46 +00:00
{
repeatEndText . removeAttribute ( "disabled" ) ;
repeatEndText . setAttribute ( "popup" , "oe-date-picker-popup" ) ;
repeatEndPicker . removeAttribute ( "disabled" ) ;
repeatEndPicker . setAttribute ( "popup" , "oe-date-picker-popup" ) ;
}
else
{
repeatEndText . setAttribute ( "disabled" , "true" ) ;
repeatEndText . removeAttribute ( "popup" ) ;
repeatEndPicker . setAttribute ( "disabled" , "true" ) ;
repeatEndPicker . removeAttribute ( "popup" ) ;
}
}
2001-12-20 20:13:53 +00:00
function updateRepeatUnitExtensions ( )
2001-11-16 18:50:06 +00:00
{
2001-12-20 20:13:53 +00:00
var repeatMenu = document . getElementById ( "repeat-length-units" ) ;
var weekExtensions = document . getElementById ( "repeat-extenstions-week" ) ;
var monthExtensions = document . getElementById ( "repeat-extenstions-month" ) ;
2001-11-16 18:50:06 +00:00
2001-12-20 20:13:53 +00:00
//FIX ME! WHEN THE WINDOW LOADS, THIS DOESN'T EXIST
if ( repeatMenu . selectedItem )
2001-11-16 18:50:06 +00:00
{
2001-12-20 20:13:53 +00:00
switch ( repeatMenu . selectedItem . value )
2002-03-05 14:52:40 +00:00
{
2001-12-20 20:13:53 +00:00
case "days" :
weekExtensions . setAttribute ( "collapsed" , "true" ) ;
monthExtensions . setAttribute ( "collapsed" , "true" ) ;
break ;
case "weeks" :
2002-05-06 19:11:19 +00:00
weekExtensions . removeAttribute ( "collapsed" ) ;
2001-12-20 20:13:53 +00:00
monthExtensions . setAttribute ( "collapsed" , "true" ) ;
updateAdvancedWeekRepeat ( ) ;
break ;
case "months" :
weekExtensions . setAttribute ( "collapsed" , "true" ) ;
2002-05-06 19:11:19 +00:00
monthExtensions . removeAttribute ( "collapsed" ) ;
2001-12-20 20:13:53 +00:00
updateAdvancedRepeatDayOfMonth ( ) ;
break ;
case "years" :
weekExtensions . setAttribute ( "collapsed" , "true" ) ;
monthExtensions . setAttribute ( "collapsed" , "true" ) ;
break ;
2002-03-05 14:52:40 +00:00
}
sizeToContent ( ) ;
2001-11-16 18:50:06 +00:00
}
2001-12-20 20:13:53 +00:00
2001-11-16 18:50:06 +00:00
}
2001-12-20 20:13:53 +00:00
2001-11-16 18:50:06 +00:00
2001-11-07 19:18:46 +00:00
/ * *
* Enable / Disable Start / End items
* /
function updateStartEndItemEnabled ( )
{
var allDayCheckBox = document . getElementById ( "all-day-event-checkbox" ) ;
var startTimeLabel = document . getElementById ( "start-time-label" ) ;
var startTimePicker = document . getElementById ( "start-time-button" ) ;
var startTimeText = document . getElementById ( "start-time-text" ) ;
var endTimeLabel = document . getElementById ( "end-time-label" ) ;
var endTimePicker = document . getElementById ( "end-time-button" ) ;
var endTimeText = document . getElementById ( "end-time-text" ) ;
2002-01-30 15:22:19 +00:00
2001-11-07 19:18:46 +00:00
if ( allDayCheckBox . checked )
{
// disable popups by removing the popup attribute
startTimeLabel . setAttribute ( "disabled" , "true" ) ;
startTimeText . setAttribute ( "disabled" , "true" ) ;
startTimeText . removeAttribute ( "popup" ) ;
startTimePicker . setAttribute ( "disabled" , "true" ) ;
startTimePicker . removeAttribute ( "popup" ) ;
endTimeLabel . setAttribute ( "disabled" , "true" ) ;
endTimeText . setAttribute ( "disabled" , "true" ) ;
endTimeText . removeAttribute ( "popup" ) ;
endTimePicker . setAttribute ( "disabled" , "true" ) ;
endTimePicker . removeAttribute ( "popup" ) ;
}
else
{
// enable popups by setting the popup attribute
startTimeLabel . removeAttribute ( "disabled" ) ;
startTimeText . removeAttribute ( "disabled" ) ;
startTimeText . setAttribute ( "popup" , "oe-time-picker-popup" ) ;
startTimePicker . removeAttribute ( "disabled" ) ;
startTimePicker . setAttribute ( "popup" , "oe-time-picker-popup" ) ;
endTimeLabel . removeAttribute ( "disabled" ) ;
endTimeText . removeAttribute ( "disabled" ) ;
endTimeText . setAttribute ( "popup" , "oe-time-picker-popup" ) ;
endTimePicker . removeAttribute ( "disabled" ) ;
endTimePicker . setAttribute ( "popup" , "oe-time-picker-popup" ) ;
}
}
2001-12-20 20:13:53 +00:00
/ * *
* Handle key down in repeat field
* /
function repeatLengthKeyDown ( repeatField )
{
updateRepeatPlural ( ) ;
}
/ * *
* Handle key down in alarm field
* /
function alarmLengthKeyDown ( repeatField )
{
updateAlarmPlural ( ) ;
}
function repeatUnitCommand ( repeatMenu )
{
updateRepeatUnitExtensions ( ) ;
}
/ *
* * Functions for advanced repeating elements
* /
function setAdvancedWeekRepeat ( )
{
var checked = false ;
if ( gEvent . recurWeekdays > 0 )
{
2002-01-31 19:00:00 +00:00
for ( var i = 0 ; i < 6 ; i ++ )
2001-12-20 20:13:53 +00:00
{
dump ( gEvent . recurWeekdays | eval ( "kRepeatDay_" + i ) ) ;
checked = ( ( gEvent . recurWeekdays | eval ( "kRepeatDay_" + i ) ) == eval ( gEvent . recurWeekdays ) ) ;
dump ( "checked is " + checked ) ;
2002-01-30 15:22:19 +00:00
2001-12-20 20:13:53 +00:00
setFieldValue ( "advanced-repeat-week-" + i , checked , "checked" ) ;
2002-01-30 15:22:19 +00:00
setFieldValue ( "advanced-repeat-week-" + i , false , "today" ) ;
2001-12-20 20:13:53 +00:00
}
}
2002-01-30 15:22:19 +00:00
//get the day number for today.
var startTime = getDateTimeFieldValue ( "start-date-text" ) ;
var dayNumber = startTime . getDay ( ) ;
setFieldValue ( "advanced-repeat-week-" + dayNumber , "true" , "checked" ) ;
setFieldValue ( "advanced-repeat-week-" + dayNumber , "true" , "disabled" ) ;
setFieldValue ( "advanced-repeat-week-" + dayNumber , "true" , "today" ) ;
2001-12-20 20:13:53 +00:00
}
/ *
* * Functions for advanced repeating elements
* /
function getAdvancedWeekRepeat ( )
{
var Total = 0 ;
2002-01-31 19:00:00 +00:00
for ( var i = 0 ; i < 7 ; i ++ )
2001-12-20 20:13:53 +00:00
{
if ( getFieldValue ( "advanced-repeat-week-" + i , "checked" ) == true )
{
Total += eval ( "kRepeatDay_" + i ) ;
}
}
return ( Total ) ;
}
/ *
* * function to set the menu items text
* /
function updateAdvancedWeekRepeat ( )
{
//get the day number for today.
var startTime = getDateTimeFieldValue ( "start-date-text" ) ;
var dayNumber = startTime . getDay ( ) ;
2002-01-30 15:22:19 +00:00
//uncheck them all if the repeat checkbox is checked
var repeatCheckBox = document . getElementById ( "repeat-checkbox" ) ;
if ( repeatCheckBox . checked )
2001-12-20 20:13:53 +00:00
{
2002-01-30 15:22:19 +00:00
//uncheck them all
2002-01-31 19:00:00 +00:00
for ( var i = 0 ; i < 7 ; i ++ )
2002-01-30 15:22:19 +00:00
{
setFieldValue ( "advanced-repeat-week-" + i , false , "checked" ) ;
2001-12-20 20:13:53 +00:00
2002-01-30 15:22:19 +00:00
setFieldValue ( "advanced-repeat-week-" + i , false , "disabled" ) ;
setFieldValue ( "advanced-repeat-week-" + i , false , "today" ) ;
}
2001-12-20 20:13:53 +00:00
}
2002-01-30 15:22:19 +00:00
setFieldValue ( "advanced-repeat-week-" + dayNumber , "true" , "checked" ) ;
2001-12-20 20:13:53 +00:00
2002-01-30 15:22:19 +00:00
setFieldValue ( "advanced-repeat-week-" + dayNumber , "true" , "disabled" ) ;
2001-12-20 20:13:53 +00:00
2002-01-30 15:22:19 +00:00
setFieldValue ( "advanced-repeat-week-" + dayNumber , "true" , "today" ) ;
2001-12-20 20:13:53 +00:00
}
/ *
* * function to set the menu items text
* /
function updateAdvancedRepeatDayOfMonth ( )
{
//get the day number for today.
var startTime = getDateTimeFieldValue ( "start-date-text" ) ;
var dayNumber = startTime . getDate ( ) ;
var dayExtension = getDayExtension ( dayNumber ) ;
document . getElementById ( "advanced-repeat-dayofmonth" ) . setAttribute ( "label" , "On the " + dayNumber + dayExtension + " of the month" ) ;
document . getElementById ( "advanced-repeat-dayofweek" ) . setAttribute ( "label" , getWeekNumberText ( getWeekNumberOfMonth ( ) ) + " " + getDayOfWeek ( dayNumber ) + " of the month" ) ;
}
function getDayExtension ( dayNumber )
{
switch ( dayNumber )
{
case 1 :
case 21 :
case 31 :
return ( "st" ) ;
case 2 :
case 22 :
return ( "nd" ) ;
case 3 :
case 23 :
return ( "rd" ) ;
default :
return ( "th" ) ;
}
}
function getDayOfWeek ( )
{
//get the day number for today.
var startTime = getDateTimeFieldValue ( "start-date-text" ) ;
var dayNumber = startTime . getDay ( ) ;
2001-12-20 21:52:12 +00:00
var dateStringBundle = srGetStrBundle ( "chrome://calendar/locale/dateFormat.properties" ) ;
2001-12-20 20:13:53 +00:00
//add one to the dayNumber because in the above prop. file, it starts at day1, but JS starts at 0
var oneBasedDayNumber = parseInt ( dayNumber ) + 1 ;
return ( dateStringBundle . GetStringFromName ( "day." + oneBasedDayNumber + ".name" ) ) ;
}
function getWeekNumberOfMonth ( )
{
//get the day number for today.
var startTime = getDateTimeFieldValue ( "start-date-text" ) ;
var dayNumber = startTime . getDay ( ) ;
var thisMonth = startTime . getMonth ( ) ;
var monthToCompare = startTime . getMonth ( ) ;
var weekNumber = 0 ;
while ( monthToCompare == thisMonth )
{
startTime = new Date ( startTime . getTime ( ) - ( 1000 * 60 * 60 * 24 * 7 ) ) ;
monthToCompare = startTime . getMonth ( ) ;
weekNumber ++ ;
}
if ( weekNumber > 3 )
{
2002-01-31 19:00:00 +00:00
var nextWeek = new Date ( getDateTimeFieldValue ( "start-date-text" ) . getTime ( ) + ( 1000 * 60 * 60 * 24 * 7 ) ) ;
2001-12-20 20:13:53 +00:00
if ( nextWeek . getMonth ( ) != thisMonth )
{
//its the last week of the month
weekNumber = 5 ;
}
}
return ( weekNumber ) ;
}
function getWeekNumberText ( weekNumber )
{
switch ( weekNumber )
{
case 1 :
return ( "First" ) ;
case 2 :
return ( "Second" ) ;
case 3 :
return ( "Third" ) ;
case 4 :
return ( "Fourth" ) ;
case 5 :
return ( "Last" ) ;
2002-01-30 15:45:39 +00:00
default :
return ( false ) ;
2001-12-20 20:13:53 +00:00
}
}
2001-11-07 19:18:46 +00:00
/ * *
* Helper function for filling the form , set the value of a property of a XUL element
*
* PARAMETERS
* elementId - ID of XUL element to set
* newValue - value to set property to ( if undefined no change is made )
* propertyName - OPTIONAL name of property to set , default is "value" , use "checked" for
* radios & checkboxes , "data" for drop - downs
* /
function setFieldValue ( elementId , newValue , propertyName )
{
var undefined ;
if ( newValue !== undefined )
{
var field = document . getElementById ( elementId ) ;
2002-01-30 15:22:19 +00:00
if ( newValue === false )
2001-11-07 19:18:46 +00:00
{
2002-01-30 15:22:19 +00:00
field . removeAttribute ( propertyName ) ;
2001-11-07 19:18:46 +00:00
}
else
{
2002-01-30 15:22:19 +00:00
if ( propertyName )
{
field . setAttribute ( propertyName , newValue ) ;
}
else
{
field . value = newValue ;
}
2001-11-07 19:18:46 +00:00
}
}
}
/ * *
* Helper function for getting data from the form ,
* Get the value of a property of a XUL element
*
* PARAMETERS
* elementId - ID of XUL element to get from
* propertyName - OPTIONAL name of property to set , default is "value" , use "checked" for
* radios & checkboxes , "data" for drop - downs
* RETURN
* newValue - value of property
* /
function getFieldValue ( elementId , propertyName )
{
var field = document . getElementById ( elementId ) ;
if ( propertyName )
{
return field [ propertyName ] ;
}
else
{
return field . value ;
}
}
/ * *
* Helper function for getting a date / time from the form .
* The element must have been set up with setDateFieldValue or setTimeFieldValue .
*
* PARAMETERS
* elementId - ID of XUL element to get from
* RETURN
* newValue - Date value of element
* /
function getDateTimeFieldValue ( elementId )
{
var field = document . getElementById ( elementId ) ;
return field . editDate ;
}
/ * *
* Helper function for filling the form , set the value of a date field
*
* PARAMETERS
* elementId - ID of time textbox to set
* newDate - Date Object to use
* /
function setDateFieldValue ( elementId , newDate )
{
// set the value to a formatted date string
var field = document . getElementById ( elementId ) ;
field . value = formatDate ( newDate ) ;
// add an editDate property to the item to hold the Date object
// used in onDatePick to update the date from the date picker.
// used in getDateTimeFieldValue to get the Date back out.
// we clone the date object so changes made in place do not propagte
field . editDate = new Date ( newDate ) ;
}
/ * *
* Helper function for filling the form , set the value of a time field
*
* PARAMETERS
* elementId - ID of time textbox to set
* newDate - Date Object to use
* /
function setTimeFieldValue ( elementId , newDate )
{
// set the value to a formatted time string
var field = document . getElementById ( elementId ) ;
field . value = formatTime ( newDate ) ;
// add an editDate property to the item to hold the Date object
// used in onTimePick to update the date from the time picker.
// used in getDateTimeFieldValue to get the Date back out.
// we clone the date object so changes made in place do not propagte
field . editDate = new Date ( newDate ) ;
}
/ * *
* Take a Date object and return a displayable date string i . e . : May 5 , 1959
* : TODO : This should be moved into DateFormater and made to use some kind of
* locale or user date format preference .
* /
function formatDate ( date )
{
2002-04-08 20:41:42 +00:00
return ( opener . gCalendarWindow . dateFormater . getFormatedDate ( date ) ) ;
2001-11-07 19:18:46 +00:00
}
/ * *
* Take a Date object and return a displayable time string i . e . : 12 : 30 PM
* /
function formatTime ( time )
{
2002-04-08 20:41:42 +00:00
var timeString = opener . gCalendarWindow . dateFormater . getFormatedTime ( time ) ;
2001-11-07 19:18:46 +00:00
return timeString ;
}
function debug ( Text )
{
dump ( "\n" + Text + "\n" ) ;
}