CalendarWindow = function () {
CalendarWindow.superclass.constructor.call(this);
//this.setUrl(url);
this.initControls();
this.initEvents();
}
mini.extend(CalendarWindow, mini.Window, {
title: "项目日历",
width: 430,
height: 467,
showModal: true,
showFooter: true,
//bodyStyle: "padding:0;",
initControls: function () {
// this.setButtons([
// { name: "ok", text: "确定", width: 60 },
// { name: "cancel", text: "取消", width: 60, style: "margin-left:10px;" }
// ]);
// this.buttons.setStyle("height:40px;padding-top:8px;");
var footerEl = this.getFooterEl();
mini.setStyle(footerEl, "padding:8px;padding-right:10px;text-align:right;");
footerEl.innerHTML = '确定 取消';
//view
var bodyEl = this.getBodyEl();
bodyEl.innerHTML =
'
当前日历:
' +
'' +
'' +
'
' +
'
' +
'
' +
'
' +
'
工作日
' +
'
例外名称
' +
'
开始日期
' +
'
完成日期
' +
'
' +
'
' +
'
' +
'
' +
'
';
mini.parse(this.el);
//获取控件对象
this.ok = mini.getbyName("ok", this);
this.cancel = mini.getbyName("cancel", this);
this.addEx = mini.get("cwin_add");
this.delEx = mini.get("cwin_del");
this.CalendarsCombo = mini.get("cwin_calendars");
this.Exceptions = mini.get("cwin_exceptions");
this.WeekDays = mini.get("cwin_weekdays");
//////////////////////////////////////////////////
this.CalendarsCombo.on("valuechanged", function (e) {
this.selectCalendar(this.CalendarsCombo.value);
}, this);
this.WeekDays.on("drawcell", function (e) {
if (e.field == "DayType") {
e.cellHtml = mini.getLongWeek(e.value - 1);
}
});
this.WeekDays.on("cellcommitedit", function (e) {
if (e.field == "DayWorking") {
//确保工作周必须有一天是工作日
var working = false;
var WeekDays = this.getData();
for (var i = 0, l = WeekDays.length; i < l; i++) {
var weekday = WeekDays[i];
if (weekday == e.record) continue;
if (weekday.DayWorking == 1) {
working = true;
break;
}
}
if (working == false) {
alert("工作周必须有一天是工作日");
e.cancel = true;
}
}
});
this.Exceptions.on("drawcell", function (e) {
if (e.field == "FromDate" || e.field == "ToDate") {
var ex = e.record;
if (ex.TimePeriod) {
e.cellHtml = mini.formatDate(ex.TimePeriod[e.field], "yyyy-MM-dd");
} else {
e.cellHtml = "";
}
}
});
this.Exceptions.on("cellbeginedit", function (e) {
if (e.field == "FromDate" || e.field == "ToDate") {
var ex = e.record;
if (ex.TimePeriod) {
e.value = ex.TimePeriod[e.field];
} else {
e.value = null;
}
}
});
this.Exceptions.on("cellcommitedit", function (e) {
if (e.field == "FromDate" || e.field == "ToDate") {
e.cancel = true;
var ex = e.record;
if (!ex.TimePeriod) {
ex.TimePeriod = {};
}
if (e.field == "FromDate" && e.value) {
if (ex.TimePeriod.ToDate && ex.TimePeriod.ToDate < e.value) {
alert("例外开始日期不能大于例外结束日期");
return;
}
}
if (e.field == "ToDate" && e.value) {
if (ex.TimePeriod.FromDate && ex.TimePeriod.FromDate > e.value) {
alert("例外开始日期不能大于例外结束日期");
return;
}
}
if (String(ex.TimePeriod[e.field]) == String(e.value)) return;
ex.TimePeriod[e.field] = e.value;
this.refresh();
}
});
this.addEx.on("click", function (e) {
var ex = {
DayWorking: 0,
DayType: 0,
Name: ""
};
this.Exceptions.addRow(ex);
}, this);
this.delEx.on("click", function (e) {
this.Exceptions.removeSelected();
}, this);
//////////////////////////
this.ok.on("click", function (e) {
var ret = true;
if (this.callback) ret = this.callback('ok');
if (ret !== false) {
this.hide();
}
}, this);
this.cancel.on("click", function (e) {
var ret = true;
if (this.callback) ret = this.callback('cancel');
if (ret !== false) {
this.hide();
}
}, this);
this.on("closableclick", function (e) {
e.cancel = true;
var ret = true;
if (this.callback) ret = this.callback('close');
if (ret !== false) {
this.hide();
}
}, this);
},
initEvents: function () {
},
getCalendar: function (calendarUID) {
for (var i = 0, l = this.Calendars.length; i < l; i++) {
var c = this.Calendars[i];
if (c.UID == calendarUID) return c;
}
},
markCalenar: function () {
if (!this.selectedCalendar) return;
var calendar = this.selectedCalendar;
calendar.WeekDays = this.WeekDays.getData();
calendar.Exceptions = this.Exceptions.getData();
},
selectCalendar: function (calendarUID) {
var c = this.getCalendar(calendarUID);
if (!c) return;
this.markCalenar();
var calendar = this.selectedCalendar = this.getCalendar(calendarUID);
// for (var i = 0, l = calendar.Exceptions.length; i < l; i++) {
// var ex = calendar.Exceptions[i];
// ex.TimePeriod.FromDate;
// ex.TimePeriod.ToDate;
// }
mini.sort(calendar.WeekDays, function (a, b) {
return a.DayType - b.DayType;
});
// if (mini.locale == 'zh_CN') {
// var o = calendar.WeekDays.removeAt(0);
// calendar.WeekDays.push(o);
// }
//this.
this.Exceptions.setData(calendar.Exceptions);
this.WeekDays.setData(calendar.WeekDays);
},
setData: function (calendars, project, callback) {
this.callback = callback;
var dataProject = project.getData();
var startDate = dataProject.StartDate;
var calendarUID = dataProject.CalendarUID;
this.Calendars = mini.clone(calendars);
this.selectCalendar(calendarUID);
this.CalendarsCombo.setData(calendars);
this.CalendarsCombo.setValue(calendarUID);
//设置日期默认选择是项目开始日期,方便操作
var fromColumn = this.Exceptions.getColumn("from");
var toColumn = this.Exceptions.getColumn("to");
fromColumn.editor.setViewDate(startDate);
toColumn.editor.setViewDate(startDate);
},
getData: function () {
this.markCalenar();
for (var i = 0, l = this.Calendars.length; i < l; i++) {
var c = this.Calendars[i];
var Exceptions = c.Exceptions;
for (var j = Exceptions.length - 1; j >= 0; j--) {
var ex = Exceptions[j];
if (!ex.TimePeriod || !ex.TimePeriod.FromDate || !ex.TimePeriod.ToDate
|| (ex.TimePeriod.FromDate > ex.TimePeriod.ToDate)
) {
Exceptions.removeAt(j);
continue;
}
ex.TimePeriod.FromDate = mini.clearTime(ex.TimePeriod.FromDate);
ex.TimePeriod.ToDate = mini.maxTime(ex.TimePeriod.ToDate);
}
}
return this.Calendars;
}
});