Bug 431811-Context menu of tasks in today pane is broken [Error: taskTree has no properties];r=philipp

git-svn-id: svn://10.0.0.236/trunk@251995 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
Berend.Cornelius%sun.com 2008-05-30 19:32:03 +00:00
parent 03625dffcd
commit 03de302245
8 changed files with 154 additions and 170 deletions

View File

@ -110,7 +110,7 @@ agendaListbox.onCheckboxChange =
function onCheckboxChange(event) { function onCheckboxChange(event) {
var periodCheckbox = event.target; var periodCheckbox = event.target;
var lopen = (periodCheckbox.getAttribute("checked") == "true"); var lopen = (periodCheckbox.getAttribute("checked") == "true");
var listItem = getParentNode(periodCheckbox, "agenda-checkbox-richlist-item"); var listItem = getParentNodeOrThis(periodCheckbox, "agenda-checkbox-richlist-item");
var period = listItem.getItem(); var period = listItem.getItem();
period.open= lopen; period.open= lopen;
if (lopen) { if (lopen) {

View File

@ -215,12 +215,6 @@ var calendarController = {
case "calendar_new_todo_command": case "calendar_new_todo_command":
createTodoWithDialog(getSelectedCalendar()); createTodoWithDialog(getSelectedCalendar());
break; break;
case "calendar_modify_todo_command":
var selectedTasks = getFocusedTaskTree().selectedTasks;
for each (var task in selectedTasks) {
modifyEventWithDialog(task, null, true);
}
break;
case "calendar_delete_todo_command": case "calendar_delete_todo_command":
deleteToDoCommand(); deleteToDoCommand();
break; break;
@ -258,36 +252,6 @@ var calendarController = {
case "calendar_reload_remote_calendars": case "calendar_reload_remote_calendars":
getCompositeCalendar().refresh(); getCompositeCalendar().refresh();
break; break;
case "calendar_percentComplete-0_command":
contextChangeTaskProgress(0);
break;
case "calendar_percentComplete-25_command":
contextChangeTaskProgress(25);
break;
case "calendar_percentComplete-50_command":
contextChangeTaskProgress(50);
break;
case "calendar_percentComplete-75_command":
contextChangeTaskProgress(75);
break;
case "calendar_percentComplete-100_command":
contextChangeTaskProgress(100);
break;
case "calendar_percentComplete-100_command2":
contextChangeTaskProgress2(100);
break;
case "calendar_priority-0_command":
contextChangeTaskPriority(0);
break;
case "calendar_priority-9_command":
contextChangeTaskPriority(9);
break;
case "calendar_priority-5_command":
contextChangeTaskPriority(5);
break;
case "calendar_priority-1_command":
contextChangeTaskPriority(1);
break;
default: default:
if (this.defaultController && !this.isCalendarInForeground()) { if (this.defaultController && !this.isCalendarInForeground()) {
// The delete-button demands a special handling in mail-mode // The delete-button demands a special handling in mail-mode
@ -448,22 +412,15 @@ var calendarController = {
}, },
get todo_items_selected cC_todo_items_selected() { get todo_items_selected cC_todo_items_selected() {
var taskTree = getFocusedTaskTree(); var selectedTasks = getSelectedTasks();
if (taskTree) { return (selectedTasks.length > 0);
var selectedTasks = taskTree.selectedTasks;
return (selectedTasks.length > 0);
}
return false;
}, },
get todo_items_writable cC_todo_items_writable() { get todo_items_writable cC_todo_items_writable() {
var taskTree = getFocusedTaskTree(); var selectedTasks = getSelectedTasks();
if (taskTree) { for each (var task in selectedTasks) {
var selectedTasks = taskTree.selectedTasks; if (isCalendarWritable(task.calendar)) {
for each (var task in selectedTasks) { return true;
if (isCalendarWritable(task.calendar)) {
return true;
}
} }
} }
return false; return false;

View File

@ -81,18 +81,18 @@
<command id="calendar_week-view_command" oncommand="showCalendarView('week')"/> <command id="calendar_week-view_command" oncommand="showCalendarView('week')"/>
<command id="calendar_multiweek-view_command" oncommand="showCalendarView('multiweek')"/> <command id="calendar_multiweek-view_command" oncommand="showCalendarView('multiweek')"/>
<command id="calendar_month-view_command" oncommand="showCalendarView('month')"/> <command id="calendar_month-view_command" oncommand="showCalendarView('month')"/>
<command id="calendar_modify_todo_command" oncommand="goDoCommand('calendar_modify_todo_command')"/> <command id="calendar_modify_todo_command" oncommand="modifyTaskFromContext(event)"/>
<command id="calendar_task_category_command" oncommand="contextChangeTaskCategory(event);"/> <command id="calendar_task_category_command" oncommand="contextChangeTaskCategory(event);"/>
<command id="calendar_percentComplete-0_command" oncommand="goDoCommand('calendar_percentComplete-0_command')"/> <command id="calendar_percentComplete-0_command" oncommand="contextChangeTaskProgress(event, 0)"/>
<command id="calendar_percentComplete-25_command" oncommand="goDoCommand('calendar_percentComplete-25_command')"/> <command id="calendar_percentComplete-25_command" oncommand="contextChangeTaskProgress(event, 25)"/>
<command id="calendar_percentComplete-50_command" oncommand="goDoCommand('calendar_percentComplete-50_command')"/> <command id="calendar_percentComplete-50_command" oncommand="contextChangeTaskProgress(event, 50)"/>
<command id="calendar_percentComplete-75_command" oncommand="goDoCommand('calendar_percentComplete-75_command')"/> <command id="calendar_percentComplete-75_command" oncommand="contextChangeTaskProgress(event, 75)"/>
<command id="calendar_percentComplete-100_command" oncommand="goDoCommand('calendar_percentComplete-100_command')"/> <command id="calendar_percentComplete-100_command" oncommand="contextChangeTaskProgress(event, 100)"/>
<command id="calendar_percentComplete-100_command2" oncommand="goDoCommand('calendar_percentComplete-100_command2')"/> <command id="calendar_percentComplete-100_command2" oncommand="contextChangeTaskProgress2(event, 100)"/>
<command id="calendar_priority-0_command" oncommand="goDoCommand('calendar_priority-0_command')"/> <command id="calendar_priority-0_command" oncommand="contextChangeTaskPriority(event, 0)"/>
<command id="calendar_priority-9_command" oncommand="goDoCommand('calendar_priority-9_command')"/> <command id="calendar_priority-9_command" oncommand="contextChangeTaskPriority(event, 9)"/>
<command id="calendar_priority-5_command" oncommand="goDoCommand('calendar_priority-5_command')"/> <command id="calendar_priority-5_command" oncommand="contextChangeTaskPriority(event, 5)"/>
<command id="calendar_priority-1_command" oncommand="goDoCommand('calendar_priority-1_command')"/> <command id="calendar_priority-1_command" oncommand="contextChangeTaskPriority(event, 1)"/>
<command id="calendar_general-priority_command" oncommand="goDoCommand('calendar_general-priority_command')"/> <command id="calendar_general-priority_command" oncommand="goDoCommand('calendar_general-priority_command')"/>
<command id="calendar_toggle_orientation_command" persist="checked" oncommand="toggleOrientation()" disabled="true"/> <command id="calendar_toggle_orientation_command" persist="checked" oncommand="toggleOrientation()" disabled="true"/>
<command id="calendar_toggle_workdays_only_command" persist="checked" oncommand="toggleWorkdaysOnly()"/> <command id="calendar_toggle_workdays_only_command" persist="checked" oncommand="toggleWorkdaysOnly()"/>
@ -330,11 +330,11 @@
<menuitem id="calendar-context-converttomessage" <menuitem id="calendar-context-converttomessage"
label="&calendar.context.convertmenu.message.label;" label="&calendar.context.convertmenu.message.label;"
accesskey="&calendar.context.convertmenu.message.accesskey;" accesskey="&calendar.context.convertmenu.message.accesskey;"
oncommand="tasksToMail()"/> oncommand="tasksToMail(event)"/>
<menuitem id="calendar-context-converttoevent" <menuitem id="calendar-context-converttoevent"
label="&calendar.context.convertmenu.event.label;" label="&calendar.context.convertmenu.event.label;"
accesskey="&calendar.context.convertmenu.event.accesskey;" accesskey="&calendar.context.convertmenu.event.accesskey;"
oncommand="tasksToEvents()"/> oncommand="tasksToEvents(event)"/>
</menupopup> </menupopup>
</menu> </menu>
</menupopup> </menupopup>

View File

@ -50,8 +50,7 @@ function addCalendarNames(aEvent) {
while (calendarMenuPopup.hasChildNodes()) { while (calendarMenuPopup.hasChildNodes()) {
calendarMenuPopup.removeChild(calendarMenuPopup.lastChild); calendarMenuPopup.removeChild(calendarMenuPopup.lastChild);
} }
var taskTree = getFocusedTaskTree(); var tasks = getSelectedTasks(aEvent);
var tasks = taskTree.selectedTasks;
var tasksSelected = (tasks.length > 0); var tasksSelected = (tasks.length > 0);
if (tasksSelected) { if (tasksSelected) {
var selIndex = appendCalendarItems(tasks[0], calendarMenuPopup, null, "contextChangeTaskCalendar(event);"); var selIndex = appendCalendarItems(tasks[0], calendarMenuPopup, null, "contextChangeTaskCalendar(event);");
@ -62,8 +61,7 @@ function addCalendarNames(aEvent) {
} }
function addCategoryNames(aEvent) { function addCategoryNames(aEvent) {
var taskTree = getFocusedTaskTree(); var tasks = getSelectedTasks(aEvent);
var tasks = taskTree.selectedTasks;
var tasksSelected = (tasks.length > 0); var tasksSelected = (tasks.length > 0);
if (tasksSelected) { if (tasksSelected) {
var index = appendCategoryItems(tasks[0], aEvent.target, document.getElementById("calendar_task_category_command")); var index = appendCategoryItems(tasks[0], aEvent.target, document.getElementById("calendar_task_category_command"));
@ -92,8 +90,7 @@ function changeTaskPriorityMenu(aEvent) {
*/ */
function changeMenuByPropertyName(aEvent, aPropertyName) { function changeMenuByPropertyName(aEvent, aPropertyName) {
uncheckChildNodes(aEvent); uncheckChildNodes(aEvent);
var taskTree = getFocusedTaskTree(); var tasks = getSelectedTasks(aEvent);
var tasks = taskTree.selectedTasks;
var tasksSelected = ((tasks != null) && (tasks.length > 0)); var tasksSelected = ((tasks != null) && (tasks.length > 0));
if (tasksSelected) { if (tasksSelected) {
var task = tasks[0]; var task = tasks[0];
@ -109,33 +106,28 @@ function changeMenuByPropertyName(aEvent, aPropertyName) {
} }
function changeContextMenuForTask(aEvent) { function changeContextMenuForTask(aEvent) {
var taskTree = getFocusedTaskTree(); var tasks = getSelectedTasks(aEvent);
var tasks = taskTree.selectedTasks;
var task = null; var task = null;
var tasksSelected = (tasks.length > 0); var tasksSelected = (tasks.length > 0);
applyAttributeToMenuChildren(aEvent.target, "disabled", (!tasksSelected)); applyAttributeToMenuChildren(aEvent.target, "disabled", (!tasksSelected));
document.getElementById("calendar_new_todo_command").removeAttribute("disabled"); document.getElementById("calendar_new_todo_command").removeAttribute("disabled");
if (tasksSelected) { if (tasksSelected) {
taskTree.contextTask = task = tasks[0]; if (isPropertyValueSame(tasks, "isCompleted")) {
if (isPropertyValueSame(tasks, "isCompleted")) {; setBooleanAttribute(document.getElementById("calendar-context-markcompleted"), "checked", tasks[0].isCompleted);
setBooleanAttribute(document.getElementById("calendar-context-markcompleted"), "checked", task.isCompleted);
} else { } else {
document.getElementById("calendar-context-markcompleted").setAttribute("checked", false); document.getElementById("calendar-context-markcompleted").setAttribute("checked", false);
} }
} else {
taskTree.contextTask = null;
} }
} }
function contextChangeTaskProgress2(aProgress) { function contextChangeTaskProgress2(aEvent, aProgress) {
contextChangeTaskProgress(aProgress); contextChangeTaskProgress(aEvent, aProgress);
document.getElementById("calendar_percentComplete-100_command2").checked = false; document.getElementById("calendar_percentComplete-100_command2").checked = false;
} }
function contextChangeTaskProgress(aProgress) { function contextChangeTaskProgress(aEvent, aProgress) {
startBatchTransaction(); startBatchTransaction();
var taskTree = getFocusedTaskTree(); var tasks = getSelectedTasks(aEvent);
var tasks = taskTree.selectedTasks;
for (var t = 0; t < tasks.length; t++) { for (var t = 0; t < tasks.length; t++) {
var task = tasks[t]; var task = tasks[t];
var newTask = task.clone().QueryInterface( Components.interfaces.calITodo ); var newTask = task.clone().QueryInterface( Components.interfaces.calITodo );
@ -159,8 +151,7 @@ function contextChangeTaskProgress(aProgress) {
function contextChangeTaskCategory(aEvent) { function contextChangeTaskCategory(aEvent) {
startBatchTransaction(); startBatchTransaction();
var taskTree = getFocusedTaskTree(); var tasks = getSelectedTasks(aEvent);
var tasks = taskTree.selectedTasks;
var tasksSelected = (tasks.length > 0); var tasksSelected = (tasks.length > 0);
if (tasksSelected) { if (tasksSelected) {
var menuItem = aEvent.target; var menuItem = aEvent.target;
@ -175,8 +166,7 @@ function contextChangeTaskCategory(aEvent) {
function contextChangeTaskCalendar(aEvent) { function contextChangeTaskCalendar(aEvent) {
startBatchTransaction(); startBatchTransaction();
var taskTree = getFocusedTaskTree(); var tasks = getSelectedTasks(aEvent);
var tasks = taskTree.selectedTasks;
for (var t = 0; t < tasks.length; t++) { for (var t = 0; t < tasks.length; t++) {
var task = tasks[t]; var task = tasks[t];
var newTask = task.clone().QueryInterface( Components.interfaces.calITodo ); var newTask = task.clone().QueryInterface( Components.interfaces.calITodo );
@ -186,10 +176,9 @@ function contextChangeTaskCalendar(aEvent) {
endBatchTransaction(); endBatchTransaction();
} }
function contextChangeTaskPriority(aPriority) { function contextChangeTaskPriority(aEvent, aPriority) {
startBatchTransaction(); startBatchTransaction();
var taskTree = getFocusedTaskTree(); var tasks = getSelectedTasks(aEvent);
var tasks = taskTree.selectedTasks;
for (var t = 0; t < tasks.length; t++) { for (var t = 0; t < tasks.length; t++) {
var task = tasks[t]; var task = tasks[t];
var newTask = task.clone().QueryInterface( Components.interfaces.calITodo ); var newTask = task.clone().QueryInterface( Components.interfaces.calITodo );
@ -199,9 +188,8 @@ function contextChangeTaskPriority(aPriority) {
endBatchTransaction(); endBatchTransaction();
} }
function modifyTaskFromContext() { function modifyTaskFromContext(aEvent) {
var taskTree = getFocusedTaskTree(); var tasks = getSelectedTasks(aEvent);
var tasks = taskTree.selectedTasks;
for (var t = 0; t < tasks.length; t++) { for (var t = 0; t < tasks.length; t++) {
modifyEventWithDialog(tasks[t], null, true); modifyEventWithDialog(tasks[t], null, true);
} }
@ -210,32 +198,43 @@ function modifyTaskFromContext() {
/** /**
* Delete the current selected item with focus from the task tree * Delete the current selected item with focus from the task tree
*/ */
function deleteToDoCommand(aDoNotConfirm) { function deleteToDoCommand(aEvent, aDoNotConfirm) {
var taskTree = getFocusedTaskTree(); var tasks = getSelectedTasks(aEvent);
var selectedItems = taskTree.selectedTasks; calendarViewController.deleteOccurrences(tasks.length,
calendarViewController.deleteOccurrences(selectedItems.length, tasks,
selectedItems,
false, false,
aDoNotConfirm); aDoNotConfirm);
} }
function getFocusedTaskTree() { function getSelectedTasks(aEvent) {
// Which tree is focused depends on the mode. var taskTree = null;
var taskTree; if (aEvent == null) {
var focusedElement = document.commandDispatcher.focusedElement; taskTree = document.getElementById("calendar-task-tree");
taskTree = getParentNode(focusedElement, "calendar-task-tree"); } else {
return taskTree; // If the MenuItem is part of the application menu we can get the related
// tree by querying the "tree" attribute that has been attached to
// the parental popupMenu
taskTree = getParentNodeOrThisByAttribute(aEvent.target, "tree", "calendar-task-tree");
if (taskTree == null) {
// in this case we know that the menuitem is part of a context menu
taskTree = getParentNodeOrThis(document.popupNode, "calendar-task-tree");
}
}
if (taskTree != null) {
return taskTree.selectedTasks;
}
else {
return [];
}
} }
function tasksToMail() { function tasksToMail(aEvent) {
var taskTree = getFocusedTaskTree(); var tasks = getSelectedTasks(aEvent);
var tasks = taskTree.selectedTasks;
calendarMailButtonDNDObserver.onDropItems(tasks); calendarMailButtonDNDObserver.onDropItems(tasks);
} }
function tasksToEvents() { function tasksToEvents(aEvent) {
var taskTree = getFocusedTaskTree(); var tasks = getSelectedTasks(aEvent);
var tasks = taskTree.selectedTasks;
calendarCalendarButtonDNDObserver.onDropItems(tasks); calendarCalendarButtonDNDObserver.onDropItems(tasks);
} }

View File

@ -125,7 +125,6 @@
<field name="mLoadCount">0</field> <field name="mLoadCount">0</field>
<field name="mTaskArray">[]</field> <field name="mTaskArray">[]</field>
<field name="mHash2Index"><![CDATA[({})]]></field> <field name="mHash2Index"><![CDATA[({})]]></field>
<field name="mContextTask">null</field>
<field name="mRefreshQueue">[]</field> <field name="mRefreshQueue">[]</field>
<field name="mPendingRefresh">null</field> <field name="mPendingRefresh">null</field>
<field name="mShowCompletedTasks">true</field> <field name="mShowCompletedTasks">true</field>
@ -224,16 +223,6 @@
]]></body> ]]></body>
</method> </method>
<property name="contextTask">
<getter><![CDATA[
return this.mContextTask;
]]></getter>
<setter><![CDATA[
this.mContextTask = val;
return this.mContextTask;
]]></setter>
</property>
<field name="mTreeView"><![CDATA[ <field name="mTreeView"><![CDATA[
({ ({
/** /**

View File

@ -107,7 +107,7 @@
<implementation> <implementation>
<field name="kMinimonth">null</field> <field name="kMinimonth">null</field>
<constructor><![CDATA[ <constructor><![CDATA[
this.kMinimonth = getParentNode(this, "minimonth"); this.kMinimonth = getParentNodeOrThis(this, "minimonth");
]]></constructor> ]]></constructor>
<property name="month"> <property name="month">
<setter><![CDATA[ <setter><![CDATA[
@ -201,7 +201,7 @@
<field name="mPopup">null</field> <field name="mPopup">null</field>
<field name="mScrollYearsHandler">{}</field> <field name="mScrollYearsHandler">{}</field>
<constructor><![CDATA[ <constructor><![CDATA[
this.kMinimonth = getParentNode(this, "minimonth"); this.kMinimonth = getParentNodeOrThis(this, "minimonth");
document.getAnonymousElementByAttribute(this, "anonid", "left-button").kMinimonth = this.kMinimonth; document.getAnonymousElementByAttribute(this, "anonid", "left-button").kMinimonth = this.kMinimonth;
document.getAnonymousElementByAttribute(this, "anonid", "today-button").kMinimonth = this.kMinimonth; document.getAnonymousElementByAttribute(this, "anonid", "today-button").kMinimonth = this.kMinimonth;
document.getAnonymousElementByAttribute(this, "anonid", "right-button").kMinimonth = this.kMinimonth; document.getAnonymousElementByAttribute(this, "anonid", "right-button").kMinimonth = this.kMinimonth;
@ -367,7 +367,7 @@
<handler event="click"> <handler event="click">
<![CDATA[ <![CDATA[
var element = event.originalTarget; var element = event.originalTarget;
var popup = getParentNode(element, "popup"); var popup = getParentNodeOrThis(element, "popup");
if (popup) { if (popup) {
var anonid = popup.getAttribute("anonid") var anonid = popup.getAttribute("anonid")
switch(anonid) { switch(anonid) {

View File

@ -1987,12 +1987,50 @@ function setBooleanAttribute(aXulElement, aAttribute, aValue) {
} }
} }
function getParentNode(aNode, aLocalName) { /**
var node = aNode; * returns a parentnode - or the overgiven node - with the given localName,
do { * by "walking up" the DOM-hierarchy.
node = node && node.parentNode; *
} while (node && (node.localName != aLocalName)); * @param aChildNode The childnode.
return node; * @param aLocalName The localName of the to-be-returned parent
* that is looked for.
* @return The parent with the given localName or the
* given childNode 'aChildNode'. If no appropriate
* parent node with aLocalName could be
* retrieved it is returned 'null'.
*/
function getParentNodeOrThis(aChildNode, aLocalName) {
var node = aChildNode;
while (node && (node.localName != aLocalName)) {
node = node.parentNode;
if (node.tagName == undefined) {
return null;
}
};
return node;
}
/**
* Returns a parentnode - or the overgiven node - with the given attributevalue
* for the given attributename by "walking up" the DOM-hierarchy.
*
* @param aChildNode The childnode.
* @param aAttibuteName The name of the attribute that is to be compared with
* @param aAttibuteValue The value of the attribute that is to be compared with
* @return The parent with the given attributeName set that has
* the same value as the given given attributevalue
* 'aAttributeValue'. If no appropriate
* parent node can be retrieved it is returned 'null'.
*/
function getParentNodeOrThisByAttribute(aChildNode, aAttributeName, aAttributeValue) {
var node = aChildNode;
while (node && (node.getAttribute(aAttributeName) != aAttributeValue)) {
node = node.parentNode;
if (node.tagName == undefined) {
return null;
}
};
return node;
} }
function setItemProperty(item, propertyName, aValue, aCapability) { function setItemProperty(item, propertyName, aValue, aCapability) {

View File

@ -548,6 +548,7 @@ function copyPopupMenus() {
addToPopupList(menulist[2], null, taskpopuplist, excludeList, true, true); addToPopupList(menulist[2], null, taskpopuplist, excludeList, true, true);
addToPopupList(menulist[3], document.getElementById("calendar-GoPopupMenu"), taskpopuplist, excludeList, true, false); addToPopupList(menulist[3], document.getElementById("calendar-GoPopupMenu"), taskpopuplist, excludeList, true, false);
var tasksViewMenuPopup = clonePopupMenu("taskitem-context-menu", "taskitem-menu", "menu-"); var tasksViewMenuPopup = clonePopupMenu("taskitem-context-menu", "taskitem-menu", "menu-");
tasksViewMenuPopup.setAttribute("tree", "calendar-task-tree");
tasksViewMenuPopup.removeChild(getMenuElementById("menu-" + "task-context-menu-modify", tasksViewMenuPopup)); tasksViewMenuPopup.removeChild(getMenuElementById("menu-" + "task-context-menu-modify", tasksViewMenuPopup));
tasksViewMenuPopup.removeChild(getMenuElementById("menu-" + "task-context-menu-delete", tasksViewMenuPopup)); tasksViewMenuPopup.removeChild(getMenuElementById("menu-" + "task-context-menu-delete", tasksViewMenuPopup));
addToPopupList(menulist[4], tasksViewMenuPopup, taskpopuplist, excludeList, false, false); addToPopupList(menulist[4], tasksViewMenuPopup, taskpopuplist, excludeList, false, false);