From edb75cb3aa7fe2a0098e7d7a97a91ce5dd7f6556 Mon Sep 17 00:00:00 2001 From: "jminta%gmail.com" Date: Sat, 21 Jan 2006 18:55:22 +0000 Subject: [PATCH] Bug 296893 Unify Sunbird and Lightning event dialogs r=pavlov, ui-r=beltzner --- .../base/content/calendar-event-dialog.css | 4 + .../base/content/calendar-event-dialog.js | 435 ++++++++++++++++-- .../base/content/calendar-event-dialog.xul | 345 +++++++++----- .../base/content/calendar-item-editing.js | 33 +- .../content/calendar-recurrence-dialog.js | 41 +- .../content/calendar-recurrence-dialog.xul | 26 +- calendar/resources/content/calendar.js | 173 +------ calendar/resources/content/calendar.xul | 9 +- calendar/resources/content/calendarWindow.js | 2 +- calendar/resources/jar.mn | 16 +- calendar/resources/locale/en-US/calendar.dtd | 9 +- .../locale/en-US/calendar.properties | 1 + .../sunbird/base/content/calendar-scripts.inc | 1 + .../sunbird/base/content/calendar-sets.inc | 8 +- 14 files changed, 750 insertions(+), 353 deletions(-) diff --git a/calendar/base/content/calendar-event-dialog.css b/calendar/base/content/calendar-event-dialog.css index b873312ee65..b137fa6064c 100644 --- a/calendar/base/content/calendar-event-dialog.css +++ b/calendar/base/content/calendar-event-dialog.css @@ -1,3 +1,7 @@ label.label { text-align: right; } + +.warning-text-class { + color : red; +} diff --git a/calendar/base/content/calendar-event-dialog.js b/calendar/base/content/calendar-event-dialog.js index 33d4f625f70..8e217126ced 100644 --- a/calendar/base/content/calendar-event-dialog.js +++ b/calendar/base/content/calendar-event-dialog.js @@ -37,6 +37,10 @@ var gReadOnlyMode = false; +// If the user clicks 'More', then we set this to true. Otherwise, we don't +// load/check the stuff in this area, because it hasn't changed. +var gDetailsShown = false; + /* dialog stuff */ function onLoad() { @@ -72,7 +76,8 @@ function onLoad() updateAccept(); // update datetime pickers - updateDuedate(); + updateDueDate(); + updateEntryDate(); // update datetime pickers updateAllDay(); @@ -80,9 +85,6 @@ function onLoad() // update recurrence button updateRecurrence(); - // update alarm checkbox/label/settings button - updateAlarm(); - // update our size! window.sizeToContent(); @@ -119,8 +121,6 @@ function loadDialog(item) setElementValue("item-title", item.title); setElementValue("item-location", item.getProperty("LOCATION")); - setElementValue("item-url", item.getProperty("URL")); - setElementValue("item-description", item.getProperty("DESCRIPTION")); /* event specific properties */ if (isEvent(item)) { @@ -133,26 +133,23 @@ function loadDialog(item) } setElementValue("event-starttime", startDate.jsDate); setElementValue("event-endtime", endDate.jsDate); + document.getElementById("component-type").selectedIndex = 0; } /* todo specific properties */ if (isToDo(item)) { + var hasEntryDate = (item.entryDate != null); + setElementValue("todo-has-entrydate", hasEntryDate, "checked"); + if (hasEntryDate) + setElementValue("todo-entrydate", item.entryDate.jsDate); + var hasDueDate = (item.dueDate != null); setElementValue("todo-has-duedate", hasDueDate, "checked"); if (hasDueDate) setElementValue("todo-duedate", item.dueDate.jsDate); - setElementValue("todo-completed", item.isCompleted, "checked"); + document.getElementById("component-type").selectedIndex = 1; } - /* attendence */ - var attendeeString = ""; - for each (var attendee in item.getAttendees({})) { - if (attendeeString != "") - attendeeString += ","; - attendeeString += attendee.id.split("mailto:")[1]; - } - setElementValue("item-attendees", attendeeString); - /* item default calendar */ if (item.calendar) { var calendarList = document.getElementById("item-calendar"); @@ -167,6 +164,51 @@ function loadDialog(item) document.getElementById("item-calendar").selectedIndex = 0; } + /* Categories */ + try { + var pb2 = Components.classes["@mozilla.org/preferences-service;1"] + .getService(Components.interfaces.nsIPrefBranch2); + var categoriesString = pb2.getComplexValue("calendar.categories.names", + Components.interfaces.nsISupportsString).data; + var categoriesList = categoriesString.split( "," ); + + // insert the category already in the menulist so it doesn't get lost + var itemCategory = item.getProperty("CATEGORIES"); + if (itemCategory) { + if (categoriesString.indexOf(itemCategory) == -1) + categoriesList[categoriesList.length] = itemCategory; + } + categoriesList.sort(); + + var oldMenulist = document.getElementById("item-categories"); + while (oldMenulist.hasChildNodes()) { + oldMenulist.removeChild(oldMenulist.lastChild); + } + + var categoryMenuList = document.getElementById("item-categories"); + var indexToSelect = 0; + + // Add a 'none' option to allow users to cancel the category + var sbs = Components.classes["@mozilla.org/intl/stringbundle;1"] + .getService(Components.interfaces.nsIStringBundleService); + var props = sbs.createBundle("chrome://calendar/locale/calendar.properties"); + var noneItem = categoryMenuList.appendItem(props.GetStringFromName("None"), "NONE"); + + for (var i in categoriesList) { + var catItem = categoryMenuList.appendItem(categoriesList[i], categoriesList[i]); + catItem.value = categoriesList[i]; + if (itemCategory && categoriesList[i] == itemCategory) { + indexToSelect = parseInt(i)+1; // Add 1 because of 'None' + } + } + categoryMenuList.selectedIndex = indexToSelect; + + } catch (ex) { + // The app using this dialog doesn't support categories + document.getElementById("categories-box").collapsed = true; + } + + /* recurrence */ /* if the item is a proxy occurrence/instance, a few things aren't valid: * - Setting recurrence on the item @@ -179,15 +221,20 @@ function loadDialog(item) } else if (item.recurrenceInfo) setElementValue("item-recurrence", "true", "checked"); - /* alarms */ - if (item.alarmTime) { - var alarmLength = item.getProperty("alarmLength"); - if (alarmLength != null) { - setElementValue("alarm-length-field", alarmLength); - setElementValue("alarm-length-units", event.getProperty("alarmUnits")); - setElementValue("alarm-trigger-relation", item.getProperty("alarmRelated")); + var detailsButton = document.getElementById("calendar-event-dialog").getButton("disclosure"); + var detailsElements = document.getElementsByAttribute("details", "true"); + + if (document.getElementById("description-row").getAttribute("collapsed") != "true") { + detailsButton.setAttribute("label", lessLabel); + for each (elem in detailsElements) { + elem.collapsed = false; } - setElementValue("item-alarm", "custom"); + loadDetails(); + } else { + for each (elem in detailsElements) { + elem.collapsed = true; + } + detailsButton.setAttribute("label", moreLabel); } } @@ -195,8 +242,6 @@ function saveDialog(item) { setItemProperty(item, "title", getElementValue("item-title")); setItemProperty(item, "LOCATION", getElementValue("item-location")); - setItemProperty(item, "URL", getElementValue("item-url")); - setItemProperty(item, "DESCRIPTION", getElementValue("item-description")); if (isEvent(item)) { var startDate = jsDateToDateTime(getElementValue("event-starttime")); @@ -216,23 +261,13 @@ function saveDialog(item) } if (isToDo(item)) { + var entryDate = getElementValue("todo-has-entrydate", "checked") ? + jsDateToDateTime(getElementValue("todo-entrydate")) : null; + setItemProperty(item, "entryDate", entryDate); + var dueDate = getElementValue("todo-has-duedate", "checked") ? jsDateToDateTime(getElementValue("todo-duedate")) : null; setItemProperty(item, "dueDate", dueDate); - setItemProperty(item, "isCompleted", getElementValue("todo-completed", "checked")); - } - - /* attendence */ - item.removeAllAttendees(); - var attendees = getElementValue("item-attendees"); - if (attendees != "") { - for each (var addr in attendees.split(",")) { - if (addr != "") { - var attendee = createAttendee(); - attendee.id = "mailto:" + addr; - item.addAttendee(attendee); - } - } } /* recurrence */ @@ -244,6 +279,51 @@ function saveDialog(item) item.recurrenceInfo = null; } + /* Category */ + var category = getElementValue("item-categories"); + + if (category != "NONE") { + setItemProperty(item, "CATEGORIES", category); + } else { + item.deleteProperty("CATEGORIES"); + } + + if (!gDetailsShown) { + // We never showed the items in the 'More' box. That means that clone() + // took care of it, so just return now + dump(item.icalString + '\n'); + return; + } + + setItemProperty(item, "URL", getElementValue("item-url")); + setItemProperty(item, "DESCRIPTION", getElementValue("item-description")); + + var status; + if (isEvent(item)) { + status = getElementValue("event-status"); + } else { + status = getElementValue("todo-status"); + } + + setItemProperty(item, "STATUS", status); + setItemProperty(item, "PRIORITY", getElementValue("priority-levels")); + setItemProperty(item, "CLASS", getElementValue("privacy-menulist")); + + if (item.status == "COMPLETED" && isToDo(item)) { + item.completedDate = getElementValue("compeleted-date-picker"); + } + + setItemProperty(item, "PERCENT-COMPLETE", getElementValue("percent-complete-menulist")); + + /* attendence */ + item.removeAllAttendees(); + var attendeeListBox = document.getElementById("attendees-listbox"); + for each (kid in attendeeListBox.childNodes) { + if (kid.attendee) { + item.addAttendee(kid.attendee); + } + } + /* alarms */ var hasAlarm = (getElementValue("item-alarm") != "none"); if (!hasAlarm) { @@ -263,9 +343,15 @@ function saveDialog(item) var alarmTime = null; if (alarmRelated == "START") { - alarmTime = item.startDate.clone(); + if (isEvent(item)) + alarmTime = item.startDate.clone(); + else + alarmTime = item.entryDate.clone(); } else if (alarmRelated == "END") { - alarmTime = item.endDate.clone(); + if (isEvent(item)) + alarmTime = item.endDate.clone(); + else + alarmTime = item.dueDate.clone(); } switch (alarmUnits) { @@ -305,6 +391,11 @@ function updateTitle() } } +function updateComponentType() { + //XXX We still can't properly convert from event <-> task via QI + return; +} + function updateStyle() { const kDialogStylesheet = "chrome://calendar/content/calendar-event-dialog.css"; @@ -331,12 +422,25 @@ function updateAccept() acceptButton.removeAttribute("disabled"); // don't allow for end dates to be before start dates - var startDate = jsDateToDateTime(getElementValue("event-starttime")); - var endDate = jsDateToDateTime(getElementValue("event-endtime")); - if (endDate.compare(startDate) == -1) { + var startDate; + var endDate; + if (isEvent(window.calendarItem)) { + startDate = jsDateToDateTime(getElementValue("event-starttime")); + endDate = jsDateToDateTime(getElementValue("event-endtime")); + } else { + startDate = getElementValue("todo-has-entrydate", "checked") ? + jsDateToDateTime(getElementValue("todo-entrydate")) : null; + endDate = getElementValue("todo-has-duedate", "checked") ? + jsDateToDateTime(getElementValue("todo-duedate")) : null; + } + + var timeWarning = document.getElementById("end-time-warning"); + if (endDate && startDate && endDate.compare(startDate) == -1) { acceptButton.setAttribute("disabled", "true"); - } else if (acceptButton.getAttribute("disabled")) { + timeWarning.removeAttribute("hidden"); + } else { acceptButton.removeAttribute("disabled"); + timeWarning.setAttribute("hidden", "true"); } // can't add/edit items in readOnly calendars @@ -347,10 +451,14 @@ function updateAccept() if (gReadOnlyMode || cal.readOnly) { acceptButton.setAttribute("disabled", "true"); } + + if (!updateTaskAlarmWarnings()) { + acceptButton.setAttribute("disabled", "true"); + } return; } -function updateDuedate() +function updateDueDate() { if (!isToDo(window.calendarItem)) return; @@ -359,8 +467,49 @@ function updateDuedate() setElementValue("todo-duedate", getElementValue("todo-duedate")); setElementValue("todo-duedate", !getElementValue("todo-has-duedate", "checked"), "disabled"); + + updateAccept(); } +function updateEntryDate() +{ + if (!isToDo(window.calendarItem)) + return; + + // force something to get set if there was nothing there before + setElementValue("todo-entrydate", getElementValue("todo-entrydate")); + + setElementValue("todo-entrydate", !getElementValue("todo-has-entrydate", "checked"), "disabled"); + + updateAccept(); +} + +function updateTaskAlarmWarnings() { + document.getElementById("alarm-start-warning").setAttribute("hidden", true); + document.getElementById("alarm-end-warning").setAttribute("hidden", true); + + var alarmType = getElementValue("item-alarm"); + if (!gDetailsShown || !isToDo(window.calendarItem) || alarmType == "none") { + return true; + } + + var hasEntryDate = getElementValue("todo-has-entrydate", "checked"); + var hasDueDate = getElementValue("todo-has-duedate", "checked"); + + var alarmRelated = document.getElementById("alarm-trigger-relation").selectedItem.value; + + if ((alarmType != "custom" || alarmRelated == "START") && !hasEntryDate) { + document.getElementById("alarm-start-warning").removeAttribute("hidden"); + return false; + } + + if (alarmRelated == "END" && !hasDueDate) { + document.getElementById("alarm-end-warning").removeAttribute("hidden"); + return false; + } + + return true; +} function updateAllDay() { @@ -406,10 +555,10 @@ function updateAlarm() /* restore old values if they're around */ setAlarmFields(alarmItem); - document.getElementById("alarm-details").style.visibility = "visible"; + document.getElementById("alarm-details").removeAttribute("hidden"); break; default: - document.getElementById("alarm-details").style.visibility = "hidden"; + document.getElementById("alarm-details").setAttribute("hidden", true); var customItem = document.getElementById("alarm-custom-menuitem"); if (prevAlarmItem == customItem) { @@ -423,6 +572,9 @@ function updateAlarm() } prevAlarmItem = alarmItem; + updateAccept(); + + this.sizeToContent(); } function editRecurrence() @@ -462,7 +614,14 @@ function setItemProperty(item, propertyName, value) item.endDate = value; break; - + case "entryDate": + if (value == item.entryDate) + break; + if ((value && !item.entryDate) || + (!value && item.entryDate) || + (value.compare(item.entryDate) != 0)) + item.entryDate = value; + break; case "dueDate": if (value == item.dueDate) break; @@ -495,3 +654,179 @@ function setItemProperty(item, propertyName, value) break; } } + +function toggleDetails() { + var detailsElements = document.getElementsByAttribute("details", "true"); + var detailsButton = document.getElementById("calendar-event-dialog").getButton("disclosure"); + + if (!detailsElements[0].collapsed) { + // Hide details + for each (elem in detailsElements) { + elem.collapsed = true; + } + detailsButton.setAttribute("label", moreLabel); + this.sizeToContent(); + return; + } + + // Display details + for each (elem in detailsElements) { + elem.collapsed = false; + } + detailsButton.setAttribute("label", lessLabel); + this.sizeToContent(); + + if (gDetailsShown) { + // We've already loaded this stuff before, so we're done + return; + } + + loadDetails(); +} + +function loadDetails() { + gDetailsShown = true; + var item = window.calendarItem; + + /* attendence */ + var attendeeString = ""; + var attendeeListBox = document.getElementById("attendees-listbox"); + + var child; + while ((child = attendeeListBox.lastChild) && (child.tagName == "listitem")) { + attendeeListBox.removeChild(child); + } + + for each (var attendee in item.getAttendees({})) { + var listItem = document.createElement("listitem"); + var nameCell = document.createElement("listcell"); + nameCell.setAttribute("label", attendee.id.split("MAILTO:")[1]); + listItem.appendChild(nameCell); + + listItem.attendee = attendee; + attendeeListBox.appendChild(listItem); + } + + + /* Status */ + setElementValue("item-url", item.getProperty("URL")); + setElementValue("item-description", item.getProperty("DESCRIPTION")); + if (isEvent(item)) { + setElementValue("event-status", item.getProperty("STATUS")); + } else { + setElementValue("todo-status", item.getProperty("STATUS")); + } + + /* Task completed date */ + if (item.completedDate) { + updateToDoStatus(item.status, item.completedDate.jsDate); + } else { + updateToDoStatus(item.status); + } + + /* Priority */ + var priorityInteger = parseInt(item.priority); + if (priorityInteger >= 1 && priorityInteger <= 4) { + document.getElementById("priority-levels").selectedIndex = 3; // high priority + } else if (priorityInteger == 5) { + document.getElementById("priority-levels").selectedIndex = 2; // medium priority + } else if (priorityInteger >= 6 && priorityInteger <= 9) { + document.getElementById("priority-levels").selectedIndex = 1; // low priority + } else { + document.getElementById("priority-levels").selectedIndex = 0; // not defined + } + + /* Privacy */ + switch (item.privacy) { + case "PUBLIC": + case "PRIVATE": + case "CONFIDENTIAL": + setElementValue("privacy-menulist", item.privacy); + break; + case "": + setElementValue("private-menulist", "PUBLIC"); + break; + default: // bogus value + dump("ERROR! Event has invalid privacy string: " + item.privacy + "\n"); + break; + } + + /* alarms */ + if (item.alarmTime) { + var alarmLength = item.getProperty("alarmLength"); + if (alarmLength != null) { + setElementValue("alarm-length-field", alarmLength); + setElementValue("alarm-length-units", item.getProperty("alarmUnits")); + setElementValue("alarm-trigger-relation", item.getProperty("alarmRelated")); + } + setElementValue("item-alarm", "custom"); + } + + // update alarm checkbox/label/settings button + updateAlarm(); + + updateTaskAlarmWarnings(); +} + +function updateToDoStatus(status, passedInCompletedDate) +{ + // RFC2445 doesn't support completedDates without the todo's status + // being "COMPLETED", however twiddling the status menulist shouldn't + // destroy that information at this point (in case you change status + // back to COMPLETED). When we go to store this VTODO as .ics the + // date will get lost. + + var completedDate; + if (passedInCompletedDate) { + completedDate = passedInCompletedDate; + } else { + completedDate = null; + } + + // remember the original values + var oldPercentComplete = getElementValue("percent-complete-menulist"); + var oldCompletedDate = getElementValue("completed-date-picker"); + + switch (status) { + case "": + case "NONE": + document.getElementById("todo-status").selectedIndex = 0; + disableElement("percent-complete-menulist"); + disableElement("percent-complete-label"); + break; + case "CANCELLED": + document.getElementById("todo-status").selectedIndex = 4; + disableElement("percent-complete-menulist"); + disableElement("percent-complete-label"); + break; + case "COMPLETED": + document.getElementById("todo-status").selectedIndex = 3; + enableElement("percent-complete-menulist"); + enableElement("percent-complete-label"); + // if there isn't a completedDate, set it to now + if (!completedDate) + completedDate = new Date(); + break; + case "IN-PROCESS": + document.getElementById("todo-status").selectedIndex = 2; + disableElement("completed-date-picker"); + enableElement("percent-complete-menulist"); + enableElement("percent-complete-label"); + break; + case "NEEDS-ACTION": + document.getElementById("todo-status").selectedIndex = 1; + enableElement("percent-complete-menulist"); + enableElement("percent-complete-label"); + break; + } + + if (status == "COMPLETED") { + setElementValue("percent-complete-menulist", "100"); + setElementValue("completed-date-picker", completedDate); + enableElement("completed-date-picker"); + } else { + setElementValue("percent-complete-menulist", oldPercentComplete); + setElementValue("completed-date-picker", oldCompletedDate); + disableElement("completed-date-picker"); + } +} diff --git a/calendar/base/content/calendar-event-dialog.xul b/calendar/base/content/calendar-event-dialog.xul index 01e4baae4ef..4f5d38991a5 100644 --- a/calendar/base/content/calendar-event-dialog.xul +++ b/calendar/base/content/calendar-event-dialog.xul @@ -50,11 +50,12 @@ @@ -62,6 +63,12 @@ + - diff --git a/calendar/base/content/calendar-item-editing.js b/calendar/base/content/calendar-item-editing.js index 50771fc1074..fab84396217 100644 --- a/calendar/base/content/calendar-item-editing.js +++ b/calendar/base/content/calendar-item-editing.js @@ -37,10 +37,21 @@ /* all params are optional */ -function createEventWithDialog(calendar, startDate, endDate, summary) +function createEventWithDialog(calendar, startDate, endDate, summary, event) { const kDefaultTimezone = calendarDefaultTimezone(); - var event = createEvent(); + + + var onNewEvent = function(event, calendar, originalEvent) { + calendar.addItem(event, null); + } + + if (event) { + openEventDialog(event, calendar, "new", onNewEvent); + return; + } + + event = createEvent(); if (!startDate) { startDate = jsDateToDateTime(new Date()); @@ -84,17 +95,23 @@ function createEventWithDialog(calendar, startDate, endDate, summary) if (summary) event.title = summary; - var onNewEvent = function(event, calendar, originalEvent) { - calendar.addItem(event, null); - } - openEventDialog(event, calendar, "new", onNewEvent); } -function createTodoWithDialog(calendar, dueDate, summary) +function createTodoWithDialog(calendar, dueDate, summary, todo) { const kDefaultTimezone = calendarDefaultTimezone(); - var todo = createToDo(); + + var onNewItem = function(item, calendar, originalItem) { + calendar.addItem(item, null); + } + + if (todo) { + openEventDialog(todo, calendar, "new", onNewItem); + return; + } + + todo = createToDo(); if (calendar) { todo.calendar = calendar; diff --git a/calendar/base/content/calendar-recurrence-dialog.js b/calendar/base/content/calendar-recurrence-dialog.js index 68b39e803a7..0ab6844a4bf 100644 --- a/calendar/base/content/calendar-recurrence-dialog.js +++ b/calendar/base/content/calendar-recurrence-dialog.js @@ -52,6 +52,8 @@ function onLoad() updateDuration(); + updateAccept(); + opener.setCursor("auto"); self.focus(); @@ -171,8 +173,6 @@ function saveDialog() case 0: recRule.type = "DAILY"; var ndays = Number(getElementValue("daily-days")); - if (ndays == "") - ndays = 1; recRule.interval = ndays; break; case 1: @@ -228,6 +228,8 @@ function saveDialog() function updateDeck() { document.getElementById("period-deck").selectedIndex = Number(getElementValue("period-list")); + + updateAccept(); } function updateDuration() @@ -251,6 +253,41 @@ function updateDuration() } } +function updateAccept() +{ + var acceptButton = document.getElementById("calendar-recurrence-dialog").getButton("accept"); + acceptButton.removeAttribute("disabled", "true"); + document.getElementById("repeat-interval-warning").setAttribute("hidden", true); + document.getElementById("repeat-numberoftimes-warning").setAttribute("hidden", true); + + switch (Number(getElementValue("period-list"))) { + case 0: // daily + var ndays = Number(getElementValue("daily-days")); + if (ndays == "" || ndays < 1) { + document.getElementById("repeat-interval-warning").removeAttribute("hidden"); + acceptButton.setAttribute("disabled", "true"); + } + break; + case 3: // yearly + var nyears = Number(getElementValue("yearly-years")); + if (nyears == "" || nyears < 1) { + document.getElementById("repeat-interval-warning").removeAttribute("hidden"); + acceptButton.setAttribute("disabled", "true"); + } + break; + } + + if (document.getElementById("recurrence-duration").selectedItem.value == "ntimes") { + var ntimes = getElementValue("repeat-ntimes-count"); + if (ntimes == "" || ntimes < 1) { + document.getElementById("repeat-numberoftimes-warning").removeAttribute("hidden"); + acceptButton.setAttribute("disabled", "true"); + } + } + + this.sizeToContent(); +} + function removeSelectedException() { var exceptionList = document.getElementById("recurrence-exceptions-listbox"); diff --git a/calendar/base/content/calendar-recurrence-dialog.xul b/calendar/base/content/calendar-recurrence-dialog.xul index 83d6f8b3f87..3a81ad5a072 100644 --- a/calendar/base/content/calendar-recurrence-dialog.xul +++ b/calendar/base/content/calendar-recurrence-dialog.xul @@ -40,6 +40,7 @@ + + + + + @@ -89,7 +98,7 @@ @@ -125,13 +134,13 @@ @@ -160,7 +169,7 @@ - + @@ -173,6 +182,15 @@ + + + + + diff --git a/calendar/resources/content/calendar.js b/calendar/resources/content/calendar.js index f83f73ca6b0..4f3ff855f35 100644 --- a/calendar/resources/content/calendar.js +++ b/calendar/resources/content/calendar.js @@ -199,26 +199,6 @@ function launchPreferences() window.openDialog("chrome://calendar/content/pref/prefBird.xul", "PrefWindow", "chrome,titlebar,resizable,modal"); } -/** -* Called when the new event button is clicked -*/ -var gNewDateVariable = null; - -function newEventCommand( event ) -{ - newEvent(); -} - - -/** -* Called when the new task button is clicked -*/ - -function newToDoCommand() -{ - newToDo( null, null ); // new task button defaults to undated todo -} - function newCalendarDialog() { openCalendarWizard(); @@ -303,7 +283,7 @@ function newEvent(startDate, endDate, allDay) var calendar = getSelectedCalendarOrNull(); - editNewEvent( calendarEvent, calendar ); + createEventWithDialog(calendar, null, null, null, calendarEvent); } /* @@ -342,7 +322,7 @@ function newToDo ( startDate, dueDate ) var calendar = getSelectedCalendarOrNull(); - editNewToDo(calendarToDo, calendar); + createTodoWithDialog(calendar, null, null, calendarToDo); } /** @@ -359,133 +339,11 @@ function getSelectedCalendarOrNull() return null; } -/** -* Launch the event dialog to edit a new (created, imported, or pasted) event. -* 'calendar' is a calICalendar object. -* When the user clicks OK "addEventDialogResponse" is called -*/ - -function editNewEvent( calendarEvent, calendar ) -{ - openEventDialog(calendarEvent, - "new", - self.addEventDialogResponse, - calendar); -} - -/** -* Launch the todo dialog to edit a new (created, imported, or pasted) ToDo. -* 'calendar' is a calICalendar object. -* When the user clicks OK "addToDoDialogResponse" is called -*/ -function editNewToDo( calendarToDo, calendar ) -{ - openEventDialog(calendarToDo, - "new", - self.addToDoDialogResponse, - calendar); -} - -/** -* Called when the user clicks OK in the new event dialog -* 'calendar' is a calICalendar object. -* -* Updates the data source. The unifinder views and the calendar views will be -* notified of the change through their respective observers. -*/ - -function addEventDialogResponse( calendarEvent, calendar ) -{ - saveItem( calendarEvent, calendar, "addEvent" ); -} - - -/** -* Called when the user clicks OK in the new to do item dialog -* 'calendar' is a calICalendar object. -*/ - -function addToDoDialogResponse( calendarToDo, calendar ) -{ - addEventDialogResponse(calendarToDo, calendar); -} - - -/** -* Helper function to launch the event dialog to edit an event. -* When the user clicks OK "modifyEventDialogResponse" is called -*/ - -function editEvent( calendarEvent ) -{ - openEventDialog(calendarEvent, - "edit", - self.modifyEventDialogResponse, - null); -} - -function editToDo( calendarTodo ) -{ - openEventDialog(calendarTodo, - "edit", - self.modifyEventDialogResponse, - null); -} - -/** -* Called when the user clicks OK in the edit event dialog -* 'calendar' is a calICalendar object. -* -* Update the data source, the unifinder views and the calendar views will be -* notified of the change through their respective observers -*/ - -function modifyEventDialogResponse( calendarEvent, calendar, originalEvent ) -{ - saveItem( calendarEvent, calendar, "modifyEvent", originalEvent ); -} - - -/** -* Called when the user clicks OK in the edit event dialog -* 'calendar' is a calICalendar object. -* -* Update the data source, the unifinder views and the calendar views will be -* notified of the change through their respective observers -*/ - -function modifyToDoDialogResponse( calendarToDo, calendar, originalToDo ) -{ - modifyEventDialogResponse(calendarToDo, calendar, originalToDo); -} - - -/** PRIVATE: open event dialog in mode, and call onOk if ok is clicked. - 'mode' is "new" or "edit". - 'calendar' is default calICalendar, typically from getSelectedCalendarOrNull - **/ -function openEventDialog(calendarEvent, mode, onOk, calendar) -{ - // set up a bunch of args to pass to the dialog - var args = new Object(); - args.calendarEvent = calendarEvent; - args.mode = mode; - args.onOk = onOk; - - if( calendar ) - args.calendar = calendar; - - // wait cursor will revert to auto in eventDialog.js loadCalendarEventDialog - window.setCursor( "wait" ); - // open the dialog modally - openDialog("chrome://calendar/content/eventDialog.xul", "caEditEvent", "chrome,titlebar,modal", args ); -} - /** * This is called from the unifinder's edit command */ -function editEventCommand() +function editEvent() { if( gCalendarWindow.EventSelection.selectedEvents.length == 1 ) { @@ -493,33 +351,18 @@ function editEventCommand() if( calendarEvent != null ) { - editEvent( calendarEvent.parentItem ); + modifyEventWithDialog(calendarEvent); } } } +function editToDo(task) { + if (!task) + return; -//originalEvent is the item before edits were committed, -//used to check if there were external changes for shared calendar -function saveItem( calendarEvent, calendar, functionToRun, originalEvent ) -{ - dump(functionToRun + " " + calendarEvent.title + "\n"); - - if (functionToRun == 'addEvent') { - doTransaction('add', calendarEvent, calendar, null, null); - } else if (functionToRun == 'modifyEvent') { - // compare cal.uri because there may be multiple instances of - // calICalendar or uri for the same spec, and those instances are - // not ==. - if (!originalEvent.calendar || - (originalEvent.calendar.uri.equals(calendar.uri))) - doTransaction('modify', calendarEvent, calendar, originalEvent, null); - else - doTransaction('move', calendarEvent, calendar, originalEvent, null); - } + modifyEventWithDialog(task); } - /** * This is called from the unifinder's delete command * diff --git a/calendar/resources/content/calendar.xul b/calendar/resources/content/calendar.xul index d0df81559e8..7888870b530 100644 --- a/calendar/resources/content/calendar.xul +++ b/calendar/resources/content/calendar.xul @@ -83,10 +83,10 @@