<% layout('/layouts/default.html', {title: '日程管理', bodyClass: ''}){ %>


<div id="pageayout" class="border" style="overflow: auto; padding: 0px;">
	<div id='calendar' class="calendar" style="margin: 10px;background: #fff; "></div>
</div>
<% } %>

<script src="${ctxStatic}/schedule/fullcalendar/js/jquery-1.7.2.min.js"></script>
<script src="${ctxStatic}/schedule/jquery-ui/jquery-ui.min.js"></script>
<script src="${ctxStatic}/schedule/fullcalendar/js/fullcalendar.min.js"></script>
<link href="${ctxStatic}/schedule/fullcalendar/css/fullcalendar.css" rel="stylesheet" />
<script type='text/javascript'>
	$(document).ready(function () {
		$('.calendar').fullCalendar({
			header: {
				left: 'prev,next',
				center: 'title',
				right: 'agendaDay,agendaWeek,month'
			},
			monthNamesShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
			dayNamesShort: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
			buttonText: {
				prev: '上一页',
				next: '下一页',
				month: '月视图',
				week: '周视图',
				day: '日视图'
			},
			titleFormat: "yyyy年MM月",
			columnFormat: {
				month: 'ddd',
				week: 'MM月dd日 ddd',
				day: 'MM月dd日 ddd'
			},
			allDayText: '今天',
			axisFormat: "HH:00",
			height: $(window).height() - 55,
			dayClick: function (date, allDay, jsEvent, view) {
				var _date = $.fullCalendar.formatDate(date, 'yyyy-MM-dd');
				var _time = $.fullCalendar.formatDate(date, 'HHmm');
				var myDate=new Date()
				if(js.formatDate(date, 'yyyyMMdd')>=js.formatDate(myDate,'yyyyMMdd')){
					btn_add();
				}
			},
			editable: true,
			eventLimit: true,
			eventAfterRender: function (event, element, view) {//数据绑定上去后添加相应信息在页面上
				var fstart = $.fullCalendar.formatDate(event.start, "HH:mm");
				var fend = $.fullCalendar.formatDate(event.end, "HH:mm");

				if (view.name == "month") {//按月份
					var evtcontent = '<div class="fc-event-inner fc-event-skin">';
					evtcontent += '<span class="fc-event-time">' + fstart + " - " + fend + '</span>';
					evtcontent += '<span class="fc-event-title">: ' + event.title + '</span>&nbsp;&nbsp;&nbsp;&nbsp;<span onclick="btn_edit(\'' + event.id + '\')">修改</span>';
					evtcontent += '&nbsp;&nbsp;&nbsp;&nbsp;<span onclick="btn_del(\'' + event.id + '\')">删除</span>';
					evtcontent += '</div><div class="ui-resizable-handle ui-resizable-e">&nbsp;&nbsp;&nbsp;</div>';

					element.html(evtcontent);
				} else {
					var evtcontent = '<div class="fc-event-inner fc-event-skin">';
					evtcontent += '<div class="fc-event-head fc-event-skin">';
					evtcontent += '<div class="fc-event-time">' + fstart + " - " + fend + event.title + '</div>';
					evtcontent += '</div>';
					evtcontent += '<div class="fc-event-content"></div>';
					evtcontent += '<div class="fc-event-bg"></div>';
					evtcontent += '</div>';
					element.html(evtcontent);
				}
			},
			events: (function () {
				var _data = [];
				js.ajaxSubmit({
					url: '${ctx}/sys/schedule/schedule/getlist',
					data: {},
					callback: function(data){
						var date=data.scheduleList;
						var rows=date;
						for (let i = 0; i < date.length ; i++) {
							rows[i]["title"] = date[i].fschedulename;
							rows[i]["end"] = date[i].fenddate;
							rows[i]["start"] =date[i].fstartdate;
							rows[i]["allDay"]=false;
						}
						_data=rows;
					},
					dataType: 'json',
					async: false,
					message: '正在获取数据...'
				});
				return _data;
			})()

		});
	});

	//添加日程
	function btn_add() {
		js.addTabPage(null, "新增日程", "${ctx}/sys/schedule/schedule/form")
	};

	//添加日程
	function btn_edit(id) {
		js.addTabPage(null, "修改日程", "${ctx}/sys/schedule/schedule/form?id="+id)
	};

	function btn_del(id) {
		$.ajax({
			url: "${ctx}/sys/schedule/schedule/delete",
			data: { id: id},
			dataType: "json",
			async: false,
			success: function (data) {
				if (data.result == "true") {
					js.alert('删除成功');
					js.getCurrentTabPage(function(contentWindow){
						contentWindow.location.reload(true);
					});
				}
			}
		});
	}

</script>

