148 lines
5.0 KiB
JavaScript
148 lines
5.0 KiB
JavaScript
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.daily = function() {
|
|
location.href = '/record/calendar';
|
|
}
|
|
kri.menu.my = function() {
|
|
location.href = '/info';
|
|
}
|
|
|
|
/**
|
|
* 뒤로가기
|
|
*/
|
|
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('select-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 = $('<ul class="input-info"></ul>').appendTo(target.closest('.input-flex-group'));
|
|
target.closest('.input-flex-group').addClass('invalid');
|
|
} else {
|
|
infoBox = $('<ul class="input-info"></ul>').appendTo(component);
|
|
}
|
|
}
|
|
infoBox.html('<li>' + oj.message + '</li>');
|
|
}
|
|
}
|
|
|
|
if (target.data('type') === 'select') {
|
|
|
|
const component = target.closest('.select-group');
|
|
if (component) {
|
|
component.addClass('select-invalid');
|
|
|
|
infoBox = component.find('.input-info');
|
|
if (infoBox.length === 0) {
|
|
infoBox = $('<ul class="input-info"></ul>').appendTo(component);
|
|
}
|
|
|
|
infoBox.html('<li>' + oj.message + '</li>');
|
|
}
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
|