import { vars } from '../archive/variable.js';
import { displayFileName, checkDuplicatesFileNameAndExt , restrictToNumber, calculateTotalJointContract, showToolTip, overviewVarsInit } from './overviewCommon.js';
import { makeTaskHistory } from './overviewPageRenderer.js';
import { overviewVars } from './overviewVariable.js';
//๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ Overview ๋ชจ๋ฌ ๊ณตํต ์ฌ์ฉ ์์ ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ
// ๋ชจ๋ฌCLSOE
const modalNames = ['facility-size', 'section-left', 'section-middle', 'schedule-list', 'schedule', 'task-period'];
modalNames.forEach(name => {
const modal = document.querySelector(`.overview-modal.${name}`);
if (!modal) return;
const closeBtn = modal.querySelector('.overview-modal-header--end img');
const footerCloseBtn = modal.querySelector('.modal-footer .btn-close');
closeBtn?.addEventListener('click', () => {
modal.style.display = 'none';
document.querySelector('.overview-modal-wrapper').style.display = 'none';
// ๋ณ์ ์ด๊ธฐํ
overviewVarsInit();
});
footerCloseBtn?.addEventListener('click', () => {
modal.style.display = 'none';
document.querySelector('.overview-modal-wrapper').style.display = 'none';
// ๋ณ์ ์ด๊ธฐํ
overviewVarsInit();
});
});
// ๋ชจ๋ฌ ์์ญ ์ธ์ ํด๋ฆญํ์๋ ๋ชจ๋ฌ ๊บผ์ง๋ ์ด๋ฒคํธ
// document.querySelector('.overview-modal-wrapper')?.addEventListener('pointerdown', (e) => {
// document.querySelector('.overview-modal-wrapper').style.display = 'none';
// document.querySelectorAll('.overview-modal').forEach(modal => {
// if (!modal.contains(e.target)) {
// modal.style.display = 'none';
// }
// });
// });
// ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ Overview ๋ชจ๋ฌ ๊ณตํต ์ฌ์ฉ ๋ ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ
//๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ Secion-Left ๋ชจ๋ฌ ์์ ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ
// ์์น๋/๊ฐ์๋ ๋๋๊ทธ์ค๋๋กญ
export function fileDragAndDrop() {
const dropbox = document.querySelector('.overview-modal .dropbox');
dropbox.addEventListener('dragenter', (e) => {
e.preventDefault();
dropbox.style.background = '#999';
});
dropbox.addEventListener('dragover', (e) => {
e.preventDefault();
dropbox.style.background = '#999';
});
dropbox.addEventListener('dragleave', (e) => {
e.preventDefault();
dropbox.style.background = '#e6e8ea';
});
dropbox.addEventListener('drop', (e) => {
e.preventDefault();
dropbox.style.background = '#e6e8ea';
const files = Array.from(e.dataTransfer.files);
// ์ค๋ณต ์ด๋ฆ๊ณผ ํ์ฅ์ ์ฒดํฌ
checkDuplicatesFileNameAndExt(files);
displayFileName();
});
};
// section-left ๋ชจ๋ฌ ์ด๊ธฐ
document.querySelector('.overview .box-header--right.section-left-edit')?.addEventListener('click', () => {
const modal = document.querySelector('.overview-modal.section-left');
const modalWrapper = document.querySelector('.overview-modal-wrapper');
modal.querySelector('.business-purpose').value = document.querySelector('.overview .box-body.business-purpose').innerText;
modal.querySelector('.performance-area').value = document.querySelector('.overview .box-body.location-map-detail .performance-area').innerText;
modal.querySelector('.reference-area').value = document.querySelector('.overview .box-body.location-map-detail .reference-area').innerText;
modal.querySelector('.facility-overview').value = document.querySelector('.overview .box-body.facility-size .facility-overview').innerText;
//overseas์ฉ ๋ถ๊ธฐ
if(!overviewVars.overseas){
modal.querySelector('.nation').value = document.querySelector('.overview .box-body.location-map-detail .nation-nm').innerText;
modal.querySelector('.continent').value = document.querySelector('.overview .box-body.location-map-detail .continent').innerText;
} else {
modal.querySelector('.nation').innerText = document.querySelector('.overview .box-body.location-map-detail .nation-nm').innerText;
modal.querySelector('.continent').innerText = document.querySelector('.overview .box-body.location-map-detail .continent').innerText;
}
overviewVarsInit();
if(overviewVars.filesNameArr.length > 0) displayFileName();
modal.querySelectorAll('input[type=file]').forEach(input => { input.value = ''; })
makeTabCell(overviewVars.originalSectionTabData);
// ํ ๊ธ ์ฒ๋ฆฌ
if (modal.style.display === 'block') {
modal.style.display = 'none';
return;
}
modal.style.display = 'block';
modalWrapper.style.display = 'block';
});
// section-left ๋ชจ๋ฌ ์์ค๊ท๋ชจ ํญ,์
์์ฑ ํจ์
export function makeTabCell(data) {
const tabContainer = document.querySelector('.section-tabs');
const contentContainer = document.querySelector('.section-content');
// ๊ฐ๋ก ์คํฌ๋กค ์ด๋ฒคํธ
tabContainer.addEventListener('wheel', (e) => {
e.preventDefault();
tabContainer.scrollLeft += e.deltaY;
});
tabContainer.innerHTML = '';
contentContainer.innerHTML = '';
// ๋ฐ์ดํฐ ์์ ๋ ๊ธฐ๋ณธ๊ฐ
if (Object.keys(data).length === 0) {
data = { '': [{ key: '', value: '', id: '' }] };
}
const titles = Object.keys(data);
titles.forEach((title, index) => {
const tab = createTab(title, index === 0);
bindTabEvents(tab, contentContainer);
tabContainer.appendChild(tab);
});
// ํญ ์ถ๊ฐ ๋ฒํผ
const addBtn = document.createElement('button');
addBtn.classList.add('xs-btn', 'add');
addBtn.innerHTML = `
`;
tabContainer.appendChild(addBtn);
addBtn.addEventListener('click', () => {
const newTab = createTab('', true);
bindTabEvents(newTab, contentContainer, true);
tabContainer.insertBefore(newTab, addBtn);
newTab.click();
});
// ์ฒซ๋ฒ์งธ ํญ ํด๋ฆญ
if (titles.length > 0) {
tabContainer.querySelector('.tab')?.click();
}
}
// ํญ ์์ฑ
function createTab(title, isActive) {
const tab = document.createElement('div');
tab.className = 'tab';
if (isActive) tab.classList.add('click-on');
const input = document.createElement('input');
input.className = 'tab-style-input';
input.type = 'text';
input.value = title;
input.placeholder = 'ํญ ์ ๋ชฉ ์
๋ ฅ';
const closeBtn = document.createElement('button');
closeBtn.className = 'xs-btn';
closeBtn.innerHTML = `
`;
tab.appendChild(input);
tab.appendChild(closeBtn);
return tab;
}
// ํญ ํด๋ฆญ, ์ ๋ชฉ์
๋ ฅ, ์ญ์ ๋ฒํผ ์ด๋ฒคํธ
function bindTabEvents(tab, contentContainer, isNew = false) {
const input = tab.querySelector('input');
const closeBtn = tab.querySelector('button');
// ํญ ํด๋ฆญ ์ด๋ฒคํธ
tab.addEventListener('click', () => {
document.querySelectorAll('.section-tabs .tab').forEach(t => t.classList.remove('click-on'));
tab.classList.add('click-on');
renderCells(input.value.trim(), contentContainer);
});
// ํญ ์ ๋ชฉ input ๋ณ๊ฒฝ ์ด๋ฒคํธ
let previousSection = input.value.trim();
input.addEventListener('input', () => {
const section = String(input.value.trim());
// ํญ ์ ๋ชฉ์ด ๋น๊ฐ ์ผ๋ ์ญ์ ์ฒ๋ฆฌ
if (section === '') {
if (previousSection && overviewVars.sectionTabData[previousSection]) delete overviewVars.sectionTabData[previousSection];
showToolTip(input, 'ํญ ์ ๋ชฉ์ด ์์ด ์
๋ด์ฉ์ด ์ด๊ธฐํ๋์์ต๋๋ค.')
// ์
์ด๊ธฐํ
document.querySelectorAll('.section-content .section-content--cell').forEach((cell, index) => {
if(index === 0){
cell.querySelectorAll('input').forEach(input => input.value = '');
} else{
// ์
์ถ๊ฐ ๋ฒํผ์ ๊ฑด๋๋
if(cell.className === 'section-content--cell add-cell-btn') return;
cell.remove();
}
});
previousSection = '';
return;
}
// ํญ ์ ๋ชฉ์ด ๊ฐ์๋ ์ฒ๋ฆฌ ๋ง๊ธฐ
if (section !== previousSection && overviewVars.sectionTabData[section]){
showToolTip(input, '์ด๋ฏธ ์กด์ฌํ๋ ํญ ์ด๋ฆ์
๋๋ค. ๋ค๋ฅธ ์ด๋ฆ์ ์
๋ ฅํด์ฃผ์ธ์.')
input.value = previousSection;
return;
}
// ํญ ์ด๋ฆ์ด ๋ณ๊ฒฝ๋ ๋
if (previousSection && previousSection !== section) {
if (overviewVars.sectionTabData[previousSection]) {
overviewVars.sectionTabData[section] = overviewVars.sectionTabData[previousSection];
delete overviewVars.sectionTabData[previousSection];
} else {
overviewVars.sectionTabData[section] = [];
}
} else if (!overviewVars.sectionTabData[section]) {
overviewVars.sectionTabData[section] = [];
}
previousSection = section;
});
// ํญ ์ญ์ ์ด๋ฒคํธ
closeBtn.addEventListener('click', async (e) => {
e.stopPropagation();
const title = input.value;
const tabLength = document.querySelectorAll('.section-tabs .tab').length;
const tabInput = document.querySelector('.section-tabs .tab input');
const cell = document.querySelectorAll('.section-content--cell input');
const emptyTab = !tabInput?.value.trim();
const emptyCell = Array.from(cell).every(input => !input.value.trim());
// ํญ์ด ํ ๊ฐ ๋จ์๊ณ ๊ณต๋ฐฑ์ผ ๊ฒฝ์ฐ ์ญ์ ๋ง๊ธฐ
if (tabLength === 1 && emptyTab && emptyCell) return;
try {
if (tabLength === 1) {
delete overviewVars.sectionTabData[title];
document.querySelector('.section-tabs .tab input').value = '';
document.querySelectorAll('.section-content .section-content--cell').forEach((cell, index) => {
if(index === 0){
cell.querySelectorAll('input').forEach(input => input.value = '');
} else{
// ์
์ถ๊ฐ ๋ฒํผ์ ๊ฑด๋๋
if(cell.className === 'section-content--cell add-cell-btn') return;
cell.remove();
}
});
} else {
delete overviewVars.sectionTabData[title];
tab.remove();
const allTabs = document.querySelectorAll('.section-tabs .tab');
const lastTab = allTabs[allTabs.length - 1];
if (lastTab) lastTab.click();
}
} catch (err) {
console.error(err);
}
});
}
// ์
๋ ๋๋ฉ
function renderCells(title, container) {
container.innerHTML = '';
let cells = overviewVars.sectionTabData[title] || [{ key: '', value: '', id: '' }];
// ํ์ดํ๋ง ์๊ณ ์
์ ๋ด์ฉ์ด ์์๋ ๊ธฐ๋ณธ๊ฐ ์ค์
if(cells.length === 0) cells = [{ key: '', value: '', id: '' }];
cells.forEach(cell => {
const row = createCell(cell);
bindCellEvents(row, title);
container.appendChild(row);
});
if (!container._hasInputEvent) {
container.addEventListener('input', (e) => {
if (!e.target.matches('input')) return;
const section = document.querySelector('.tab.click-on input').value.trim();
if (section === '') {
container.querySelectorAll('.section-content--cell input').forEach(cell => {
cell.value = ''
});
showToolTip(e.target, 'ํญ์ ์ ๋ชฉ์ ๋จผ์ ์
๋ ฅํด์ฃผ์ธ์')
return
}
const keyInputs = container.querySelectorAll('input.short-input');
const valueInputs = container.querySelectorAll('input.middle-input');
const keyValueList = [];
for (let i = 0; i < keyInputs.length; i++) {
const key = keyInputs[i].value;
const value = valueInputs[i] ? valueInputs[i].value : '';
const id = keyInputs[i].dataset.id ? parseInt(keyInputs[i].dataset.id) : null;
const projectId = vars.project_id;
keyValueList.push({ key, value, id, projectId });
}
overviewVars.sectionTabData[section] = keyValueList;
});
container._hasInputEvent = true;
}
// ์
์ถ๊ฐ ๋ฒํผ
const addCell = document.createElement('div');
addCell.className = 'section-content--cell add-cell-btn';
addCell.innerHTML = `
์
์ถ๊ฐ
`;
addCell.addEventListener('click', () => {
const newCell = createCell({ key: '', value: '', id: null });
bindCellEvents(newCell, title);
container.insertBefore(newCell, addCell);
});
container.appendChild(addCell);
}
// ์
์์ฑ
function createCell(cell) {
const row = document.createElement('div');
row.className = 'section-content--cell';
row.innerHTML = `
`;
const btn = document.createElement('button');
btn.classList.add('xs-btn', 'cell-remove');
btn.innerHTML = `
`;
row.appendChild(btn);
return row;
}
// ์
์ญ์ ๋ฒํผ ์ด๋ฒคํธ ์ถ๊ฐ
function bindCellEvents(row, title) {
const btn = row.querySelector('.cell-remove');
const cellId = row.querySelector('input')?.dataset.id;
btn.addEventListener('click', async () => {
try {
// ๊ธฐ๋ณธ์์ฑ๋ ์
์ด๋ฒคํธ์์ title์ด ๋ค์ด์ค์ง ์๋ ๊ฒฝ์ฐ๊ฐ ์์ด์ ๊ฐ์ ์ง์ ๋ฃ์ด์ค
title = document.querySelector('.section-tabs .tab.click-on input').value;
const cells = document.querySelectorAll('.section-content--cell');
if (cellId) {
// DB ์ญ์ ์ฑ๊ณต ์ sectionTabData ์
๋ฐ์ดํธ
const index = overviewVars.sectionTabData[title].findIndex(item => item.id == cellId);
if (index !== -1) overviewVars.sectionTabData[title].splice(index, 1);
} else {
// ํญ ์
๋ ฅ์ด ๋์ง์๊ณ sectionTabData์ data๊ฐ ์์๋ row ์ญ์ ์ฒ๋ฆฌ
if(!overviewVars.sectionTabData[title]){
if(cells.length > 2){
return row.remove();
} else {
return;
}
}
const index = overviewVars.sectionTabData[title].findIndex(item => item.key === row.querySelector('.short-input')?.value && item.value === row.querySelector('.middle-input')?.value);
if(index !== -1) overviewVars.sectionTabData[title].splice(index, 1);
}
// ์
์ด ํ๋๋ฟ์ด๋ฉด value ์ด๊ธฐํ, ์๋๋ฉด ์ญ์
if (cells.length === 2) {
row.querySelectorAll('input').forEach(input => input.value = '');
} else {
row.remove();
}
} catch (err) {
console.error(err);
}
});
}
// Section-left ์์ค๊ท๋ชจ ๋ชจ๋ฌ OPEN
document.querySelector('.overview .box-header--right.facility-size button')?.addEventListener('click', async () => {
const modalWrapper = document.querySelector('.overview-modal-wrapper');
const modal = document.querySelector('.overview-modal.facility-size');
//ํ ๊ธ
if (modal.style.display === 'block') {
modal.style.display = 'none';
modalWrapper.style.display = 'none';
return;
}
try {
const res = await axios.get(`/${vars.project_id}/overview/getFacilitySizeData`, { params: { projectId: vars.project_id } });
if (res.data.message === '200') {
const modalBody = modal.querySelector('.overview-modal-body');
modalBody.innerHTML = '';
const dataArr = res.data.data;
if (dataArr.length === 0) {
modalBody.innerHTML = `
`
}
let currentTitle = '';
for (let i = 0; i < dataArr.length; i++) {
if (dataArr[i].title !== currentTitle) {
currentTitle = dataArr[i].title;
const boxHeader = document.createElement('div');
boxHeader.className = 'box-header';
const h3 = document.createElement('h3');
h3.textContent = currentTitle;
boxHeader.appendChild(h3);
modalBody.appendChild(boxHeader);
}
const typeWrap = document.createElement('div');
typeWrap.className = 'type--wrap';
const left = document.createElement('div');
left.className = 'type--wrap-left';
const p = document.createElement('p');
p.textContent = dataArr[i].key;
left.appendChild(p);
const right = document.createElement('div');
right.className = 'type--wrap-right';
const h4 = document.createElement('h4');
h4.textContent = dataArr[i].value;
right.appendChild(h4);
typeWrap.appendChild(left);
typeWrap.appendChild(right);
modalBody.appendChild(typeWrap);
}
}
modal.style.display = 'block';
modalWrapper.style.display = 'block';
} catch (err) {
console.log(err);
}
});
// section-left ์์น๋/๊ฐ์๋ ์ด๋ฏธ์ง ์ ์ฅ
document.querySelector('.overview-modal.section-left .overview-img-file-input')?.addEventListener('change', () => {
const files = Array.from(document.querySelector('.overview-modal.section-left .overview-img-file-input').files);
// ์ค๋ณต ์ด๋ฆ๊ณผ ํ์ฅ์ ์ฒดํฌ
checkDuplicatesFileNameAndExt(files);
// ๋ฑ๋ก๋ ํ์ผ์ ์ด๋ฆ์ ์ถ๊ฐ
displayFileName();
// ์ด๊ธฐํ
document.querySelector('.overview-modal.section-left .overview-img-file-input').value = '';
});
// ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ Secion-Left ๋ชจ๋ฌ ๋ ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ
//๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ Secion-Middle ๋ชจ๋ฌ ์์ ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ
// section-middle ๋ชจ๋ฌ ์ด๊ธฐ
document.querySelector('.overview .box-header--right.section-middle-edit')?.addEventListener('click', () => {
const modal = document.querySelector('.overview-modal.section-middle');
const modalWrapper = document.querySelector('.overview-modal-wrapper');
modal.querySelector('.abbreviated-name').value = document.querySelector('.overview .abbreviated-name').innerText;
modal.querySelector('.task-nm-en').value = document.querySelector('.overview .task-nm-en').innerText;
modal.querySelector('.task-purpose').value = document.querySelector('.overview .task-purpose').innerText;
modal.querySelector('.order-size-usd').value = document.querySelector('.overview .order-size-usd').innerText;
modal.querySelector('.order-size-krw').value = document.querySelector('.overview .order-size-krw').innerText;
modal.querySelector('.client-origin').value = document.querySelector('.overview .client-origin').innerText;
modal.querySelector('.financial').value = document.querySelector('.financial').innerText;
modal.querySelector('.financial-country').value = document.querySelector('.overview .financial-country').innerText;
modal.querySelector('.selection-method').value = document.querySelector('.overview .selection-method').innerText;
modal.querySelector('.overview-table-container').innerHTML = document.querySelector('.overview .overview-table-container ').innerHTML;
modal.querySelector('.support-department').value = document.querySelector('.overview .support-department').innerText;
modal.querySelector('.support-manager-nm').value = document.querySelector('.overview .support-manager-nm').innerText;
modal.querySelector('.completion-date').value = document.querySelector('.overview .completion-date').innerText;
// overseas์ฉ ๋ถ๊ธฐ
if(!overviewVars.overseas){
modal.querySelector('.project-no').value = document.querySelector('.overview .project-no').innerText;
modal.querySelector('.task-type').value = document.querySelector('.overview .task-type').innerText;
modal.querySelector('.bid').value = document.querySelector('.overview .bid').innerText;
modal.querySelector('.client').value = document.querySelector('.overview .client').innerText;
modal.querySelector('.department').value = document.querySelector('.overview .department').innerText;
modal.querySelector('.currency-code').value = document.querySelector('.overview .currency-code').innerText;
modal.querySelector('.task-nm-kr').value = document.querySelector('.overview .task-nm-kr').innerText;
modal.querySelector('.contract-period').value = document.querySelector('.overview .contract-period').innerText;
modal.querySelector('.projectmanager-nm').value = document.querySelector('.overview .projectmanager-nm').innerText;
modal.querySelector('.manager-nm').value = document.querySelector('.overview .manager-nm').innerText;
modal.querySelector('.contract-date').value = document.querySelector('.overview .contract-date').innerText;
modal.querySelector('.commencement-date').value = document.querySelector('.overview .commencement-date').innerText;
modal.querySelector('.scheduled-completion-date').value = document.querySelector('.overview .scheduled-completion-date').innerText;
modal.querySelector('.scheuled-commencement-date').value = document.querySelector('.overview .scheuled-commencement-date').innerText;
modal.querySelectorAll('.joint-contract-company-name').forEach(company => { company.contentEditable = true; company.style.color = '#FF3D00'; })
// ๊ณต๋๋๊ธ ์์ , ์์๋ณํ, ์ซ์ ์ ํ
modal.querySelectorAll('.joint-contract-company-shares, .joint-contract-krw, .joint-contract-usd').forEach(joint => {
joint.contentEditable = true;
joint.style.color = '#FF3D00';
joint.addEventListener('input', (event) => {
restrictToNumber(joint, event);
calculateTotalJointContract(joint);
});
});
} else {
modal.querySelector('.project-no').innerText = document.querySelector('.overview .project-no').innerText;
modal.querySelector('.task-type').innerText = document.querySelector('.overview .task-type').innerText;
modal.querySelector('.bid').innerText = document.querySelector('.overview .bid').innerText;
modal.querySelector('.client').innerText = document.querySelector('.overview .client').innerText;
modal.querySelector('.department').innerText = document.querySelector('.overview .department').innerText;
modal.querySelector('.currency-code').innerText = document.querySelector('.overview .currency-code').innerText;
modal.querySelector('.task-nm-kr').innerText = document.querySelector('.overview .task-nm-kr').innerText;
modal.querySelector('.contract-period').innerText = document.querySelector('.overview .contract-period').innerText;
modal.querySelector('.projectmanager-nm').innerText = document.querySelector('.overview .projectmanager-nm').innerText;
modal.querySelector('.manager-nm').innerText = document.querySelector('.overview .manager-nm').innerText;
modal.querySelector('.contract-date').innerText = document.querySelector('.overview .contract-date').innerText;
modal.querySelector('.commencement-date').innerText = document.querySelector('.overview .commencement-date').innerText;
modal.querySelector('.scheduled-completion-date').innerText = document.querySelector('.overview .scheduled-completion-date').innerText;
modal.querySelector('.scheuled-commencement-date').innerText = document.querySelector('.overview .scheuled-commencement-date').innerText;
}
const jointTable = modal.querySelector('.overview-table-container')
// ํญ ์ปจํ
์ด๋ ๊ฐ๋ก์คํฌ๋กค ํ ์ด๋ฒคํธ ์ถ๊ฐ
jointTable.addEventListener('wheel', (e)=> {
e.preventDefault();
jointTable.scrollLeft += e.deltaY;
});
// ํ ๊ธ ์ฒ๋ฆฌ
if (modal.style.display === 'block') {
modal.style.display = 'none';
return;
}
modal.style.display = 'block';
modalWrapper.style.display = 'block';
});
// section-middle ๊ณผ์
๊ธฐ๊ฐ ๋ชจ๋ฌ ์ด๊ธฐ
document.querySelector('.overview .box-header--right.task-period')?.addEventListener('click', async () => {
const modal = document.querySelector('.overview-modal.task-period');
const modalWrapper = document.querySelector('.overview-modal-wrapper');
modal.querySelector('.contract-date').innerText = document.querySelector('.overview .contract-date').innerText;
modal.querySelector('.commencement-date').innerText = document.querySelector('.overview .commencement-date').innerText;
modal.querySelector('.scheduled-completion-date').innerText = document.querySelector('.overview .scheduled-completion-date').innerText;
modal.querySelector('.completion-date').innerText = document.querySelector('.overview .completion-date').innerText;
// ๊ณผ์
์ค์ง ์ด๋ ฅ ์์ฑ
makeTaskHistory();
// ํ ๊ธ ์ฒ๋ฆฌ
if (modal.style.display === 'block') {
modal.style.display = 'none';
return;
}
modal.style.display = 'block';
modalWrapper.style.display = 'block';
});
// section-middle ๊ณผ์
์ค์ง ์ด๋ ฅ ๋ฆฌ์คํธ ์ถ๊ฐ
document.querySelector('.overview-modal.task-period .box-header--right button')?.addEventListener('click', () => {
const ul = document.querySelector('.overview-modal.task-period .overview-modal-body ul');
const li = document.createElement('li');
// ์ฐจ์
const numberDiv = document.createElement('div');
numberDiv.className = 'work-list-number';
const orderInput = document.createElement('input');
orderInput.type = 'text';
orderInput.className = 'order work-list-number';
numberDiv.appendChild(orderInput);
// ์ค์ง์ผ์
const dateDiv = document.createElement('div');
dateDiv.className = 'work-list-date';
const dateInput = document.createElement('input');
dateInput.className = 'suspension-date work-list-date';
dateInput.type = 'date';
dateDiv.appendChild(dateInput);
// ์ค์ง์ฌ์
const reasonDiv = document.createElement('div');
reasonDiv.className = 'work-list-script';
const reasonInput = document.createElement('input');
reasonInput.className = 'suspension-reason work-list-script';
reasonInput.type = 'text';
reasonDiv.appendChild(reasonInput);
// ์ฌ๊ฐ์ผ์
const redateDiv = document.createElement('div');
redateDiv.className = 'work-list-redate';
const redateInput = document.createElement('input');
redateInput.className = 'resumption-date work-list-redate';
redateInput.type = 'date';
redateDiv.appendChild(redateInput);
// ํ์๋ด์ฉ
const detailDiv = document.createElement('div');
detailDiv.className = 'work-list-detail';
const consultInput = document.createElement('input');
consultInput.className = 'consuletation-content work-list-detail';
consultInput.type = 'text';
detailDiv.appendChild(consultInput);
// ๋ณ๊ฒฝ ์ผ์
const changeDiv = document.createElement('div');
changeDiv.className = 'work-list-changedate';
const changeInput = document.createElement('input');
changeInput.className = 'change-date work-list-changedate';
changeInput.type = 'date';
changeDiv.appendChild(changeInput);
const btn = document.createElement('button');
btn.className = 'xs-btn-type';
const img = document.createElement('img');
img.className = 'icon';
img.src = '/main/img/overview/icon-close-111.svg';
img.alt = 'icon-close-111';
btn.appendChild(img);
// ๊ณผ์
์ค์ง์ด๋ ฅ ๋ฆฌ์คํธ ๊ฐ๋ณ ์ญ์ ๋ฒํผ
btn.addEventListener('click', async (e) => {
li.remove();
});
li.append(numberDiv, dateDiv, reasonDiv, redateDiv, detailDiv, changeDiv, btn);
ul.appendChild(li);
});
if(!overviewVars.overseas){
// section-middle ๊ณต๋๋๊ธ ์ด ์ถ๊ฐ
document.querySelector('.overview-modal.section-middle .joint-contract-add')?.addEventListener('click', () => {
const table = document.querySelector('.overview-modal.section-middle .overview-table-container table');
const headerRow = table.querySelector('thead tr');
const currentCols = headerRow.querySelectorAll('th').length;
// ์ด๊ณ์ ์ฃผ๊ด์ฌ
const newIndex = currentCols - 1;
document.querySelector('.overview-modal .total-joint-contract-company-name').innerText = newIndex;
const newTh = document.createElement('th');
if (newIndex < 2) {
newTh.innerText = '์ฃผ๊ด์ฌ';
} else {
newTh.innerText = `๊ณต๋๋๊ธ${newIndex - 1}`;
}
headerRow.appendChild(newTh);
const tbodyRows = table.querySelectorAll('tbody tr');
const defaultValues = ['ํ์ฌ๋ช
', '0', '0', '0'];
const classList = ['joint-contract-company-name', 'joint-contract-company-shares', 'joint-contract-krw', 'joint-contract-usd'];
tbodyRows.forEach((row, idx) => {
const td = document.createElement('td');
td.className = classList[idx];
td.innerText = defaultValues[idx];
td.contentEditable = true;
td.style.color = '#FF3D00';
// ๊ณต๋๋๊ธ ์ซ์ ์ ํ
if (idx > 0) {
td.addEventListener('input', (event) => {
restrictToNumber(td, event);
calculateTotalJointContract(td);
});
}
row.appendChild(td);
});
});
// section-middle ๊ณต๋๋๊ธ ์ด ์ญ์
document.querySelector('.overview-modal.section-middle .joint-contract-delete')?.addEventListener('click', () => {
const table = document.querySelector('.overview-modal.section-middle .overview-table-container table');
const theadRow = table.querySelector('thead tr');
const ths = theadRow.querySelectorAll('th');
// ์ฃผ๊ด์ฌ๊น์ง ์ญ์ ํ์๋ ๊ณ์ฐํ ๊ฐ์ด ์์ผ๋ฏ๋ก ์ด๊ธฐํ
if (ths.length === 3){
document.querySelector('.overview-modal .total-joint-contract-company-name').innerText = 0;
document.querySelectorAll('.overview-modal .total-joint-contract-company-shares, .overview-modal .total-joint-contract-krw, .overview-modal .total-joint-contract-usd').forEach(el => el.innerText = 0);
}
if (ths.length <= 2) {
alert("์ญ์ ํ ์ ์๋ ์ด์ด ์์ต๋๋ค.");
return;
}
// ๋ง์ง๋ง th ์ญ์
theadRow.removeChild(ths[ths.length - 1]);
// tbody์ ๋ง์ง๋ง td ์ญ์
const tbodyRows = table.querySelectorAll('tbody tr');
tbodyRows.forEach(row => {
const tds = row.querySelectorAll('td');
if (tds.length > 2) {
row.removeChild(tds[tds.length - 1]);
}
});
// ์ญ์ ์์ ์ด๊ณ ๊ณ์ฐ
document.querySelectorAll('.overview-modal.section-middle .overview-table-container td').forEach(td => {
calculateTotalJointContract(td);
});
// ์ด ํ์ฌ ์ ์
๋ฐ์ดํธ
document.querySelector('.overview-modal .total-joint-contract-company-name').innerText = ths.length - 3;
});
}
// ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ Secion-Middle ๋ชจ๋ฌ ๋ ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ
//๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ Secion-Right ๋ชจ๋ฌ ์์ ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ๐ฝ
// section-right ์บ๋ฆฐ๋ ์ฃผ์์ผ์ ํ๋ฃจ์ข
์ผ ๋ฒํผ
document.querySelector('.overview-modal.schedule .custom-checkbox.all-day')?.addEventListener('change', () => {
const allDay = document.querySelector('.overview-modal.schedule .custom-checkbox.all-day input');
const startTime = document.querySelector('.overview-modal.schedule .startTime');
const endTime = document.querySelector('.overview-modal.schedule .endTime');
const isChecked = allDay.checked;
startTime.disabled = isChecked;
endTime.disabled = isChecked;
if (isChecked) {
startTime.value = '';
endTime.value = '';
} else {
startTime.value = '00:00';
endTime.value = '23:59';
}
});
// section-right ์ฃผ์์ผ์ Color ํด๋ฆญ ํจ๊ณผ
document.querySelectorAll('.overview-modal .color .label-color')?.forEach(btn => {
btn.addEventListener('click', (e) => {
document.querySelectorAll('.overview-modal .color .label-color').forEach(label => {
label.classList.remove('on');
});
e.target.classList.add('on');
});
});
// ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ Secion-Right ๋ชจ๋ฌ ๋ ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ๐ผ