383272-[Proto] Recurrence dialog: weekly and monthly recurrencepattern is not in sync with minimonths;r=mickey

This commit is contained in:
Berend.Cornelius%sun.com 2007-10-26 21:54:19 +00:00
Родитель 61280e749a
Коммит e900741b9e
1 изменённых файлов: 132 добавлений и 94 удалений

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

@ -63,105 +63,136 @@ function onLoad() {
if (item.parentItem != item) { if (item.parentItem != item) {
item = item.parentItem; item = item.parentItem;
} }
if (!recinfo) {
recinfo = createRecurrenceInfo();
}
// Split out rules and exceptions
var rrules = splitRecurrenceRules(recinfo);
var rules = rrules[0];
var exceptions = rrules[1];
if (recinfo) { // Deal with the rules
// Split out rules and exceptions if (rules.length > 0) {
var rrules = splitRecurrenceRules(recinfo); // We only handle 1 rule currently
var rules = rrules[0]; var rule = rules[0];
var exceptions = rrules[1]; if (rule instanceof Components.interfaces.calIRecurrenceRule) {
switch (rule.type) {
case "DAILY":
document.getElementById("period-list").selectedIndex = 0;
setElementValue("daily-days", rule.interval);
break;
case "WEEKLY":
setElementValue("weekly-weeks", rule.interval);
document.getElementById("period-list").selectedIndex = 1;
break;
case "MONTHLY":
setElementValue("monthly-interval", rule.interval);
document.getElementById("period-list").selectedIndex = 2;
break;
case "YEARLY":
setElementValue("yearly-interval", rule.interval);
document.getElementById("period-list").selectedIndex = 3;
break;
default:
dump("unable to handle your rule type!\n");
break;
}
// Deal with the rules var byDayRuleComponent = rule.getComponent("BYDAY", {});
if (rules.length > 0) { var byMonthDayRuleComponent = rule.getComponent("BYMONTHDAY", {});
// We only handle 1 rule currently var byMonthRuleComponent = rule.getComponent("BYMONTH", {});
var rule = rules[0]; var kDefaultTimezone = calendarDefaultTimezone();
if (rule instanceof Components.interfaces.calIRecurrenceRule) { var startDate = gStartTime.getInTimezone(kDefaultTimezone);
switch (rule.type) {
case "DAILY": // "DAILY" ruletype
document.getElementById("period-list").selectedIndex = 0; // byDayRuleComponents may have been set priorily by "MONTHLY"- ruletypes
setElementValue("daily-days", rule.interval); // where they have a different context-
var ruleComp = rule.getComponent("BYDAY", {}); // that's why we also query the current rule-type
if (ruleComp.length > 0) { if ((byDayRuleComponent.length == 0) || (rule.type != "DAILY")){
document.getElementById("daily-group").selectedIndex = 1; document.getElementById("daily-group").selectedIndex = 0;
} else { } else {
document.getElementById("daily-group").selectedIndex = 0; document.getElementById("daily-group").selectedIndex = 1;
} }
break;
case "WEEKLY": // "WEEKLY" ruletype
document.getElementById("period-list").selectedIndex = 1; if ((byDayRuleComponent.length == 0) || (rule.type != "WEEKLY")) {
setElementValue("weekly-weeks", rule.interval); document.getElementById("daypicker-weekday").days = [startDate.weekday + 1];
var days = rule.getComponent("BYDAY", {}); }
document.getElementById("daypicker-weekday").days = days; else {
break; document.getElementById("daypicker-weekday").days = byDayRuleComponent;
case "MONTHLY": }
document.getElementById("period-list").selectedIndex = 2;
setElementValue("monthly-interval", rule.interval); // "MONTHLY" ruletype
var ruleComp = rule.getComponent("BYDAY", {}); var ruleComponentsEmpty = ((byDayRuleComponent.length == 0) &&
if (ruleComp.length > 0) { (byMonthDayRuleComponent.length == 0));
document.getElementById("monthly-group").selectedIndex = 0; if (ruleComponentsEmpty || (rule.type != "MONTHLY")) {
var byday = ruleComp[0]; document.getElementById("monthly-group").selectedIndex = 1;
var occurrence = (byday - (byday % 8)) / 8; document.getElementById("monthly-days").days = [startDate.day];
var weekday = byday % 8; var day = Math.floor((startDate.day - 1) / 7) + 1;
setElementValue("monthly-ordinal", occurrence); setElementValue("monthly-ordinal", day);
setElementValue("monthly-weekday", Math.abs(weekday)); setElementValue("monthly-weekday", startDate.weekday + 1);
} else { }
var ruleComp = rule.getComponent("BYMONTHDAY", {}); else {
if (ruleComp.length > 0) { if (byDayRuleComponent.length > 0) {
if (ruleComp.length == 1 && ruleComp[0] == -1) { document.getElementById("monthly-group").selectedIndex = 0;
document.getElementById("monthly-group").selectedIndex = 0; var weekday = getWeekdayOfRule(byDayRuleComponent[0]);
setElementValue("monthly-ordinal", ruleComp[0]); setElementValue("monthly-ordinal", occurrence);
setElementValue("monthly-weekday", ruleComp[0]); setElementValue("monthly-weekday", Math.abs(weekday));
} else {
document.getElementById("monthly-group").selectedIndex = 1;
document.getElementById("monthly-days").days = ruleComp;
}
}
}
break;
case "YEARLY":
document.getElementById("period-list").selectedIndex = 3;
setElementValue("yearly-interval", rule.interval);
var byMonthRule = rule.getComponent("BYMONTH", {});
var byDayRule = rule.getComponent("BYDAY", {});
var byMonthDayRule = rule.getComponent("BYMONTHDAY", {});
if (byMonthRule.length > 0) {
if (byMonthDayRule.length > 0) {
document.getElementById("yearly-group").selectedIndex = 0;
setElementValue("yearly-month-ordinal", byMonthRule[0]);
setElementValue("yearly-days", byMonthDayRule[0]);
} else if (byDayRule.length > 0) {
document.getElementById("yearly-group").selectedIndex = 1;
var byday = byDayRule[0];
var occurrence = (byday - (byday % 8)) / 8;
var weekday = byday % 8;
setElementValue("yearly-ordinal", occurrence);
setElementValue("yearly-weekday", weekday);
setElementValue("yearly-month-rule", byMonthRule[0]);
}
}
break;
default:
dump("unable to handle your rule type!\n");
break;
} }
else {
if (byMonthDayRuleComponent.length > 0) {
if (byMonthDayRuleComponent.length == 1 && byDayRuleComponent[0] == -1) {
document.getElementById("monthly-group").selectedIndex = 0;
setElementValue("monthly-ordinal", byMonthDayRuleComponent[0]);
setElementValue("monthly-weekday", byMonthDayRuleComponent[0]);
} else {
document.getElementById("monthly-group").selectedIndex = 1;
document.getElementById("monthly-days").days = byMonthDayRuleComponent;
}
}
}
}
/* load up the duration of the event radiogroup */ // "YEARLY" ruletype
if (rule.isByCount) { if ((byMonthRuleComponent.length == 0) || (rule.type != "YEARLY")) {
if (rule.count == -1) { setElementValue("yearly-days", startDate.day);
setElementValue("recurrence-duration", "forever"); setElementValue("yearly-month-ordinal", startDate.month + 1);
} else { var day = Math.floor((startDate.day - 1) / 7) + 1;
setElementValue("recurrence-duration", "ntimes"); setElementValue("yearly-ordinal", day);
setElementValue("repeat-ntimes-count", rule.count ); setElementValue("yearly-weekday", startDate.weekday + 1);
} setElementValue("yearly-month-rule", startDate.month + 1);
}
else {
if (byMonthDayRuleComponent.length > 0) {
document.getElementById("yearly-group").selectedIndex = 0;
setElementValue("yearly-month-ordinal", byMonthRuleComponent[0]);
setElementValue("yearly-days", byMonthDayRuleComponent[0]);
} else if (byDayRuleComponent.length > 0) {
document.getElementById("yearly-group").selectedIndex = 1;
var weekday = getWeekdayOfRule(byDayRuleComponent[0]);
setElementValue("yearly-ordinal", occurrence);
setElementValue("yearly-weekday", weekday);
setElementValue("yearly-month-rule", byMonthRuleComponent[0]);
}
}
/* load up the duration of the event radiogroup */
if (rule.isByCount) {
if (rule.count == -1) {
setElementValue("recurrence-duration", "forever");
} else { } else {
var endDate = rule.endDate; setElementValue("recurrence-duration", "ntimes");
if (!endDate) { setElementValue("repeat-ntimes-count", rule.count );
setElementValue("recurrence-duration", "forever"); }
} else { } else {
// Convert the datetime from UTC to localtime. var endDate = rule.endDate;
endDate = endDate.getInTimezone(calendarDefaultTimezone()); if (!endDate) {
setElementValue("recurrence-duration", "until"); setElementValue("recurrence-duration", "forever");
setElementValue("repeat-until-date", endDate.jsDate); } else {
} // Convert the datetime from UTC to localtime.
endDate = endDate.getInTimezone(calendarDefaultTimezone());
setElementValue("recurrence-duration", "until");
setElementValue("repeat-until-date", endDate.jsDate);
} }
} }
} }
@ -174,6 +205,13 @@ function onLoad() {
self.focus(); self.focus();
} }
function getWeekdayOfRule(aByDayRuleComponent) {
var occurrence = (aByDayRuleComponent - (aByDayRuleComponent % 8)) / 8;
return aByDayRuleComponent % 8;
}
function onSave(item) { function onSave(item) {
// Always return 'null' if this item is an occurrence. // Always return 'null' if this item is an occurrence.
if (!item || item.parentItem != item) { if (!item || item.parentItem != item) {