function formatDate(date) {
var d = new Date(date),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2)
month = '0' + month;
if (day.length < 2)
day = '0' + day;
return [year, month, day].join('-');
}
function renderScheduleListCustom(items) {
var side_list_show = 5;
var $list = $('#sc-list').html('');
var n_dates = Object.keys(items).length;
var date_count = 0;
var hide = false;
$.each(items, function(key, ele) {
var dates = key.split('~');
var sdate = dates[0];
var edate = dates[1];
var sdt = sdate.split('-');
var edt = edate.split('-');
var $item = $('
');
if(hide) {
$item.addClass('hidden-item');
}
date_count += 1;
$item.append(''+sdt[0] + '.' + sdt[1] + '
'+sdt[2]+'
');
var addcls = '';
if(edate && sdate != edate) {
$item.append('~
');
$item.append(''+edt[0] + '.' + edt[1] + '
'+edt[2]+'
');
addcls = ' has-duration';
}
var $content = $('');
$.each(ele, function(didx, dlist) {
$.each(dlist, function(idx, item) {
console.log(item);
var label = item.label;
var ca_name = '';
$content.append('' + item.type + ' (' + item.si_startdate + ')
');
$.each(item.class_list, function(cidx, cls) {
$content.append('' + cls.no + '교시 '+ cls.stime + (cls.etime ? '~'+cls.etime : '') + ' ('+ cls.cname+')
');
});
});
});
var show_more = false;
if(date_count == side_list_show && n_dates > side_list_show) {
hide = true;
show_more = true;
}
if(show_more) {
$item.addClass('before-more');
}
$item.append($content);
$list.append($item);
if(show_more) {
$list.append('+ 더보기
');
}
});
if(items.length == 0) {
$list.append('등록된 일정이 없습니다.
');
}
}
function renderScheduleList(items) {
var side_list_show = 5;
var $list = $('#sc-list').html('');
var n_dates = Object.keys(items).length;
var date_count = 0;
var hide = false;
$.each(items, function(key, ele) {
var dates = key.split('~');
var sdate = dates[0];
var edate = dates[1];
var sdt = sdate.split('-');
var edt = edate.split('-');
var $item = $('');
if(hide) {
$item.addClass('hidden-item');
}
date_count += 1;
$item.append(''+sdt[0] + '.' + sdt[1] + '
'+sdt[2]+'
');
var addcls = '';
if(edate && sdate != edate) {
$item.append('~
');
$item.append(''+edt[0] + '.' + edt[1] + '
'+edt[2]+'
');
addcls = ' has-duration';
}
var $content = $('');
if(ele.mode == 'auto') {
$.each(ele, function(idx, item) {
//var label = (item.type1 ? item.type1 : (item.type2 ? item.type2 : item.type3));
//var ca_name = (item.ca_name ? ' ('+item.ca_name+')' : '');
var label = item.label;
var ca_name = '';
$content.append('' + label + ca_name + '
');
});
} else { // custom mode
$.each(ele, function(idx, item) {
var label = item.label;
var ca_name = '';
$content.append('' + label + ca_name + '
');
$.each(item.class_list, function(cidx, cls) {
$content.append('' + cls.no + '교시 '+ cls.stime + (cls.etime ? '~'+cls.etime : '') + ' ('+ cls.cname+')
');
});
});
}
var show_more = false;
if(date_count == side_list_show && n_dates > side_list_show) {
hide = true;
show_more = true;
}
if(show_more) {
$item.addClass('before-more');
}
$item.append($content);
$list.append($item);
if(show_more) {
$list.append('+ 더보기
');
}
});
if(items.length == 0) {
$list.append('등록된 일정이 없습니다.
');
}
}
function updateScheduleList(start) {
$.ajax({
url: 'https://boatcraft.co.kr/skin/board/1st_map/schedule/feed-list.php',
data: { start: formatDate(Date.parse(start)), sname: '경기여주', ename: '여주시설관리공단 (경기여주)', bo_table:'testsite_info', wr_id:'39' },
method: 'get',
dataType: 'json',
aysnc: false,
success: function(json) {
if(json.code !== 1) {
alert(json.message);
return;
}
if(typeof json.mode !== 'undefined' && json.mode == 'custom') {
renderScheduleListCustom(json.list);
} else {
renderScheduleList(json.list);
}
},
error: function(jqXHR, textStatus, errorThrown) {
alert('서버와의 통신 중 에러가 발생했습니다.');
}
});
}
document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
initialView: 'dayGridMonth',
initialDate: '2024-05-19',
locale: 'ko',
height: 'auto',
eventDidMount: function(info) {
var tooltip = new Tooltip(info.el, {
title: info.event.extendedProps.description,
placement: 'top',
trigger: 'hover',
container: 'body'
});
},
headerToolbar: {
left: 'prev,next today',
center: 'title',
right: '',
},
eventSources: 'https://boatcraft.co.kr/skin/board/1st_map/schedule/feed.php?bo_table=testsite_info&wr_id=39&sname=%EA%B2%BD%EA%B8%B0%EC%97%AC%EC%A3%BC&ename=%EC%97%AC%EC%A3%BC%EC%8B%9C%EC%84%A4%EA%B4%80%EB%A6%AC%EA%B3%B5%EB%8B%A8+%28%EA%B2%BD%EA%B8%B0%EC%97%AC%EC%A3%BC%29',
});
calendar.render();
$('#calendar-prev').click(function() {
calendar.prev();
$('#sc-list').html('Loading...');
var d = formatDate(calendar.getDate());
var ds = d.split('-');
$('#calendar-today').html(ds[0] + '년 ' + parseInt(ds[1]) + '월');
updateScheduleList(d);
});
$('#calendar-next').click(function() {
calendar.next();
$('#sc-list').html('Loading...');
var d = formatDate(calendar.getDate());
var ds = d.split('-');
$('#calendar-today').html(ds[0] + '년 ' + parseInt(ds[1]) + '월');
updateScheduleList(d);
});
$('#calendar-today').click(function() {
calendar.today();
$('#sc-list').html('Loading...');
var d = formatDate(calendar.getDate());
var ds = d.split('-');
$('#calendar-today').html(ds[0] + '년 ' + parseInt(ds[1]) + '월');
d = ds[0] + '-' + ds[1] + '-01';
updateScheduleList(d);
});
updateScheduleList('2024-05-01');
});
$(function() {
$('#tsi-admin a').click(function(evt) {
var href = $(this).attr('href');
var new_win = window.open(href, 'win_sc', 'left=100,top=100,width=1000,height=800,scrollbars=0');
new_win.focus();
evt.preventDefault();
});
$(document).on('click', '.more-date', function(evt) {
$('.more-date').remove();
$('#sc-list .before-more').removeClass('before-more');
$('#sc-list .hidden-item').show();
});
});