- URL 하드코딩 → .env APP_URL 기반 동적 URL로 변경 - DB 연결 하드코딩 → .env 기반으로 변경 - MySQL strict mode DATE 오류 수정
345 lines
14 KiB
JavaScript
345 lines
14 KiB
JavaScript
$(document).ready(function() {
|
|
let todo_currentMonth = new Date().getMonth();
|
|
let todo_currentYear = new Date().getFullYear();
|
|
|
|
function todo_fetchCalendarData(month, year) {
|
|
$.ajax({
|
|
url: "/todo1/fetch_todo.php",
|
|
type: "post",
|
|
data: { month: month + 1, year: year },
|
|
dataType: "json",
|
|
success: function(response) {
|
|
let selectedFilter = $('input[name="filter"]:checked').attr('id');
|
|
let calendarHtml = todo_generateCalendarHtml(response.todo_data, response.leave_data, selectedFilter, response.holiday_data);
|
|
$('#todo-calendar-container').html(calendarHtml);
|
|
$('#todo-current-period').text(todo_currentYear + '/' + ('0' + (todo_currentMonth + 1)).slice(-2));
|
|
var showTodoView = getCookie("showTodoView");
|
|
var todoCalendarContainer = $("#todo-list");
|
|
if (showTodoView === "show") {
|
|
todoCalendarContainer.css("display", "block");
|
|
} else {
|
|
todoCalendarContainer.css("display", "none");
|
|
}
|
|
},
|
|
error: function() {
|
|
console.log('Failed to fetch data');
|
|
}
|
|
});
|
|
}
|
|
|
|
function todo_generateCalendarHtml(todoData, leaveData, filter, holidayData) {
|
|
const daysOfWeek = ['일', '월', '화', '수', '목', '금', '토'];
|
|
let date = new Date(todo_currentYear, todo_currentMonth, 1);
|
|
let firstDay = date.getDay();
|
|
let lastDate = new Date(todo_currentYear, todo_currentMonth + 1, 0).getDate();
|
|
let today = new Date();
|
|
|
|
let todayYear = today.getFullYear();
|
|
let todayMonth = today.getMonth();
|
|
let todayDate = today.getDate();
|
|
|
|
let calendarHtml = '<table id="todo-list" class="table" style="width: 100%; table-layout: fixed;">';
|
|
calendarHtml += '<thead class="table-info text-start"><tr>';
|
|
daysOfWeek.forEach(day => {
|
|
calendarHtml += '<th class="fs-6 text-start" style="width: calc(100% / ' + daysOfWeek.length + ');">' + day + '</th>';
|
|
});
|
|
calendarHtml += '</tr></thead><tbody>';
|
|
|
|
let day = 1;
|
|
for (let i = 0; i < 6; i++) {
|
|
calendarHtml += '<tr>';
|
|
for (let j = 0; j < 7; j++) {
|
|
if (i === 0 && j < firstDay) {
|
|
calendarHtml += '<td class="text-start"></td>';
|
|
} else if (day > lastDate) {
|
|
calendarHtml += '<td class="text-start"></td>';
|
|
} else {
|
|
let currentDate = new Date(todo_currentYear, todo_currentMonth, day);
|
|
let dayData = todoData.filter(item => new Date(item.orderdate).getDate() === day);
|
|
|
|
let leaveDataForDay = leaveData.filter(item => {
|
|
let leaveStart = convertToKST(item.al_askdatefrom);
|
|
let leaveEnd = convertToKST(item.al_askdateto);
|
|
return currentDate >= leaveStart && currentDate <= leaveEnd;
|
|
});
|
|
|
|
let dayClass = (j === 0 || j === 6) ? 'red-day' : '';
|
|
if (currentDate.getFullYear() === todayYear && currentDate.getMonth() === todayMonth && currentDate.getDate() === todayDate) {
|
|
dayClass += ' today-bg';
|
|
}
|
|
// 휴일처리를 위한 구문 추가 20240830
|
|
// 한국 시간대를 고려한 날짜 변환 함수
|
|
function convertToKST(dateString) {
|
|
const utcDate = new Date(dateString + 'T00:00:00Z'); // UTC로 변환
|
|
const kstDate = new Date(utcDate.getTime() + 9 * 60 * 60 * 1000); // 9시간 추가 (KST)
|
|
kstDate.setHours(0, 0, 0, 0); // 시간을 0으로 설정
|
|
return kstDate;
|
|
}
|
|
|
|
// holidayData에 해당 날짜가 있는지 확인
|
|
let holidayForDay = holidayData.filter(item => {
|
|
let startDate = convertToKST(item.startdate);
|
|
let endDate = item.enddate && item.enddate !== '0000-00-00' ? convertToKST(item.enddate) : startDate;
|
|
return currentDate >= startDate && currentDate <= endDate;
|
|
});
|
|
|
|
// 만약 해당 날짜가 holiday에 포함되면 red-day 추가
|
|
if (holidayForDay.length > 0) {
|
|
dayClass += ' text-danger';
|
|
}
|
|
// 휴일처리를 위한 구문 끝.
|
|
|
|
calendarHtml += `<td class="text-start ${dayClass}"><div class="fw-bold fs-6">${day} <button type="button" class="event btn btn-outline-dark btn-sm" style="border:0px;" data-date="${todo_currentYear}-${('0' + (todo_currentMonth + 1)).slice(-2)}-${('0' + day).slice(-2)}" > <i class="bi bi-plus"></i> </button> </div>`;
|
|
|
|
// 휴일 holiday 표시
|
|
holidayForDay.forEach(item => {
|
|
calendarHtml += `<div><span class='badge bg-danger'>${item.comment}</span></div>`;
|
|
});
|
|
|
|
if ((filter === 'filter_all' || filter === 'filter_al') && holidayForDay.length === 0) {
|
|
// 연차데이터 표시 (휴일이 아닌 경우에만)
|
|
leaveDataForDay.forEach(item => {
|
|
calendarHtml += `<div class="leave-info justify-content-start text-start" style="border: 1px dashed brown;"><span class="text-secondary">${item.author} (<i class="bi bi-tree-fill"></i>${item.al_item})</span></div>`;
|
|
});
|
|
}
|
|
|
|
dayData.forEach(item => {
|
|
if (filter === 'filter_all' ||
|
|
(filter === 'filter_hyeonseol' && item.itemsep === '현설') ||
|
|
(filter === 'filter_ipchal' && item.itemsep === '입찰') ||
|
|
(filter === 'filter_etc' && (!item.itemsep || item.itemsep === ''))) {
|
|
|
|
if (!item.towhom) item.towhom = '전체공지';
|
|
else item.towhom = item.towhom;
|
|
|
|
calendarHtml += '<div class="todo-event event" data-id="' + item.num + '">';
|
|
if (item.itemsep !== '현설' && item.itemsep !== '입찰') {
|
|
calendarHtml += '<span class="badge bg-primary">' + item.towhom + '</span> ';
|
|
} else if (item.itemsep === '현설') {
|
|
calendarHtml += '<span class="badge bg-success">' + item.itemsep + '</span> ';
|
|
} else if (item.itemsep === '입찰') {
|
|
calendarHtml += '<span class="badge bg-warning">' + item.itemsep + '</span> ';
|
|
}
|
|
calendarHtml += item.title + '</div>';
|
|
}
|
|
});
|
|
|
|
calendarHtml += '</td>';
|
|
day++;
|
|
}
|
|
}
|
|
calendarHtml += '</tr>';
|
|
}
|
|
|
|
calendarHtml += '</tbody></table>';
|
|
return calendarHtml;
|
|
}
|
|
|
|
|
|
$('#todo-calendar-container').on('click', '.event', function() {
|
|
let num = $(this).data('id');
|
|
let date = $(this).data('date');
|
|
loadForm(num, date);
|
|
});
|
|
|
|
function loadForm(num, date) {
|
|
let mode = num == 'undefined' || num == null ? 'insert' : 'update';
|
|
// console.log(date);
|
|
$("#mode").val(mode);
|
|
$("#num").val(num);
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "/todo1/fetch_modal.php",
|
|
data: { mode: mode, num: num, seldate : date },
|
|
dataType: "html",
|
|
success: function(response) {
|
|
document.querySelector(".modal-body .custom-card").innerHTML = response;
|
|
$("#todoModal").show();
|
|
|
|
// Bootstrap's data-dismiss="modal" handles modal closing automatically
|
|
// Removed custom click handlers to prevent conflicts
|
|
$(".todo-close, .modal-close-btn").off('click').on('click', function() {
|
|
$("#todoModal").hide(); // 제이쿼리 모달 닫기 함수
|
|
});
|
|
|
|
// Log 파일보기
|
|
$("#showlogBtn").click( function() {
|
|
var num = $("#num").val();
|
|
// table 이름을 넣어야 함
|
|
var workitem = 'todos1' ;
|
|
// 버튼 비활성화
|
|
var btn = $(this);
|
|
popupCenter("/Showlog.php?num=" + num + "&workitem=" + workitem , '로그기록 보기', 500, 500);
|
|
btn.prop('disabled', false);
|
|
});
|
|
|
|
// 요청처리일을 입력하면 진행상태를 '완료'로 변경하고, 날짜를 지우면 '작성'으로 변경
|
|
$('#deadline').change(function() {
|
|
if ($(this).val()) {
|
|
$('#work_status').val('완료');
|
|
} else {
|
|
$('#work_status').val('작성');
|
|
}
|
|
});
|
|
|
|
// 저장 버튼
|
|
$("#saveBtn").on("click", function() {
|
|
var formData = $("#board_form").serialize();
|
|
|
|
$.ajax({
|
|
url: "/todo1/process.php",
|
|
type: "post",
|
|
data: formData,
|
|
success: function(response) {
|
|
console.log(response);
|
|
Toastify({
|
|
text: "저장완료",
|
|
duration: 3000,
|
|
close: true,
|
|
gravity: "top",
|
|
position: "center",
|
|
backgroundColor: "#4fbe87",
|
|
}).showToast();
|
|
$("#todoModal").hide();
|
|
todo_fetchCalendarData(todo_currentMonth, todo_currentYear); // 변경된 데이터만 다시 로드
|
|
},
|
|
error: function(jqxhr, status, error) {
|
|
console.log(jqxhr, status, error);
|
|
}
|
|
});
|
|
});
|
|
|
|
// 삭제 버튼
|
|
$("#deleteBtn").on("click", function() {
|
|
var user_name = $("#user_name").val();
|
|
var first_writer = $("#first_writer").val();
|
|
var level = $("#level").val();
|
|
|
|
console.log('user_name', user_name);
|
|
console.log('first_writer', first_writer);
|
|
console.log('level', level);
|
|
|
|
if (user_name !== first_writer && Number(level) !== 1) {
|
|
Swal.fire({
|
|
title: '삭제불가',
|
|
text: "작성자, 관리자만 삭제 가능합니다.",
|
|
icon: 'error',
|
|
confirmButtonText: '확인'
|
|
});
|
|
return;
|
|
}
|
|
|
|
Swal.fire({
|
|
title: '자료 삭제',
|
|
text: "삭제는 신중! 정말 삭제하시겠습니까?",
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonColor: '#3085d6',
|
|
cancelButtonColor: '#d33',
|
|
confirmButtonText: '삭제',
|
|
cancelButtonText: '취소'
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
$("#mode").val('delete');
|
|
var formData = $("#board_form").serialize();
|
|
|
|
$.ajax({
|
|
url: "/todo1/process.php",
|
|
type: "post",
|
|
data: formData,
|
|
success: function(response) {
|
|
Toastify({
|
|
text: "파일 삭제완료",
|
|
duration: 2000,
|
|
close: true,
|
|
gravity: "top",
|
|
position: "center",
|
|
style: {
|
|
background: "linear-gradient(to right, #00b09b, #96c93d)"
|
|
},
|
|
}).showToast();
|
|
|
|
$("#todoModal").hide();
|
|
todo_fetchCalendarData(todo_currentMonth, todo_currentYear); // 변경된 데이터만 다시 로드
|
|
},
|
|
error: function(jqxhr, status, error) {
|
|
console.log(jqxhr, status, error);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
// 체크박스 클릭시 처리
|
|
function updateApproversInput() {
|
|
let approvers = [];
|
|
$('.approver-checkbox:checked').each(function() {
|
|
approvers.push($(this).data('user-name'));
|
|
});
|
|
$('#towhom').val(approvers.join(', '));
|
|
}
|
|
|
|
$('.approver-checkbox').change(function() {
|
|
updateApproversInput();
|
|
});
|
|
|
|
// 기존에 선택된 사용자를 반영합니다.
|
|
let selectedApprovers = $('#towhom').val().split(', ');
|
|
$('.approver-checkbox').each(function() {
|
|
if (selectedApprovers.includes($(this).data('user-name'))) {
|
|
$(this).prop('checked', true);
|
|
}
|
|
});
|
|
|
|
},
|
|
error: function(jqxhr, status, error) {
|
|
console.log("AJAX Error: ", status, error);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
// 초기 라디오 버튼 상태 설정 및 필터 변경 이벤트
|
|
function initializeRadioButtons() {
|
|
let selectedFilter = getCookie("todoFilter") || 'filter_all';
|
|
$('#' + selectedFilter).prop('checked', true);
|
|
todo_fetchCalendarData(todo_currentMonth, todo_currentYear);
|
|
}
|
|
|
|
$('input[name="filter"]').on('change', function() {
|
|
let selectedFilter = $('input[name="filter"]:checked').attr('id');
|
|
setCookie("todoFilter", selectedFilter, 10);
|
|
todo_fetchCalendarData(todo_currentMonth, todo_currentYear);
|
|
});
|
|
|
|
// 이전 월 보기
|
|
$('#todo-prev-month').click(function() {
|
|
todo_currentMonth--;
|
|
if (todo_currentMonth < 0) {
|
|
todo_currentMonth = 11;
|
|
todo_currentYear--;
|
|
}
|
|
todo_fetchCalendarData(todo_currentMonth, todo_currentYear);
|
|
});
|
|
|
|
// 다음 월 보기
|
|
$('#todo-next-month').click(function() {
|
|
todo_currentMonth++;
|
|
if (todo_currentMonth > 11) {
|
|
todo_currentMonth = 0;
|
|
todo_currentYear++;
|
|
}
|
|
todo_fetchCalendarData(todo_currentMonth, todo_currentYear);
|
|
});
|
|
|
|
// 현재 월로 돌아가기
|
|
$('#todo-current-month').click(function() {
|
|
todo_currentMonth = new Date().getMonth();
|
|
todo_currentYear = new Date().getFullYear();
|
|
todo_fetchCalendarData(todo_currentMonth, todo_currentYear);
|
|
});
|
|
|
|
// 페이지 로드 시 초기화
|
|
initializeRadioButtons();
|
|
});
|