Hooking up the exceptions part of the recurrence dialog so that you can restore dates that you had previously deleted. bug 298346.
git-svn-id: svn://10.0.0.236/trunk@175364 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
37c68b386e
commit
e95cbe536b
@ -44,6 +44,8 @@ function onLoad()
|
||||
window.calendarEvent = args.calendarEvent;
|
||||
window.originalRecurrenceInfo = args.recurrenceInfo;
|
||||
|
||||
window.removedExceptions = [];
|
||||
|
||||
loadDialog();
|
||||
|
||||
updateDeck();
|
||||
@ -76,77 +78,88 @@ function loadDialog()
|
||||
if (!window.originalRecurrenceInfo)
|
||||
return;
|
||||
|
||||
var ritems = window.originalRecurrenceInfo.getRecurrenceItems({});
|
||||
|
||||
/* split out rules and exceptions */
|
||||
var rules = [];
|
||||
var exceptions = [];
|
||||
|
||||
for each (var r in ritems) {
|
||||
if (r instanceof calIRecurrenceRule) {
|
||||
if (r.isNegative)
|
||||
exceptions.push(r);
|
||||
else
|
||||
rules.push(r);
|
||||
}
|
||||
}
|
||||
var rrules = splitRecurrenceRules(window.originalRecurrenceInfo);
|
||||
var rules = rrules[0];
|
||||
var exceptions = rrules[1];
|
||||
|
||||
/* deal with the rules */
|
||||
if (rules.length > 0) {
|
||||
// we only handle 1 rule currently
|
||||
var rule = rules[0];
|
||||
if (rule instanceof calIRecurrenceRule) {
|
||||
|
||||
switch(rule.type) {
|
||||
case "DAILY":
|
||||
document.getElementById("period-list").selectedIndex = 0;
|
||||
switch(rule.type) {
|
||||
case "DAILY":
|
||||
document.getElementById("period-list").selectedIndex = 0;
|
||||
|
||||
setElementValue("daily-days", rule.interval);
|
||||
break;
|
||||
case "WEEKLY":
|
||||
document.getElementById("period-list").selectedIndex = 1;
|
||||
setElementValue("daily-days", rule.interval);
|
||||
break;
|
||||
case "WEEKLY":
|
||||
document.getElementById("period-list").selectedIndex = 1;
|
||||
|
||||
const byDayTable = { 1 : "sun", 2 : "mon", 3 : "tue", 4 : "wed",
|
||||
5 : "thu", 6 : "fri", 7: "sat" };
|
||||
const byDayTable = { 1 : "sun", 2 : "mon", 3 : "tue", 4 : "wed",
|
||||
5 : "thu", 6 : "fri", 7: "sat" };
|
||||
|
||||
for each (var i in rule.getComponent("BYDAY", {})) {
|
||||
setElementValue("weekly-" + byDayTable[i], "true", "checked");
|
||||
for each (var i in rule.getComponent("BYDAY", {})) {
|
||||
setElementValue("weekly-" + byDayTable[i], "true", "checked");
|
||||
}
|
||||
break;
|
||||
case "MONTHLY":
|
||||
document.getElementById("period-list").selectedIndex = 2;
|
||||
break;
|
||||
case "YEARLY":
|
||||
document.getElementById("period-list").selectedIndex = 3;
|
||||
break;
|
||||
default:
|
||||
dump("unable to handle your rule type!\n");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "MONTHLY":
|
||||
document.getElementById("period-list").selectedIndex = 2;
|
||||
break;
|
||||
case "YEARLY":
|
||||
document.getElementById("period-list").selectedIndex = 3;
|
||||
break;
|
||||
default:
|
||||
dump("unable to handle your rule type!\n");
|
||||
break;
|
||||
}
|
||||
|
||||
/* load up the duration of the event radiogroup */
|
||||
if (rule.count == -1) {
|
||||
setElementValue("recurrence-duration", "forever");
|
||||
} else if (rule.isByCount) {
|
||||
setElementValue("recurrence-duration", "ntimes");
|
||||
setElementValue("repeat-ntimes-count", rule.count );
|
||||
} else {
|
||||
setElementValue("recurrence-duration", "until");
|
||||
setElementValue("repeat-until-date", rule.endDate.jsDate); // XXX getInTimezone()
|
||||
}
|
||||
/* load up the duration of the event radiogroup */
|
||||
if (rule.count == -1) {
|
||||
setElementValue("recurrence-duration", "forever");
|
||||
} else if (rule.isByCount) {
|
||||
setElementValue("recurrence-duration", "ntimes");
|
||||
setElementValue("repeat-ntimes-count", rule.count );
|
||||
} else {
|
||||
setElementValue("recurrence-duration", "until");
|
||||
setElementValue("repeat-until-date", rule.endDate.jsDate); // XXX getInTimezone()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Deal with exceptions */
|
||||
var exceptionListBox = document.getElementById("recurrence-exceptions-listbox");
|
||||
|
||||
// XXX handle exceptions
|
||||
for each (exception in exceptions) {
|
||||
if (exception instanceof calIRecurrenceDate) {
|
||||
exceptionListBox.appendItem(exception.date.toString()).date = exception.date;
|
||||
} else if (exception instanceof calIRecurrenceDateSet) {
|
||||
var dateSet = exception.getDates({});
|
||||
for each(date in dateSet)
|
||||
exceptionListBox.appendItem(date.toString()).date = date;
|
||||
} else
|
||||
dump(exception);
|
||||
}
|
||||
}
|
||||
|
||||
function saveDialog()
|
||||
{
|
||||
var deckNumber = Number(getElementValue("period-list"));
|
||||
|
||||
var recurrenceInfo = createRecurrenceInfo();
|
||||
recurrenceInfo.item = window.calendarEvent;
|
||||
var recurrenceInfo = null;
|
||||
if (window.originalRecurrenceInfo) {
|
||||
recurrenceInfo = window.originalRecurrenceInfo.clone();
|
||||
var rrules = splitRecurrenceRules(recurrenceInfo);
|
||||
if (rrules[0].length > 0)
|
||||
recurrenceInfo.deleteRecurrenceItem(rrules[0][0]);
|
||||
} else {
|
||||
recurrenceInfo = createRecurrenceInfo();
|
||||
recurrenceInfo.item = window.calendarEvent;
|
||||
}
|
||||
|
||||
var recRule = new calRecurrenceRule();
|
||||
|
||||
switch (deckNumber) {
|
||||
case 0:
|
||||
recRule.type = "DAILY";
|
||||
@ -197,6 +210,11 @@ function saveDialog()
|
||||
|
||||
recurrenceInfo.appendRecurrenceItem(recRule);
|
||||
|
||||
|
||||
for each (date in window.removedExceptions) {
|
||||
recurrenceInfo.restoreOccurrenceAt(date);
|
||||
}
|
||||
|
||||
return recurrenceInfo;
|
||||
}
|
||||
|
||||
@ -226,3 +244,28 @@ function updateDuration()
|
||||
setElementValue("repeat-until-date", "true", "disabled");
|
||||
}
|
||||
}
|
||||
|
||||
function removeSelectedException()
|
||||
{
|
||||
var exceptionList = document.getElementById("recurrence-exceptions-listbox");
|
||||
var item = exceptionList.selectedItem;
|
||||
window.removedExceptions.push(item.date);
|
||||
exceptionList.removeItemAt(exceptionList.getIndexOfItem(item));
|
||||
}
|
||||
|
||||
function splitRecurrenceRules(recurrenceInfo)
|
||||
{
|
||||
var ritems = recurrenceInfo.getRecurrenceItems({});
|
||||
|
||||
var rules = [];
|
||||
var exceptions = [];
|
||||
|
||||
for each (var r in ritems) {
|
||||
if (r.isNegative)
|
||||
exceptions.push(r);
|
||||
else
|
||||
rules.push(r);
|
||||
}
|
||||
|
||||
return [rules, exceptions];
|
||||
}
|
||||
|
||||
@ -185,10 +185,9 @@
|
||||
<label value="Exceptions:"/>
|
||||
|
||||
<hbox align="center">
|
||||
<listbox id="recurrence-dates-listbox" rows="8" flex="1"/>
|
||||
<vbox>
|
||||
<button label="Add..."/>
|
||||
<button label="Remove"/>
|
||||
<listbox id="recurrence-exceptions-listbox" rows="8" flex="1"/>
|
||||
<vbox align="top">
|
||||
<button label="Remove" oncommand="removeSelectedException();"/>
|
||||
</vbox>
|
||||
</hbox>
|
||||
|
||||
|
||||
@ -76,6 +76,7 @@ interface calIRecurrenceInfo : nsISupports
|
||||
|
||||
calIRecurrenceItem getRecurrenceItemAt (in unsigned long aIndex);
|
||||
void deleteRecurrenceItemAt (in unsigned long aIndex);
|
||||
void deleteRecurrenceItem (in calIRecurrenceItem aItem);
|
||||
// inserts the item at the given index, pushing the item that was previously there forward
|
||||
void insertRecurrenceItemAt (in calIRecurrenceItem aItem, in unsigned long aIndex);
|
||||
|
||||
|
||||
@ -210,6 +210,23 @@ calRecurrenceInfo.prototype = {
|
||||
this.mRecurrenceItems.splice(aIndex, 1);
|
||||
},
|
||||
|
||||
deleteRecurrenceItem: function(aItem) {
|
||||
if (!this.mBaseItem)
|
||||
throw Components.results.NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
if (this.mImmutable)
|
||||
throw Components.results.NS_ERROR_OBJECT_IS_IMMUTABLE;
|
||||
|
||||
for (var i = 0; i < this.mRecurrenceItems.length; i++) {
|
||||
if (this.mRecurrenceItems[i] == aItem) {
|
||||
this.deleteRecurrenceItemAt(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw Components.results.NS_ERROR_INVALID_ARG;
|
||||
},
|
||||
|
||||
insertRecurrenceItemAt: function(aItem, aIndex) {
|
||||
if (!this.mBaseItem)
|
||||
throw Components.results.NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user