Fix event handling for todo list. r=finally-getting-the-hang-of-this

This commit is contained in:
shaver%mozilla.org 2005-07-06 16:03:09 +00:00
parent 75933a51dc
commit 58d2456ca3
2 changed files with 38 additions and 31 deletions

View File

@ -15,21 +15,21 @@
onAddItem: function onAddItem(aItem)
{
if (!(item instanceof Components.interfaces.calITodo))
if (!(aItem instanceof Components.interfaces.calITodo))
return;
this.todoList.addTodo(aItem);
},
onDeleteItem: function onDeleteItem(aItem)
{
if (!(item instanceof Components.interfaces.calITodo))
if (!(aItem instanceof Components.interfaces.calITodo))
return;
this.todoList.rebuildDisplay();
},
onModifyItem: function onModifyItem(aItem)
{
if (!(item instanceof Components.interfaces.calITodo))
if (!(aItem instanceof Components.interfaces.calITodo))
return;
this.todoList.rebuildDisplay();
},
@ -72,6 +72,7 @@
}
})
]]></field>
<property name="calendar">
<getter><![CDATA[ return this.mCalendar; ]]></getter>
<setter><![CDATA[
@ -84,15 +85,24 @@
]]></setter>
</property>
<method name="fireEvent">
<parameter name="aEventType"/>
<body><![CDATA[
var e = document.createEvent("Events");
e.initEvent("todo-" + aEventType, false, true);
this.dispatchEvent(e);
]]></body>
</method>
<method name="addTodo">
<parameter name="aTodo"/>
<body><![CDATA[
dump("adding new todo " + aTodo.title + "\n");
void("adding new todo " + aTodo.title + "\n");
var newTodoElt = document.createElement("calendar-todo-item");
newTodoElt.setAttribute("item-calendar", aTodo.calendar.uri.spec);
this.appendChild(newTodoElt);
newTodoElt.setTodo(aTodo);
newTodoElt.todo = aTodo;
]]></body>
</method>
@ -125,7 +135,6 @@
]]></handler>
<handler event="keypress"><![CDATA[
dump("handling keypress " + event.keyCode + "\n");
const kKE = Components.interfaces.nsIDOMKeyEvent;
if (event.keyCode == kKE.DOM_VK_RETURN ||
event.keyCode == kKE.DOM_VK_ENTER) {
@ -165,19 +174,10 @@
<property name="label">
<getter><![CDATA[ return document.getAnonymousElementByAttribute(this, "anonid", "todo-label");]]></getter>
</property>
<method name="fireEvent">
<parameter name="aEventType"/>
<body>
<![CDATA[
var e = document.createEvent("Events");
e.initEvent("todo-" + aEventType, false, true);
this.dispatchEvent(e);
]]>
</body>
</method>
<property name="todo" onget="return this.mTodo;"
onset="this.mTodo = val; this.updateDisplayFromTodo();"/>
<method name="setAttribute">
<parameter name="aAttr"/>
<parameter name="aVal"/>
@ -195,13 +195,8 @@
var dirty = false;
var clone = this.mTodo.clone();
if (this.mTodo.isCompleted != this.checkbox.checked) {
dump("checked changed (" + uneval(this.mTodo.isCompleted) +
" => " + uneval(this.checkbox.checked) + "\n");
clone.isCompleted = this.checkbox.checked;
dirty = true;
} else {
dump("checked not changed (" + uneval(this.mTodo.isCompleted) +
" == " + uneval(this.checkbox.checked) + "\n");
}
if (this.mTodo.title != this.label.value) {
clone.title = this.label.value;
@ -209,7 +204,7 @@
}
if (dirty) {
this.mTodo.calendar.modifyItem(clone, this.mTodo, null);
dump(clone.icalComponent.serializeToICS() + "\n");
// dump(clone.icalComponent.serializeToICS() + "\n");
this.mTodo = clone;
}
]]></body>
@ -222,13 +217,6 @@
]]></body>
</method>
<method name="setTodo">
<parameter name="aTodo"/>
<body><![CDATA[
this.mTodo = aTodo;
this.updateDisplayFromTodo();
]]></body>
</method>
</implementation>
</binding>

View File

@ -1,7 +1,26 @@
function eventToTodo(event)
{
try {
return event.originalTarget.selectedItem.todo;
} catch (e) {
return null;
}
}
function handleTodoListEvent(event)
{
var todo = eventToTodo(event);
var name = todo ? ('"' + todo.title + '"') : "<none>";
dump("Todo list event: " + event.type + " (" + name + ")\n");
}
function initializeTodoList()
{
var todoList = document.getElementById("calendar-todo-list");
todoList.calendar = getCompositeCalendar();
todoList.addEventListener("todo-item-open", handleTodoListEvent, false);
todoList.addEventListener("todo-item-delete", handleTodoListEvent, false);
todoList.addEventListener("todo-empty-dblclick", handleTodoListEvent, false);
}
window.addEventListener("load", initializeTodoList, false);