let kri = {
isReturn: false,
};
kri.menu = new Object;
kri.logger = new Object();
kri.form = new Object();
/* kri.menu : 스크립트로 페이지 이동 */
/**
* 메인 페이지 이동
*/
kri.menu.main = function() {
location.href = '/';
}
/**
* 로그아웃 팝업 오픈
*/
kri.menu.logout = function() {
etUI.dialog.alert({
title: '로그아웃 확인',
message: '로그아웃 하시겠어요?
서비스를 다시 이용하시려면 로그인이 필요합니다.',
type: 'confirm',
dialogType: 'confirm',
callback: function () {
location.href = '/logout';
},
});
}
/**
* 전체 메뉴 팝업 오픈
*/
kri.menu.open = function() {
ajaxUtil._ajaxAsyncMethod(
'/menu',
{},
function(rstData, status) {
if (rstData != null && rstData.dailyLatest !== undefined && rstData.dailyLatest !== null) {
$('.menuModal').find('.date').html('최근등록 : ' + rstData.dailyLatest + '');
} else {
$('.menuModal').find('.date').html('등록된 일계부가 없습니다.');
}
$('.detail-menu').each(function (index, item) {
if ($(item).find('li').length == 0) {
$(item).hide();
}
});
const menuModal = document.querySelector('.menuModal').ui;
menuModal.open();
},
function(code, rstData) {
kri.logger.error('Do nothing. code: '+ code, rstData);
$('.menuModal').find('.date').hide();
},
'get',
'json'
);
};
/**
* 이용약관 팝업 오픈
*/
kri.menu.terms = function() {
const $modal = $('.commModal');
$modal.addClass('term-wrap');
$modal.find('.modal-tit').text('이용약관');
$modal.find('.modal-content').empty();
ajaxUtil._ajaxAsyncMethod(
'/policy/terms',
{},
function(rstData, status) {
$modal.find('.modal-content').html(rstData);
const commModal = document.querySelector('.commModal').ui;
commModal.open();
},
function(code, rstData) {
kri.logger.error('Do nothing. code: '+ code, rstData);
},
'get',
'html'
);
}
/**
* 개인정보처리방침 팝업 오픈
*/
kri.menu.privacy = function() {
const $modal = $('.commModal');
$modal.addClass('term-wrap');
$modal.find('.modal-tit').text('개인정보처리방침');
$modal.find('.modal-content').empty();
ajaxUtil._ajaxAsyncMethod(
'/policy/privacy',
{},
function(rstData, status) {
$modal.find('.modal-content').html(rstData);
const commModal = document.querySelector('.commModal').ui;
commModal.open();
},
function(code, rstData) {
kri.logger.error('Do nothing. code: '+ code, rstData);
},
'get',
'html'
);
}
/**
* 뒤로가기
*/
kri.menu.goBack = function() {
if (typeof formControl === 'object' && typeof formControl.historyBack === 'function') {
formControl.historyBack();
return;
} else {
history.back();
}
}
/**
* Back Forward Cache로 브라우저가 로딩될 경우 혹은 브라우저 뒤로가기 했을 경우
* document.ready 가 먼저 실행 > window.onpageshow
*/
window.onpageshow = function(event) {
if (event.persisted || (window.performance && window.performance.navigation.type == 2)) {
kri.isReturn = true;
}
// 전체 공통
if (typeof formControl === 'object' && typeof formControl.init === 'function') {
setTimeout(() => {
formControl.init();
}, 500)
}
}
/* kri.logger */
/**
* client 오류성 로그 기록용 로거, 로그 레벨에 따라 표시
* @param message
* @param el
*/
kri.logger.debug = function(message, el){
let callee = arguments.callee.caller == '' ? arguments.callee.caller.arguments.callee.name : (arguments.callee.caller ? arguments.callee.caller.name : '');
console.log("[DEBUG] caller : " + callee + " / message : " + message, el);
};
kri.logger.error = function(message, el){
let callee = arguments.callee.caller == '' ? arguments.callee.caller.arguments.callee.name : (arguments.callee.caller ? arguments.callee.caller.name : '');
console.error("[ERROR] caller : " + callee + " / message : " + message, el);
};
kri.logger.info = function(message){
let callee = arguments.callee.caller == '' ? arguments.callee.caller.arguments.callee.name : (arguments.callee.caller ? arguments.callee.caller.name : '');
console.info("[INFO] caller : " + callee + " / message : " + message);
};
kri.logger.warn = function(message){
let callee = arguments.callee.caller == '' ? arguments.callee.caller.arguments.callee.name : (arguments.callee.caller ? arguments.callee.caller.name : '');
console.warn("[WARN] caller : " + callee + " / message : " + message);
};
kri.form.errorInit = function (formElement) {
if (formElement.length > 0) {
$(formElement).find('.component-input').removeClass('input-invalid');
$(formElement).find('.input-flex-group').removeClass('invalid');
$(formElement).find('.select-group').removeClass('input-invalid');
$(formElement).find('.input-info').each(function () {
$(this).remove();
});
}
};
kri.form.error = function(errorList){
let isResetDone = false;
$(errorList).each((idx, oj) => {
const target = $('[name="' + oj.field + '"]');
let infoBox = null;
if (!isResetDone) {
const formElement = target.closest('form');
if (formElement.length > 0) {
$(formElement).find('.component-input').removeClass('input-invalid');
$(formElement).find('.input-flex-group').removeClass('invalid');
$(formElement).find('.select-group').removeClass('select-invalid');
$(formElement).find('.input-info').each(function () {
$(this).remove();
});
}
isResetDone = true;
}
if (target.length > 0) {
const component = target.closest('.component-input');
if(component){
component.addClass('input-invalid');
//연결된 구조 일 경우 상위에 변경
if(target.closest('.input-flex-group').length > 0){
infoBox = target.closest('.input-flex-group').find('.input-info');
} else {
infoBox = component.find('.input-info');
}
if (infoBox.length === 0) {
if(target.closest('.input-flex-group').length > 0){
infoBox = $('