StringBuffer next = new StringBuffer();
next.append("c_goTo('/calendar.do?Type=DAILY&selectedDay=" + nextDailyDay);
next.append("&selectedMonthName=" + nextDailyMonth + "&selectedYear=" + nextDailyYear + "');");
calendarNavBarList.add(new DDNameValue("Previous", previous.toString()));
calendarNavBarList.add(new DDNameValue("Today", current.toString()));
calendarNavBarList.add(new DDNameValue("Next", next.toString()));
} else if (calendarType != null && (calendarType.equals("WEEKLY") || calendarType.equals("WEEKLYCOLUMNS"))) {
int previousWeekDate = 0;
String previousWeekMonth = "";
int previousWeekYear = 0;
if (currentDay != 0 && currentMonth >= 0 && currentYear != 0) {
Calendar previousCalendarWeek = Calendar.getInstance();
previousCalendarWeek.set(currentYear, currentMonth, currentDay);
previousCalendarWeek.add(Calendar.DATE, -7);
previousWeekDate = previousCalendarWeek.get(Calendar.DATE);
int intYearOfMonth = previousCalendarWeek.get(Calendar.MONTH);
previousWeekMonth = getCalenderMonthName(intYearOfMonth);
previousWeekYear = previousCalendarWeek.get(Calendar.YEAR);
}
int nextWeekDay = 0;
String nextWeekMonth = "";
int nextWeekYear = 0;
if (currentDay != 0 && currentMonth >= 0 && currentYear != 0) {
Calendar nextCalendarWeek = Calendar.getInstance();
nextCalendarWeek.set(currentYear, currentMonth, currentDay);
nextCalendarWeek.add(Calendar.DATE, +7);
nextWeekDay = nextCalendarWeek.get(Calendar.DATE);
int intYearOfMonth = nextCalendarWeek.get(Calendar.MONTH);
nextWeekYear = nextCalendarWeek.get(Calendar.YEAR);
nextWeekMonth = getCalenderMonthName(intYearOfMonth);
}
StringBuffer previous = new StringBuffer();
previous.append("c_goTo('/calendar.do?Type=" + calendarType + "&selectedDay=" + previousWeekDate);
previous.append("&selectedMonthName=" + previousWeekMonth + "&selectedYear=" + previousWeekYear + "');");
StringBuffer current = new StringBuffer();
current.append("c_goTo('/calendar.do?Type=" + calendarType + "&selectedDay=" + thisDayOfMonth);
current.append("&selectedMonthName=" + thisMonth + "&selectedYear=" + thisYear + "');");
StringBuffer next = new StringBuffer();
next.append("c_goTo('/calendar.do?Type=" + calendarType + "&selectedDay=" + nextWeekDay);
next.append("&selectedMonthName=" + nextWeekMonth + "&selectedYear=" + nextWeekYear + "');");
calendarNavBarList.add(new DDNameValue("Previous", previous.toString()));
calendarNavBarList.add(new DDNameValue("Current Week", current.toString()));
calendarNavBarList.add(new DDNameValue("Next", next.toString()));
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd");
String dailyGo = "c_goTo('/calendar.do?Type=DAILY";
if (currentDay != 0 && currentMonth >= 0 && currentYear != 0) {
Calendar headerCalendarWeek = Calendar.getInstance();
headerCalendarWeek.set(currentYear, currentMonth, currentDay);
int dayOfWeek = headerCalendarWeek.get(Calendar.DAY_OF_WEEK);
// Subtracting it with 2 coz in the Calendar Starting Day is Monday.
int offset = dayOfWeek - 2;
if (offset < 0) {
int daysInWeek = 7;
// if we are before the current day of the week, we need to fall all
// the way back to the previous beginning of the week. calculating our
// offset in this way will give us the right num of days to the
// previous start. this makes it easy to just add it to the
// currentDate.
offset = daysInWeek + offset;
}
int currentDate = headerCalendarWeek.get(Calendar.DATE);
headerCalendarWeek.set(Calendar.DATE, currentDate - offset);
int headerDayOfMonth = headerCalendarWeek.get(Calendar.DATE);
int headerMonthOfYear = headerCalendarWeek.get(Calendar.MONTH);
int headerYear = headerCalendarWeek.get(Calendar.YEAR);
try {
// This is used in the columnar weekly view for calculating the
// date to be filled in when you click on a empty cell.
calendarNavBarMap.put("startDayOfWeek", new Integer(headerDayOfMonth));
} catch (NumberFormatException nfe) {
logger.info("[setCalendarNavBar]: The offset for the clickable weekly view boxes will probably be broken.");
calendarNavBarMap.put("startDayOfWeek", new Integer(0));
}
String dateString = headerYear + ",'" + getCalenderMonthName(headerMonthOfYear) + "'," + headerDayOfMonth;
String headerDate = formatter.format(headerCalendarWeek.getTime());
String dailyDate = "&selectedDay=" + headerDayOfMonth + "&selectedMonthName=" + getCalenderMonthName(headerMonthOfYear) + "&selectedYear="
+ headerYear;
String action = "ScheduleActivity(" + dateString + ",'','');";
dateList.put(String.valueOf(0), action);
headerLinkList.put(String.valueOf(0), dailyGo + dailyDate + "');");
headerList.put(String.valueOf(0), headerDate);
int count = 1;
for (int i = 0; i < 6; i++) {
headerCalendarWeek.add(Calendar.DATE, 1);
headerDayOfMonth = headerCalendarWeek.get(Calendar.DAY_OF_MONTH);
headerMonthOfYear = headerCalendarWeek.get(Calendar.MONTH);
headerYear = headerCalendarWeek.get(Calendar.YEAR);
dateString = headerYear + ",'" + getCalenderMonthName(headerMonthOfYear) + "'," + headerDayOfMonth;
action = "ScheduleActivity(" + dateString + ",'','');";
dateList.put(String.valueOf(count), action);
headerDate = formatter.format(headerCalendarWeek.getTime());
headerList.put(String.valueOf(count), headerDate);
dailyDate = "&selectedDay=" + headerDayOfMonth + "&selectedMonthName=" + getCalenderMonthName(headerMonthOfYear) + "&selectedYear="
+ headerYear;
headerLinkList.put(String.valueOf(count), dailyGo + dailyDate + "');");
count++;
}
}
} else if (calendarType != null && calendarType.equals("MONTHLY")) {
int previousMonthlyDay = 0;
String previousMonthlyMonth = "";
int previousMonthlyYear = 0;
if (currentDay != 0 && currentMonth >= 0 && currentYear != 0) {
Calendar previousCalendarWeek = Calendar.getInstance();
previousCalendarWeek.set(currentYear, currentMonth, currentDay);
previousCalendarWeek.add(Calendar.MONTH, -1);
previousMonthlyDay = previousCalendarWeek.get(Calendar.DATE);
int intYearOfMonth = previousCalendarWeek.get(Calendar.MONTH);
previousMonthlyMonth = getCalenderMonthName(intYearOfMonth);
previousMonthlyYear = previousCalendarWeek.get(Calendar.YEAR);
}
int nextMonthlyDay = 0;
String nextMonthlyMonth = "";
int nextMonthlyYear = 0;
if (currentDay != 0 && currentMonth >= 0 && currentYear != 0) {
Calendar nextCalendarWeek = Calendar.getInstance();
nextCalendarWeek.set(currentYear, currentMonth, currentDay);
nextCalendarWeek.add(Calendar.MONTH, 1);
nextMonthlyDay = nextCalendarWeek.get(Calendar.DATE);
int intYearOfMonth = nextCalendarWeek.get(Calendar.MONTH);
nextMonthlyYear = nextCalendarWeek.get(Calendar.YEAR);
nextMonthlyMonth = getCalenderMonthName(intYearOfMonth);
}
StringBuffer previous = new StringBuffer();
previous.append("c_goTo('/calendar.do?Type=MONTHLY&selectedDay=" + previousMonthlyDay);
previous.append("&selectedMonthName=" + previousMonthlyMonth + "&selectedYear=" + previousMonthlyYear + "');");
StringBuffer current = new StringBuffer();
current.append("c_goTo('/calendar.do?Type=MONTHLY&selectedDay=" + thisDayOfMonth);
current.append("&selectedMonthName=" + thisMonth + "&selectedYear=" + thisYear + "');");
StringBuffer next = new StringBuffer();
next.append("c_goTo('/calendar.do?Type=MONTHLY&selectedDay=" + nextMonthlyDay);
next.append("&selectedMonthName=" + nextMonthlyMonth + "&selectedYear=" + nextMonthlyYear + "');");
calendarNavBarList.add(new DDNameValue("Previous", previous.toString()));
calendarNavBarList.add(new DDNameValue("Current Month", current.toString()));
calendarNavBarList.add(new DDNameValue("Next", next.toString()));
} else if (calendarType != null && calendarType.equals("YEARLY")) {
int previousYearlyYear = 0;
previousYearlyYear = currentYear - 1;
int nextYearlyYear = 0;
nextYearlyYear = currentYear + 1;
StringBuffer previous = new StringBuffer();
previous.append("c_goTo('/calendar.do?Type=YEARLY&selectedYear=" + previousYearlyYear + "');");
StringBuffer current = new StringBuffer();
current.append("c_goTo('/calendar.do?Type=YEARLY&selectedYear=" + thisYear + "');");
StringBuffer next = new StringBuffer();
next.append("c_goTo('/calendar.do?Type=YEARLY&selectedYear=" + nextYearlyYear + "');");
calendarNavBarList.add(new DDNameValue("Previous", previous.toString()));
calendarNavBarList.add(new DDNameValue("Current Year", current.toString()));
calendarNavBarList.add(new DDNameValue("Next", next.toString()));
}
calendarNavBarMap.put("calendarNavBar", calendarNavBarList);
calendarNavBarMap.put("headerList", headerList);
calendarNavBarMap.put("headerLinkList", headerLinkList);
calendarNavBarMap.put("dateList", dateList);