fullcalendar 日曆外掛3.9.0遇到的坑
阿新 • • 發佈:2018-12-31
var calendar;
(function ($) {
var language = getCookie("userLanguage");
calendar = $('#calendar').fullCalendar({
firstDay: 0,//設定一週中顯示的第一天是哪天,週日是0,週一是1
buttonText: {//設定日曆頭部各按鈕的顯示文字資訊
today: '今天/本週',
month: '月',
week: '周',
day: '日'
},
allDayText:'全天',
locale : language,//多語言
height: 600,
header: {//設定日曆頭部資訊。
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: false,//不能進行編輯
droppable: false,
drop: function (date, allDay) { // this function is called when something is dropped
var originalEventObject = $(this).data('eventObject');
var $extraEventClass = $(this).attr('data-class');
var copiedEventObject = $.extend({}, originalEventObject);
copiedEventObject.start = date;
copiedEventObject.allDay = allDay;
if ($extraEventClass) copiedEventObject['className'] = [$extraEventClass];
$('#calendar').fullCalendar('renderEvent', copiedEventObject, true);
if ($('#drop-remove').is(':checked')) {
$(this).remove();
}
},
selectable: true,//是否允許使用者通過單擊或拖動選擇日曆中的物件,包括天和時間
selectHelper: true,//當點選或拖動選擇時間時,顯示預設載入的提示資訊,該屬性只在周/天視圖裡可用。
select: function(start, end, allDay) {//選中某個時間
var view = calendar.fullCalendar('getView');
if (view.type != 'month'){
return;
}
calendar.fullCalendar('gotoDate', $.fullCalendar.moment(start._d));
calendar.fullCalendar('changeView', 'agendaDay');
},
viewRender : function(view, element){//**當新的日期區間渲染後或者檢視切換後觸發**
$("#details").hide();
var type = $('#calendar').fullCalendar('getView').type;
if (type == "agendaWeek" || type == "basicWeek"){
type = 'week';
}else if (type == "agendaDay" || type == "basicDay"){
type = 'day';
}else{
type = 'month';
}
var data = new Array();
var changePlan = new Array();var routine;var othertasks;var release;
$("#calendar").fullCalendar('removeEvents');
if(arrayFindString(select,"change")!=null || arrayFindString(select,"all")!=null){
if(select.length>1 ||arrayFindString(select,"all")!=null){
changePlan = jQueryAjax("/changeCalendarAction/changePlan", {
"viewType" : type,
"viewDate" : formatDate($('#calendar').fullCalendar('getDate')._d,'yyyy/MM/dd'),
"mult":1,
},null, 'get');
}else {
changePlan = jQueryAjax("/changeCalendarAction/changePlan", {
"viewType" : type,
"viewDate" : formatDate($('#calendar').fullCalendar('getDate')._d,'yyyy/MM/dd'),
"mult":0,
},null, 'get');
}
data = data.concat(changePlan);
}
if(arrayFindString(select,"routine")!=null || arrayFindString(select,"all")!=null){
if(select.length>1 ||arrayFindString(select,"all")!=null) {
routine = jQueryAjax("/planTaskCalendarAction/changePlan", {
"viewType": type,
"viewDate": formatDate($('#calendar').fullCalendar('getDate')._d, 'yyyy/MM/dd'),
"other": 0,
"mult":1,
}, null, 'get');
}else {
routine = jQueryAjax("/planTaskCalendarAction/changePlan", {
"viewType": type,
"viewDate": formatDate($('#calendar').fullCalendar('getDate')._d, 'yyyy/MM/dd'),
"other": 0,
"mult":0,
}, null, 'get');
}
data = data.concat(routine);
}
if(arrayFindString(select,"othertasks")!=null || arrayFindString(select,"all")!=null){
if(select.length>1||arrayFindString(select,"all")!=null) {
othertasks = jQueryAjax("/planTaskCalendarAction/changePlan", {
"viewType" : type,
"viewDate" : formatDate($('#calendar').fullCalendar('getDate')._d,'yyyy/MM/dd'),
"other":1,
"mult":1,
},null, 'get');}
else {
othertasks = jQueryAjax("/planTaskCalendarAction/changePlan", {
"viewType" : type,
"viewDate" : formatDate($('#calendar').fullCalendar('getDate')._d,'yyyy/MM/dd'),
"other":1,
"mult":0,
},null, 'get');
}
data = data.concat(othertasks);
}
if(arrayFindString(select,"report")!=null || arrayFindString(select,"all")!=null){
if(select.length>1||arrayFindString(select,"all")!=null) {
release = jQueryAjax("/releaseCalendarAction/changePlan", {
"viewType" : type,
"viewDate" : formatDate($('#calendar').fullCalendar('getDate')._d,'yyyy/MM/dd'),
"mult":1,
},null, 'get');}else {
release = jQueryAjax("/releaseCalendarAction/changePlan", {
"viewType" : type,
"viewDate" : formatDate($('#calendar').fullCalendar('getDate')._d,'yyyy/MM/dd'),
"mult":0,
},null, 'get');
}
data = data.concat(release);
}
for (var i = 0; i < data.length; i++){
var start = new Date(data[i][3]);
var end = new Date(data[i][4]);
$("#calendar").fullCalendar('renderEvent',{
"id" : data[i][0],
"title" : data[i][1],
"start" : start,
"startTime" : start,
"end" : end,
"endTime" : end,
"type" : data[i][9],
"content" : data[i][2],
"className" : data[i][5],
"ourl" : data[i][13]
},true);
}
},
eventClick: function(calEvent, jsEvent, view) {//當點選日曆中的某一日程(事件)時,觸發此操作
$("#details").hide();
var url = getRootPath() + calEvent.ourl;
window.parent.Addtabs.add({
id: calEvent.id,
title: calEvent.title,
content: "",
url: url + calEvent.id
});
},
eventMouseover : function(event, jsEvent, view){//滑鼠劃過的事件
},
eventMouseout : function(event, jsEvent, view){//滑鼠離開的事件
}
});
})