[FO] 일계부 수입/지출 스크립트 공통 정리

This commit is contained in:
김현주
2025-06-17 10:05:10 +09:00
parent 7db6843313
commit ffcf1a8934
5 changed files with 203 additions and 297 deletions

View File

@@ -23,12 +23,12 @@ krip.daily.goToPrev = function(target, searchMonth, groupNo) {
url = url.replace('{target}', target);
console.log(url);
}
};
krip.daily.goToPrev = function() {
// TODO : history.back 으로 해결 되는가?
history.back();
}
};
krip.daily.goToNext = function(target, searchMonth, groupNo) {
let url = krip.daily.httpUrl.target;
@@ -60,4 +60,122 @@ krip.daily.todayNone = function(month, groupNo, target, checked) {
$('.component-btns').find('.btn-primary').attr('disabled', !checked);
},
);
};
krip.daily.baseBindUI = function() {
etUI.locales.ko = {
dialog: {
positive: '예',
negative: '아니오',
},
};
const $noneWrap = $('input[name="todayNone"]');
$noneWrap.on('click', function () {
let checked = $(this).is(':checked');
let $btn = $(ENV.modal.selectorId);
$btn.attr('disabled', checked);
if (checked) {
$btn.find('i').addClass('ico-add-disabled');
$btn.find('i').removeClass('ico-add');
$noneWrap.val('Y');
} else {
$btn.find('i').addClass('ico-add');
$btn.find('i').removeClass('ico-add-disabled');
//document.reqForm.todayNone.value = 'N';
$noneWrap.val('N');
}
// TODO 2번 이벤트 발생하는 원인 찾기
console.log(1111)
krip.daily.todayNone(ENV.month, ENV.groupNo, $noneWrap.data('type'), checked);
});
const $formWrap = $(ENV.modal.selectorId);
$formWrap.on('click', function() {
krip.daily.createModal();
});
}
krip.daily.createModal = function(id) {
if (ENV.httpUrl.form === undefined) {
kri.logger.warn('[daily] form url is none.');
return;
}
if (id === undefined) {
id = 0;
}
ajaxUtil._ajaxAsyncMethod(
ENV.httpUrl.form.replace('{id}', id),
{},
function(rstHtml, status) {
$(ENV.modal.selector).find('.modal-content').html(rstHtml);
const modal01 = document.querySelector(ENV.modal.selector).ui;
modal01.open();
modalControl._bindModelUI();
},
function(code, rstData) {
kri.logger.error('Do nothing. code: '+ code, rstData);
},
'get',
'html'
);
}
krip.daily.removeConfirm = function(id) {
etUI.dialog.alert({
title: '삭제 안내',
message: '등록하신 내용을 삭제하시겠어요?<br>삭제된 내용은 복구할 수 없습니다.',
type: 'confirm',
dialogType: 'confirm',
callback: function () {
krip.daily.remove(id);
},
});
};
krip.daily.remove = function(id) {
if (ENV.httpUrl.remove === undefined) {
kri.logger.warn('[daily] remove url is none.');
return;
}
ajaxUtil._ajaxAsync(
ENV.httpUrl.remove,
{ 'id': id },
function (rstData, status) {
location.reload();
},
);
};
krip.daily.resetConfirm = function() {
etUI.dialog.alert({
title: '초기화 안내',
message: '등록하신 모든 내용을 삭제하시겠어요?<br>삭제된 내용은 복구할 수 없습니다.',
type: 'confirm',
dialogType: 'confirm',
callback: function () {
krip.daily.reset();
},
});
};
krip.daily.reset = function() {
if (ENV.httpUrl.reset === undefined) {
kri.logger.warn('[daily] reset url is none.');
return;
}
ajaxUtil._ajaxAsync(
ENV.httpUrl.reset,
{},
function (rstData, status) {
location.reload();
},
);
};

View File

@@ -3,14 +3,6 @@
xmlns:th="http://www.thymeleaf.org" lang="ko">
<th:block>
<th:block th:if="${@systemProperties['spring.profiles.active'] eq 'local'}">
<div>
reqVO: [[${reqVO}]]
</div>
<div>
detail: [[${dailyRecord}]]
</div>
</th:block>
<div class="modal-content-inner">
<div class="component-btns type-tab"
th:if="${not detail.updated}">
@@ -164,7 +156,7 @@
<div class="component-btns">
<div class="btns-row">
<button type="button" class="btn btn-full btn-l btn-primary" onclick="formControl.createVaild();">
<button type="button" class="btn btn-full btn-l btn-primary" onclick="modalControl.createVaild();">
<span class="btn-txt">등록</span>
</button>
</div>

View File

@@ -3,14 +3,6 @@
xmlns:th="http://www.thymeleaf.org" lang="ko">
<div layout:fragment="content" th:classappend="acco-wrap">
<th:block th:if="${@systemProperties['spring.profiles.active'] eq 'local'}">
<div>
reqVO: [[${reqVO}]]
</div>
<div>
dailyRecord: [[${dailyRecord}]]
</div>
</th:block>
<main id="content" role="main">
<div class="inner">
<hgroup class="tit-group">
@@ -27,9 +19,6 @@
<p>지출 내역을 등록해 주세요.</p>
</hgroup>
<form name="reqForm">
<input type="hidden" name="todayNone" value="N">
</form>
<!--/* 신규 등록 */-->
<th:block th:if="${#lists.isEmpty(expenseList)}">
<button type="button" class="btn btn-m btn-secondary btn-full button-modal01" data-testid="button-modal01"
@@ -38,10 +27,10 @@
th:classappend="${#strings.equals(dailyRecord.expenseStatus, 'TODAY_NONE') ? 'ico-add-disabled' : 'ico-add'}"></i>
<span class="btn-txt">추가 등록</span>
</button>
<div class="component-input align-center">
<label class="checkbox-inner" id="todayNone">
<input type="checkbox" name="todayNone"
data-type="EXPENSE"
th:checked="${#strings.equals(dailyRecord.expenseStatus, 'TODAY_NONE')}">
<span class="checkbox-item">
<span class="checkbox-txt">금일 등록내용 없음</span>
@@ -54,7 +43,7 @@
<section class="regist-item-area">
<p class="total">
<span>총 <strong>[[${#lists.size(expenseList)}]]</strong>건</span>
<button type="button" class="btn-reset" onclick="formControl.resetConfirm()">
<button type="button" class="btn-reset" onclick="krip.daily.resetConfirm()">
<i class="ico-reset ico-small" aria-hidden="true"></i>
<span>초기화</span>
</button>
@@ -65,8 +54,8 @@
<div class="item-tit-group">
<p class="item-name">[[${item.categorySelf}]]</p>
<div class="btn-group">
<button type="button" class="delete" th:onclick="formControl.removeConfirm([[${item.id}]])"><span class="hide-txt">삭제</span></button>
<button type="button" class="edit" th:onclick="formControl.createModal([[${item.id}]])"><span class="hide-txt">수정</span></button>
<button type="button" class="delete" th:onclick="krip.daily.removeConfirm([[${item.id}]])"><span class="hide-txt">삭제</span></button>
<button type="button" class="edit" th:onclick="krip.daily.createModal([[${item.id}]])"><span class="hide-txt">수정</span></button>
</div>
</div>
<ul class="detail-list">
@@ -150,67 +139,25 @@
remove: /*[[|/api/record/expense/${reqVO.searchMonth}/${reqVO.groupNo}/remove|]]*/'removeUrl',
reset: /*[[|/api/record/expense/${reqVO.searchMonth}/${reqVO.groupNo}/reset|]]*/'resetUrl',
},
modal: {
// 등록 버튼
selectorId: '.button-modal01',
// 등록 영역
selector: '.modal01',
},
month: /*[[${reqVO.searchMonth}]]*/'month',
groupNo: /*[[${reqVO.groupNo}]]*/'groupNo',
submitted: false,
};
let bind = {
form: {
selectorId: '.button-modal01',
selector: '.modal01',
},
selectbox: null,
}
let formControl = {
init() {
formControl._bindUI();
//formControl.createModal();
// TODO 등록된 건수가 0일 경우 버튼 비활성화
krip.daily.baseBindUI();
},
_bindUI() {
etUI.locales.ko = {
dialog: {
positive: '예',
negative: '아니오',
},
};
};
let $noneWrap = $('#todayNone');
$noneWrap.on('click', 'input[name="todayNone"]', function() {
let checked = $(this).is(':checked');
let $btn = $('.button-modal01');
$btn.attr('disabled', checked);
if (checked) {
$btn.find('i').addClass('ico-add-disabled');
$btn.find('i').removeClass('ico-add');
document.reqForm.todayNone.value = 'Y';
} else {
$btn.find('i').addClass('ico-add');
$btn.find('i').removeClass('ico-add-disabled');
document.reqForm.todayNone.value = 'N';
}
krip.daily.todayNone(ENV.month, ENV.groupNo, 'EXPENSE', checked);
});
let $formWrap = $(bind.form.selectorId);
$formWrap.on('click', function() {
formControl.createModal();
});
// const $btnModal01 = document.querySelector(".button-modal01");
// $btnModal01.addEventListener("click", function() {
// const modal01 = document.querySelector(".modal01").ui;
// modal01.open();
// });
},
let modalControl = {
_bindModelUI() {
etUI.initUI();
const $select2 = document.querySelector('#unitCode');
const selectboxInstance2 = new etUI.components.SelectBox();
selectboxInstance2.core.init($select2, {
@@ -220,50 +167,43 @@
}
});
let $formWrap = $(bind.form.selector).find('form');
$formWrap.on('keyup', 'input[name="price"]', function() {
// TODO : UI disabled
const $formWrap = $(ENV.modal.selector).find('form');
const $price = $(ENV.modal.selector).find('form input[name="price"]');
const $estimatedValue = $(ENV.modal.selector).find('form input[name="estimatedValue"]');
$price.on('keyup', function() {
if ($(this).val() === '') {
$formWrap.find('input[name="estimatedValue"]').attr('disabled', false);
modalControl._priceActive($estimatedValue);
} else {
$formWrap.find('input[name="estimatedValue"]').val('').attr('disabled', true);
modalControl._priceDisabled($estimatedValue);
}
});
$formWrap.on('keyup', 'input[name="estimatedValue"]', function() {
// TODO : UI disabled
$estimatedValue.on('keyup', function() {
if ($(this).val() === '') {
$formWrap.find('input[name="price"]').attr('disabled', false);
modalControl._priceActive($price);
} else {
$formWrap.find('input[name="price"]').val('').attr('disabled', true);
modalControl._priceDisabled($price);
}
});
},
createModal(id) {
if (id === undefined) {
id = 0;
// data set
selectboxInstance2.setValue($formWrap.find('input[name="unitCode"]').val());
if ($price.val() === '' && $estimatedValue.val() !== '') {
modalControl._priceDisabled($price);
} else if ($price.val() !== '' && $estimatedValue.val() === '') {
modalControl._priceDisabled($estimatedValue);
}
ajaxUtil._ajaxAsyncMethod(
ENV.httpUrl.form.replace('{id}', id),
{},
function(rstHtml, status) {
$('.modal01').find('.modal-content').html(rstHtml);
const modal01 = document.querySelector(".modal01").ui;
modal01.open();
formControl._bindModelUI();
},
function(code, rstData) {
kri.logger.error('Do nothing. code: '+ code, rstData);
},
'get',
'html'
);
},
_priceActive($input) {
$input.val('').attr('disabled', false);
$input.parent().parent().closest('.component-input').removeClass('input-disabled');
},
_priceDisabled($input) {
$input.val('').attr('disabled', true);
$input.parent().parent().closest('.component-input').addClass('input-disabled');
},
createVaild() {
formControl.create();
modalControl.create();
},
create() {
const f = document.reqModalForm;
@@ -277,6 +217,7 @@
function (rstData, status) {
console.log('rstData', rstData)
location.reload();
// TODO : next
/*
if (f.todayNone.value === 'Y') {
krip.daily.goToMain();
@@ -287,47 +228,6 @@
},
);
},
removeConfirm(id) {
etUI.dialog.alert({
title: "삭제 안내",
message: "등록하신 내용을 삭제하시겠어요?<br>삭제된 내용은 복구할 수 없습니다.",
type: "confirm",
dialogType: "confirm",
callback: function () {
formControl.remove(id);
},
});
},
remove(id) {
console.log('remove', id)
ajaxUtil._ajaxAsync(
ENV.httpUrl.remove,
{ 'id': id },
function (rstData, status) {
location.reload();
},
);
},
resetConfirm() {
etUI.dialog.alert({
title: "초기화 안내",
message: "등록하신 모든 내용을 삭제하시겠어요?<br>삭제된 내용은 복구할 수 없습니다.",
type: "confirm",
dialogType: "confirm",
callback: function () {
formControl.reset();
},
});
},
reset() {
ajaxUtil._ajaxAsync(
ENV.httpUrl.reset,
{},
function (rstData, status) {
location.reload();
},
);
},
};
</script>
</section>

View File

@@ -3,14 +3,6 @@
xmlns:th="http://www.thymeleaf.org" lang="ko">
<th:block>
<th:block th:if="${@systemProperties['spring.profiles.active'] eq 'local'}">
<div>
reqVO: [[${reqVO}]]
</div>
<div>
detail: [[${dailyRecord}]]
</div>
</th:block>
<div class="modal-content-inner">
<div class="component-btns type-tab"
th:if="${not detail.updated}">
@@ -57,7 +49,7 @@
<span class="select-sub-txt">임산물 수입이 있는 경우, 등록해 주세요.</span>
</div>
<div id="cropCode" class="component-select bottom-sheet" data-props-default="재배형태를 선택해 주세요" data-props-type="bottomSheet">
<input type="hidden1" name="cropCode" th:value="${detail.cropCode}" data-type="select">
<input type="hidden" name="cropCode" th:value="${detail.cropCode}" data-type="select">
<button type="button" class="select-box">
<span class="select-txt"></span>
</button>
@@ -130,7 +122,7 @@
</p>
</div>
<div id="unitCode" class="component-select bottom-sheet" data-props-default="단위를 선택해 주세요" data-props-type="bottomSheet">
<input type="hidden1" name="unitCode" th:value="${detail.unitCode}">
<input type="hidden" name="unitCode" th:value="${detail.unitCode}">
<button type="button" class="select-box">
<span class="select-txt"></span>
</button>
@@ -194,13 +186,12 @@
<div class="component-btns">
<div class="btns-row">
<button type="button" class="btn btn-full btn-l btn-primary" onclick="formControl.createVaild();">
<button type="button" class="btn btn-full btn-l btn-primary" onclick="modalControl.createVaild();">
<span class="btn-txt">등록</span>
</button>
</div>
</div>
</div>
</th:block>
</html>

View File

@@ -3,14 +3,6 @@
xmlns:th="http://www.thymeleaf.org" lang="ko">
<div layout:fragment="content" th:classappend="acco-wrap">
<th:block th:if="${@systemProperties['spring.profiles.active'] eq 'local'}">
<div>
reqVO: [[${reqVO}]]
</div>
<div>
dailyRecord: [[${dailyRecord}]]
</div>
</th:block>
<main id="content" role="main">
<div class="inner">
<hgroup class="tit-group">
@@ -27,9 +19,6 @@
<p>수입 내역을 등록해 주세요.</p>
</hgroup>
<form name="reqForm">
<input type="hidden" name="todayNone" value="N">
</form>
<!--/* 신규 등록 */-->
<th:block th:if="${#lists.isEmpty(incomeList)}">
<button type="button" class="btn btn-m btn-secondary btn-full button-modal01" data-testid="button-modal01"
@@ -41,6 +30,7 @@
<div class="component-input align-center">
<label class="checkbox-inner" id="todayNone">
<input type="checkbox" name="todayNone"
data-type="INCOME"
th:checked="${#strings.equals(dailyRecord.incomeStatus, 'TODAY_NONE')}">
<span class="checkbox-item">
<span class="checkbox-txt">금일 등록내용 없음</span>
@@ -53,7 +43,7 @@
<section class="regist-item-area">
<p class="total">
<span>총 <strong>[[${#lists.size(incomeList)}]]</strong>건</span>
<button type="button" class="btn-reset" onclick="formControl.resetConfirm()">
<button type="button" class="btn-reset" onclick="krip.daily.resetConfirm()">
<i class="ico-reset ico-small" aria-hidden="true"></i>
<span>초기화</span>
</button>
@@ -64,8 +54,8 @@
<div class="item-tit-group">
<p class="item-name">[[${item.categorySelf}]]</p>
<div class="btn-group">
<button type="button" class="delete" th:onclick="formControl.removeConfirm([[${item.id}]])"><span class="hide-txt">삭제</span></button>
<button type="button" class="edit" th:onclick="formControl.createModal([[${item.id}]])"><span class="hide-txt">수정</span></button>
<button type="button" class="delete" th:onclick="krip.daily.removeConfirm([[${item.id}]])"><span class="hide-txt">삭제</span></button>
<button type="button" class="edit" th:onclick="krip.daily.createModal([[${item.id}]])"><span class="hide-txt">수정</span></button>
</div>
</div>
<ul class="detail-list">
@@ -153,64 +143,25 @@
remove: /*[[|/api/record/income/${reqVO.searchMonth}/${reqVO.groupNo}/remove|]]*/'removeUrl',
reset: /*[[|/api/record/income/${reqVO.searchMonth}/${reqVO.groupNo}/reset|]]*/'resetUrl',
},
modal: {
// 등록 버튼
selectorId: '.button-modal01',
// 등록 영역
selector: '.modal01',
},
month: /*[[${reqVO.searchMonth}]]*/'month',
groupNo: /*[[${reqVO.groupNo}]]*/'groupNo',
submitted: false,
};
let bind = {
form: {
selectorId: '.button-modal01',
selector: '.modal01',
},
selectbox: null,
}
let formControl = {
init() {
formControl._bindUI();
//formControl.createModal();
krip.daily.baseBindUI();
},
_bindUI() {
etUI.locales.ko = {
dialog: {
positive: '예',
negative: '아니오',
},
};
};
let $noneWrap = $('#todayNone');
$noneWrap.on('click', 'input[name="todayNone"]', function () {
let checked = $(this).is(':checked');
let $btn = $('.button-modal01');
$btn.attr('disabled', checked);
if (checked) {
$btn.find('i').addClass('ico-add-disabled');
$btn.find('i').removeClass('ico-add');
document.reqForm.todayNone.value = 'Y';
} else {
$btn.find('i').addClass('ico-add');
$btn.find('i').removeClass('ico-add-disabled');
document.reqForm.todayNone.value = 'N';
}
krip.daily.todayNone(ENV.month, ENV.groupNo, 'INCOME', checked);
});
let $formWrap = $(bind.form.selectorId);
$formWrap.on('click', function() {
formControl.createModal();
});
// const $btnModal01 = document.querySelector(".button-modal01");
// $btnModal01.addEventListener("click", function() {
// const modal01 = document.querySelector(".modal01").ui;
// modal01.open();
// });
},
let modalControl = {
_bindModelUI() {
etUI.initUI();
const $select1 = document.querySelector('#cropCode');
const selectboxInstance1 = new etUI.components.SelectBox();
selectboxInstance1.core.init($select1, {
@@ -229,50 +180,44 @@
}
});
const $formWrap = $(bind.form.selector).find('form');
$formWrap.on('keyup', 'input[name="price"]', function() {
// TODO : UI disabled
const $formWrap = $(ENV.modal.selector).find('form');
const $price = $(ENV.modal.selector).find('form input[name="price"]');
const $estimatedValue = $(ENV.modal.selector).find('form input[name="estimatedValue"]');
$price.on('keyup', function() {
if ($(this).val() === '') {
$formWrap.find('input[name="estimatedValue"]').attr('disabled', false);
modalControl._priceActive($estimatedValue);
} else {
$formWrap.find('input[name="estimatedValue"]').val('').attr('disabled', true);
modalControl._priceDisabled($estimatedValue);
}
});
$formWrap.on('keyup', 'input[name="estimatedValue"]', function() {
// TODO : UI disabled
$estimatedValue.on('keyup', function() {
if ($(this).val() === '') {
$formWrap.find('input[name="price"]').attr('disabled', false);
modalControl._priceActive($price);
} else {
$formWrap.find('input[name="price"]').val('').attr('disabled', true);
modalControl._priceDisabled($price);
}
});
},
createModal(id) {
if (id === undefined) {
id = 0;
// data set
selectboxInstance1.setValue($formWrap.find('input[name="cropCode"]').val());
selectboxInstance2.setValue($formWrap.find('input[name="unitCode"]').val());
if ($price.val() === '' && $estimatedValue.val() !== '') {
modalControl._priceDisabled($price);
} else if ($price.val() !== '' && $estimatedValue.val() === '') {
modalControl._priceDisabled($estimatedValue);
}
ajaxUtil._ajaxAsyncMethod(
ENV.httpUrl.form.replace('{id}', id),
{},
function(rstHtml, status) {
$('.modal01').find('.modal-content').html(rstHtml);
const modal01 = document.querySelector(".modal01").ui;
modal01.open();
formControl._bindModelUI();
},
function(code, rstData) {
kri.logger.error('Do nothing. code: '+ code, rstData);
},
'get',
'html'
);
},
_priceActive($input) {
$input.val('').attr('disabled', false);
$input.parent().parent().closest('.component-input').removeClass('input-disabled');
},
_priceDisabled($input) {
$input.val('').attr('disabled', true);
$input.parent().parent().closest('.component-input').addClass('input-disabled');
},
createVaild() {
formControl.create();
modalControl.create();
},
create() {
const f = document.reqModalForm;
@@ -286,6 +231,7 @@
function (rstData, status) {
console.log('rstData', rstData)
location.reload();
// TODO : next
/*
if (f.todayNone.value === 'Y') {
krip.daily.goToMain();
@@ -296,47 +242,6 @@
},
);
},
removeConfirm(id) {
etUI.dialog.alert({
title: "삭제 안내",
message: "등록하신 내용을 삭제하시겠어요?<br>삭제된 내용은 복구할 수 없습니다.",
type: "confirm",
dialogType: "confirm",
callback: function () {
formControl.remove(id);
},
});
},
remove(id) {
console.log('remove', id)
ajaxUtil._ajaxAsync(
ENV.httpUrl.remove,
{ 'id': id },
function (rstData, status) {
location.reload();
},
);
},
resetConfirm() {
etUI.dialog.alert({
title: "초기화 안내",
message: "등록하신 모든 내용을 삭제하시겠어요?<br>삭제된 내용은 복구할 수 없습니다.",
type: "confirm",
dialogType: "confirm",
callback: function () {
formControl.reset();
},
});
},
reset() {
ajaxUtil._ajaxAsync(
ENV.httpUrl.reset,
{},
function (rstData, status) {
location.reload();
},
);
},
};
</script>
</section>