Fix bug 409249 - Creating Tasks should return an error. r=dbo

This commit is contained in:
mozilla%kewis.ch 2008-01-14 12:46:29 +00:00
Родитель e80679297c
Коммит 26458ea69b
6 изменённых файлов: 73 добавлений и 13 удалений

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

@ -95,13 +95,13 @@ var calendarController = {
isCommandEnabled: function cC_isCommandEnabled(aCommand) {
switch (aCommand) {
case "calendar_new_event_command":
return this.writable;
return this.writable && this.calendars_support_events;
case "calendar_modify_event_command":
return this.item_selected;
case "calendar_delete_event_command":
return this.selected_items_writable;
case "calendar_new_todo_command":
return this.writable;
return this.writable && this.calendars_support_tasks;
case "calendar_delete_todo_comand":
return this.writable; // XXX are selected todo items readonly?
@ -350,6 +350,32 @@ var calendarController = {
this.item_selected &&
!this.selected_events_readonly &&
(!this.offline || !this.selected_events_requires_network);
},
get calendars_support_tasks() {
// XXX We might want to cache this
var calendars = getCalendarManager().getCalendars({});
for each (var cal in calendars) {
if (isCalendarWritable(cal) &&
cal.getProperty("capabilities.tasks.supported") !== false) {
return true;
}
}
return false;
},
get calendars_support_events() {
// XXX We might want to cache this
var calendars = getCalendarManager().getCalendars({});
for each (var cal in calendars) {
if (isCalendarWritable(cal) &&
cal.getProperty("capabilities.events.supported") !== false) {
return true;
}
}
return false;
}
};

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

@ -1,4 +1,3 @@
/* -*- Mode: javascript; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
@ -186,14 +185,30 @@ function openEventDialog(calendarItem, calendar, mode, callback, job)
mode = mode || "new";
calendar = calendar || getSelectedCalendar();
var calendars = getCalendarManager().getCalendars({});
calendars = calendars.filter(function(el) { return !el.readOnly; });
calendars = calendars.filter(isCalendarWritable);
if (calendar.readOnly && mode == "new" && calendars.length < 1) {
// All calendars are marked readonly, don't show the dialog
var isItemSupported;
if (isToDo(calendarItem)) {
isItemSupported = function isTodoSupported(cal) {
return (cal.getProperty("capabilities.tasks.supported") !== false);
};
} else if (isEvent(calendarItem)) {
isItemSupported = function isEventSupported(cal) {
return (cal.getProperty("capabilities.events.supported") !== false);
};
}
// Filter out calendars that don't support the given calendar item
calendars = calendars.filter(isItemSupported);
if (mode == "new" && calendars.length < 1 &&
(!isCalendarWritable(calendar) || !isItemSupported(calendar))) {
// There are no writable calendars or no calendar supports the given
// item. Don't show the dialog.
return;
} else if (calendar.readOnly && mode == "new") {
// If the default calendar is marked readOnly, pick the first
// non-readOnly calendar
} else if (mode == "new" &&
(!isCalendarWritable(calendar) || !isItemSupported(calendar))) {
// Pick the first calendar that supports the item and is writable
calendar = calendars[0];
if (calendarItem) {
// XXX The dialog currently uses the items calendar as a first
@ -230,7 +245,7 @@ function openEventDialog(calendarItem, calendar, mode, callback, job)
// open the dialog modeless
var url = "chrome://calendar/content/sun-calendar-event-dialog.xul";
if (isInvitation || calendar.readOnly) {
if (isInvitation || !isCalendarWritable(calendar)) {
url = "chrome://calendar/content/calendar-summary-dialog.xul";
}
openDialog(url, "_blank", "chrome,titlebar,resizable", args);

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

@ -1548,7 +1548,8 @@
<parameter name="aMouseX"/>
<parameter name="aMouseY"/>
<body><![CDATA[
if (aOccurrence.calendar.readOnly) {
if (!isCalendarWritable(aOccurrence.calendar) ||
aOccurrence.calendar.getProperty("capabilities.events.supported") === false) {
return;
}
@ -1742,7 +1743,9 @@
this.calendarView.selectedDay = this.mDate;
// If the selected calendar is readOnly, we don't want any sweeping.
if (getSelectedCalendar().readOnly) {
var cal = getSelectedCalendar();
if (!isCalendarWritable(cal) ||
cal.getProperty("capabilities.events.supported") === false) {
return;
}

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

@ -131,6 +131,8 @@ interface calICalendar : nsISupports
* capabilities.attachments.supported Supports attachments
* capabilities.privacy.supported Supports a privacy state
* capabilities.priority.supported Supports the priority field
* capabilities.events.supported Supports tasks
* capabilities.tasks.supported Supports events
*
* The following capabilities are used to restrict the values for specific
* fields. An array should be specified with the values, the default

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

@ -286,6 +286,17 @@ function loadDialog(item) {
loadDateTime(item);
var isItemSupported;
if (isToDo(calendarItem)) {
isItemSupported = function isTodoSupported(cal) {
return (cal.getProperty("capabilities.tasks.supported") !== false);
};
} else if (isEvent(calendarItem)) {
isItemSupported = function isEventSupported(cal) {
return (cal.getProperty("capabilities.events.supported") !== false);
};
}
// add calendars to the calendar menulist
var calendarList = document.getElementById("item-calendar");
var calendars = getCalendarManager().getCalendars({});
@ -303,7 +314,9 @@ function loadDialog(item) {
}
}
selectIndex++;
} else if (calendar && !calendar.readOnly) {
} else if (calendar &&
isCalendarWritable(calendar) &&
isItemSupported(calendar)) {
var menuitem = calendarList.appendItem(calendar.name, i);
menuitem.calendar = calendar;
if (calendarToUse) {

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

@ -172,6 +172,7 @@ calGoogleCalendar.prototype = {
// Capabilities
case "capabilities.attachments.supported":
case "capabilities.priority.supported":
case "capabilities.tasks.supported":
return false;
case "capabilities.privacy.values":
return ["DEFAULT", "PUBLIC", "PRIVATE"];