var calendarView;
var emptyWeeks;
var emptyWeeksEnd;
var totalWeeks;
function SchCalendar_Export() {
$("#formQuery").submit();
}
function getCalendarView() {
if ($("#SchoolYearDropdown").length > 0 && $.data($("#SchoolYearDropdown")[0], "combobox")) {
var schoolYearID = $("#SchoolYearDropdown").combobox("getValue");
$.post(calenderUrl, { schoolYearID: schoolYearID }, function (data) {
if (data.IsSuccess) {
calendarView = data.Data;
draw();
} else {
$.messager.alert("系统提示", data.Message);
}
})
}
}
//需要在getTotalWeeks方法调用之后才调用,有依赖关系
function getWeeksOfMonth(month) {
//var isParaMonth = false;
var startDate = eval('new ' + eval(calendarView.StartDate).source);
var beginDate = startDate.addDay(-1);
var weekCount = 0;
for (var i = 0; i < totalWeeks; i++) {
var curWeekStart = beginDate.addDay(1 + (i * 7));
var curWeekEnd = beginDate.addDay((i + 1) * 7);
if (curWeekEnd.getMonth() == (month - 1)) { //javascript的月份是从0开始的
//isParaMonth = true;
weekCount++;
}
// else if (isParaMonth && (curWeekStart.getMonth() == (month - 1))) {
// weekCount++;
// break;
// }
}
return weekCount;
}
function getTotalWeeks() {
var startDate = eval('new ' + eval(calendarView.StartDate).source);
var endDate = eval('new ' + eval(calendarView.EndDate).source);
var firstWeek = eval('new ' + eval(calendarView.SchoolYear.FirstWeek).source);
emptyWeeks = Math.ceil(firstWeek.substractDay(startDate) / 7);
emptyWeeksEnd = Math.floor(endDate.substractDay(firstWeek.addDay(calendarView.SchoolYear.WeeksNum * 7)) / 7);
totalWeeks = calendarView.SchoolYear.WeeksNum + emptyWeeks + emptyWeeksEnd;
}
function draw() {
var html = new Array();
getTotalWeeks();
html.push('
');
html.push(getTitleRow());
html.push(getMonthTitleRow());
html.push(getDayRows());
html.push(getWeekTitleRow());
html.push('
');
html.push('
注:表上有★者为法定节假日,停课,不补课;有阴影的为寒暑假时间。
');
html.push('
法定节假日:' + calendarView.HolidayStr + '
');
html.push('
校内安排:' + calendarView.ScalendarStr + '
');
$("#calendarviewcontent").html(html.join("\n"));
drawSplashLine($(".calendarview-monthtitle-left")[0]);
}
function getTitleRow() {
var html = new Array();
html.push(' ');
// html.push(' '
// .concat(calendarView.UniversityName, calendarView.SchoolYear.Years, '学年', calendarView.SchoolYear.SchoolcodeName, '校历 | '));
html.push(' '
.concat(calendarView.UniversityName, calendarView.SchoolYear.Code, '学期校历 | '));
html.push('
');
return html.join("\n");
}
function getConner() {
var html = new Array();
html.push('');
html.push(' ');
html.push(' | ');
html.push(' 月份 | ');
html.push('
');
html.push(' ');
html.push(' 星期 | ');
html.push(' | ');
html.push('
');
html.push('
');
return html.join("\n");
}
function getMonthTitleRow() {
var html = new Array();
var endDate = eval('new ' + eval(calendarView.EndDate).source);
html.push(' ');
html.push(' ' + getConner() + ' | ');
for (var i = 0; i < calendarView.Months.length; i++) {
var monthWeekCount = getWeeksOfMonth(calendarView.Months[i].Month);
if (i == (calendarView.Months.length - 1) && endDate.getMonth() > (calendarView.Months[i].Month - 1)) monthWeekCount++;
html.push(' ');
html.push(' '.concat(calendarView.Months[i].ChineseName, ' | '));
}
html.push('
');
return html.join("\n");
}
function getWeekTitleRow() {
var html = new Array();
html.push(' ');
html.push(' 周次 | ');
for (var i = 0; i < totalWeeks; i++) {
html.push(' ');
if (i >= emptyWeeks && i < (emptyWeeks + calendarView.SchoolYear.WeeksNum)) {
html.push(calendarView.WeekNums[i - emptyWeeks].ChineseName);
} else {
html.push(' ');
}
html.push(' | ');
}
html.push('
');
return html.join("\n");
}
function getDayRows() {
var html = new Array();
var startDate = eval('new ' + eval(calendarView.StartDate).source);
var firstWeek = eval('new ' + eval(calendarView.SchoolYear.FirstWeek).source);
for (var i = 0; i < 7; i++) {
html.push(' ');
html.push(' ' + calendarView.WeekDays[i].ChineseName + ' | ');
var rowStartDate = startDate.addDay(i);
for (var j = 0; j < totalWeeks; j++) {
var curDate = rowStartDate.addDay(j * 7);
html.push(' ');
html.push(curDate.getDate());
if ($.grep(calendarView.Holidays, function (val, index) { return eval('new ' + eval(val).source).valueOf() == curDate.valueOf(); }).length > 0) {
html.push('★');
}
html.push(' | ');
}
html.push('
');
}
return html.join("\n");
}
function getTop(tdobj) {
vParent = tdobj.offsetParent;
t = tdobj.offsetTop;
while (vParent.tagName.toUpperCase() != "BODY") {
t += vParent.offsetTop;
vParent = vParent.offsetParent;
}
return t;
}
function getLeft(tdobj) {
vParent = tdobj.offsetParent;
t = tdobj.offsetLeft;
while (vParent.tagName.toUpperCase() != "BODY") {
t += vParent.offsetLeft;
vParent = vParent.offsetParent;
}
return t;
}
function line(startX, startY, endX, endY, container) {
if (startX == endX) {
if (startY > endY) {
var tempY = startY;
startY = endY;
endY = tempY;
}
for (var k = startY; k < endY; k++) {
createPoint(container, startX, k);
}
}
// y = ax + b
var a = (startY - endY) / (startX - endX);
var b = startY - ((startY - endY) / (startX - endX)) * startX;
if (Math.abs(startX - endX) > Math.abs(startY - endY)) {
if (startX > endX) {
var tempX = endX;
endX = startX;
startX = tempX;
}
var left = $(container).offset().left;
var top = $(container).offset().top;
for (var i = startX; i <= endX; i++) {
createPoint(container, i, a * i + b);
}
} else {
if (startY > endY) {
var tempY = startY;
startY = endY;
endY = tempY;
}
for (var j = startY; j <= endY; j++) {
createPoint(container, (j - b) / a, j);
}
}
}
function createPoint(container, x, y) {
var node = document.createElement('div');
node.className = 'line';
container.appendChild(node);
$(node).offset({
left: x,
top: y
});
}
//line(1,1,100,100,"000000");
function drawSplashLine(container) {
line(getLeft(container), getTop(container), getLeft(container) + container.offsetWidth,
getTop(container) + container.offsetHeight, container);
}