[FO] 일계부 등록 wip
This commit is contained in:
238
front/src/main/resources/static/ui/ajaxUtil.js
Normal file
238
front/src/main/resources/static/ui/ajaxUtil.js
Normal file
@@ -0,0 +1,238 @@
|
||||
var ajaxUtil = {
|
||||
_msg400 : '잘못된 요청입니다.',
|
||||
_msg404 : '',
|
||||
_msg401 : '로그인에 실패했습니다.',
|
||||
_msg403 : '로그인에 실패했습니다.',
|
||||
_msg500 : '오류가 발생하여\n정상 처리되지 않았습니다.',
|
||||
|
||||
$400 : '400',
|
||||
$401 : '401',
|
||||
$403 : '403',
|
||||
$404 : '404',
|
||||
$500 : '500',
|
||||
|
||||
_csrfHeader : $('meta[name="_csrf_header"]').attr('content'),
|
||||
_csrfToken : $('meta[name="_csrf"]').attr('content'),
|
||||
loading : null,
|
||||
loadingStatus:false,
|
||||
|
||||
_init : function(obj){ //에러메시지를 정의 해주어야 한다.
|
||||
ajaxUtil._msg400 = obj._msg400;
|
||||
ajaxUtil._msg404 = obj._msg404;
|
||||
ajaxUtil._msg401 = obj._msg401;
|
||||
ajaxUtil._msg403 = obj._msg403;
|
||||
ajaxUtil._msg500 = obj._msg500;
|
||||
},
|
||||
|
||||
_alertError : function (code) {
|
||||
var message = ajaxUtil._msg500;
|
||||
if (code == '400') {
|
||||
message = ajaxUtil._msg400;
|
||||
}
|
||||
ajaxUtil._alert(message, '오류 안내');
|
||||
},
|
||||
_alert : function (alertMessage, alertTitle, afterEvent) {
|
||||
ajaxUtil._alertMethod({
|
||||
id: null,
|
||||
title: alertTitle !== undefined ? alertTitle : null,
|
||||
message: alertMessage,
|
||||
after: afterEvent !== undefined ? (afterEvent ? 'Y' : 'N') : 'N',
|
||||
});
|
||||
},
|
||||
_alertId : function (alertId, afterEvent) {
|
||||
ajaxUtil._alertMethod({
|
||||
id: alertId,
|
||||
title: null,
|
||||
message: null,
|
||||
after: afterEvent !== undefined ? (afterEvent ? 'Y' : 'N') : 'N',
|
||||
});
|
||||
},
|
||||
_alertMethod : function (jsonObj) {
|
||||
ajaxUtil._ajaxSyncNoWaiting(
|
||||
'/m/common/alert',
|
||||
jsonObj,
|
||||
function(rstData) {
|
||||
var $wrap = $('#bindWrap');
|
||||
if ($wrap.find('.ui-popup-common-alert').length != 0) {
|
||||
$wrap.find('.ui-popup-common-alert').remove();
|
||||
}
|
||||
|
||||
$wrap.append(rstData);
|
||||
uxgFn.popup.bind('.ui-popup-common-alert').open();
|
||||
},
|
||||
function(code, rstData) {
|
||||
research.logger.error('Do nothing. code: '+ code, rstData);
|
||||
},
|
||||
'html');
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* 로딩바가 있는 동기식 방식 처리
|
||||
*/
|
||||
_ajaxSync : function(url, jsonObj, successCallback, errorCallback, dataType) {
|
||||
ajaxUtil._showWaiting();
|
||||
ajaxUtil._ajaxSyncMethod(url, ajaxUtil._jsonStringify(jsonObj), successCallback, errorCallback, 'post', dataType);
|
||||
},
|
||||
/**
|
||||
* 로딩바가 없는 동기식 방식 처리
|
||||
*/
|
||||
_ajaxSyncNoWaiting : function(url, jsonObj, successCallback, errorCallback, dataType) {
|
||||
ajaxUtil._ajaxSyncMethod(url, ajaxUtil._jsonStringify(jsonObj), successCallback, errorCallback, 'post', dataType);
|
||||
},
|
||||
/**
|
||||
* 로딩바가 없는 동기식 방식 처리(MethodType를 지정할 수 있는)
|
||||
*/
|
||||
_ajaxSyncMethod : function(url, jsonObj, successCallback, errorCallback, method, dataType) {
|
||||
ajaxUtil._ajaxMethod(url, jsonObj, successCallback, errorCallback, method, dataType, false);
|
||||
},
|
||||
/**
|
||||
* 로딩바가 있는 비동기식 방식 처리
|
||||
*/
|
||||
_ajaxAsync : function (url, jsonObj, successCallback, errorCallback, dataType) {
|
||||
ajaxUtil._showWaiting();
|
||||
ajaxUtil._ajaxAsyncMethod(url, ajaxUtil._jsonStringify(jsonObj), successCallback, errorCallback, 'post', dataType);
|
||||
},
|
||||
/**
|
||||
* 로딩바가 없는 비동기식 방식 처리
|
||||
*/
|
||||
_ajaxAsyncNoWaiting : function (url, jsonObj, successCallback, errorCallback, dataType) {
|
||||
ajaxUtil._ajaxAsyncMethod(url, ajaxUtil._jsonStringify(jsonObj), successCallback, errorCallback, 'post', dataType);
|
||||
},
|
||||
/**
|
||||
* 로딩바가 없는 비동기식 방식 처리(MethodType를 지정할 수 있는)
|
||||
*/
|
||||
_ajaxAsyncMethod : function (url, jsonObj, successCallback, errorCallback, method, dataType) {
|
||||
ajaxUtil._ajaxMethod(url, jsonObj, successCallback, errorCallback, method, dataType, true);
|
||||
},
|
||||
/**
|
||||
* ajax 공통 처리
|
||||
*/
|
||||
_ajaxMethod : function (url, jsonObj, successCallback, errorCallback, method, dataType, async) {
|
||||
if (typeof ENV != 'undefined' && typeof ENV.submitted == 'boolean') {
|
||||
ENV.submitted = true;
|
||||
}
|
||||
|
||||
$.ajax(
|
||||
{
|
||||
beforeSend : function(xhr) {
|
||||
if (ajaxUtil._csrfHeader != undefined) {
|
||||
xhr.setRequestHeader(ajaxUtil._csrfHeader, ajaxUtil._csrfToken);
|
||||
}
|
||||
},
|
||||
beforeSubmit : '',
|
||||
url : url,
|
||||
type : method != undefined ? method : 'post', // get, post
|
||||
dataType : dataType != undefined ? dataType : 'json', // xml, html, script, json
|
||||
data : jsonObj,
|
||||
contentType : 'application/json; charset=UTF-8',
|
||||
async: async,
|
||||
statusCode : {
|
||||
404:function(rstData){
|
||||
ajaxUtil._hideWaiting();
|
||||
if (typeof errorCallback !== 'undefined') {
|
||||
errorCallback(ajaxUtil.$404, rstData);
|
||||
} else {
|
||||
ajaxUtil._goToMain();
|
||||
}
|
||||
},
|
||||
401:function(){
|
||||
ajaxUtil._goToMain();
|
||||
},
|
||||
403:function(rstData){
|
||||
ajaxUtil._goToMain();
|
||||
},
|
||||
422:function(rstData, status) {
|
||||
alert(422)
|
||||
console.log(rstData)
|
||||
$(rstData.responseJSON).each((idx, oj) => {
|
||||
// TODO : form id? or body
|
||||
let target = $('body').find('[name=' + oj.field + ']');
|
||||
target.addClass('is-invalid');
|
||||
|
||||
target.parent().find('.invalid-feedback').text(oj.defaultMessage);
|
||||
});
|
||||
},
|
||||
500:function(rstData){
|
||||
ajaxUtil._hideWaiting();
|
||||
if (rstData.responseText != '') {
|
||||
let resultJSON = ajaxUtil._jsonParse(rstData.responseText);
|
||||
if (rstData.responseJSON != undefined) {
|
||||
resultJSON = rstData.responseJSON;
|
||||
}
|
||||
|
||||
if (resultJSON.code == 1064) {
|
||||
ajaxUtil._alert(resultJSON.message, '확인');
|
||||
} else if (typeof errorCallback !== 'undefined') {
|
||||
errorCallback(ajaxUtil.$500, rstData);
|
||||
}
|
||||
} else if (typeof errorCallback !== 'undefined') {
|
||||
errorCallback(ajaxUtil.$500, rstData);
|
||||
}
|
||||
}
|
||||
},
|
||||
success : function(rstData, status) {
|
||||
ajaxUtil._hideWaiting();
|
||||
if (typeof successCallback !== 'undefined') {
|
||||
successCallback(rstData, status);
|
||||
}
|
||||
},
|
||||
error : function(rstData) {
|
||||
ajaxUtil._hideWaiting();
|
||||
if (!(rstData.status == 500 || rstData.status == 422)) {
|
||||
if (typeof errorCallback !== 'undefined') {
|
||||
errorCallback(rstData.status, rstData);
|
||||
} else {
|
||||
ajaxUtil._alertError(ajaxUtil._msg500);
|
||||
}
|
||||
}
|
||||
},
|
||||
complete : function(xhr, status, err) {
|
||||
ajaxUtil._hideWaiting();
|
||||
if (typeof ENV != 'undefined' && typeof ENV.submitted == 'boolean') {
|
||||
ENV.submitted = false;
|
||||
}
|
||||
if (typeof commentENV != 'undefined' && typeof commentENV.submitted == 'boolean') {
|
||||
commentENV.submitted = false;
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
_jsonParse : function parse(jsonStr) {
|
||||
try {
|
||||
var jsonObj = JSON.parse(jsonStr);
|
||||
// chamobile.logger.debug(jsonObj);
|
||||
return jsonObj;
|
||||
} catch (error) {
|
||||
console.error("Invalid JSON string:", error);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
_jsonStringify : function stringify(obj) {
|
||||
try {
|
||||
var jsonStr = JSON.stringify(obj);
|
||||
// chamobile.logger.debug(jsonStr);
|
||||
return jsonStr;
|
||||
} catch (error) {
|
||||
console.error("Error stringifying object:", error);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
|
||||
_goToMain:function() {
|
||||
location.href = '/';
|
||||
},
|
||||
_hideWaiting:function(){
|
||||
if (ajaxUtil.loadingStatus) {
|
||||
ajaxUtil.loadingStatus = false;
|
||||
// TODO : 로딩바 숨김
|
||||
}
|
||||
},
|
||||
_showWaiting:function(){
|
||||
ajaxUtil.loadingStatus = true;
|
||||
// TODO : 로딩바 활성화
|
||||
},
|
||||
};
|
||||
33
front/src/main/resources/static/ui/commonUtil.js
Normal file
33
front/src/main/resources/static/ui/commonUtil.js
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
|
||||
var research = {};
|
||||
research.json = new Object();
|
||||
research.logger = new Object();
|
||||
|
||||
/* research.logger */
|
||||
/**
|
||||
* client 오류성 로그 기록용 로거, 로그 레벨에 따라 표시
|
||||
* @param message
|
||||
* @param el
|
||||
*/
|
||||
research.logger.debug = function(message, el){
|
||||
var 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);
|
||||
};
|
||||
|
||||
research.logger.error = function(message, el){
|
||||
var 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);
|
||||
};
|
||||
|
||||
research.logger.info = function(message){
|
||||
var callee = arguments.callee.caller == '' ? arguments.callee.caller.arguments.callee.name : (arguments.callee.caller ? arguments.callee.caller.name : '');
|
||||
console.info("[INFO] caller : " + callee + " / message : " + message);
|
||||
};
|
||||
|
||||
research.logger.warn = function(message){
|
||||
var callee = arguments.callee.caller == '' ? arguments.callee.caller.arguments.callee.name : (arguments.callee.caller ? arguments.callee.caller.name : '');
|
||||
console.warn("[WARN] caller : " + callee + " / message : " + message);
|
||||
};
|
||||
|
||||
|
||||
30
front/src/main/resources/static/ui/page/daily-record.js
Normal file
30
front/src/main/resources/static/ui/page/daily-record.js
Normal file
@@ -0,0 +1,30 @@
|
||||
var page = {};
|
||||
page.daily = new Object();
|
||||
|
||||
page.daily.httpUrl = {
|
||||
root: '/record/calendar',
|
||||
daily: '/record/daily/{searchMonth}/{groupNo}',
|
||||
income: '/record/income/{searchMonth}/{groupNo}',
|
||||
work: '/record/work/{searchMonth}/{groupNo}',
|
||||
expense: '/record/expense/{searchMonth}/{groupNo}',
|
||||
power: '/record/power/{searchMonth}/{groupNo}',
|
||||
forestry: '/record/forestry/{searchMonth}/{groupNo}',
|
||||
}
|
||||
|
||||
page.daily.goToMain = function() {
|
||||
location.href = page.daily.httpUrl.root;
|
||||
}
|
||||
|
||||
page.daily.goToNext = function(target, searchMonth, groupNo) {
|
||||
let url = page.daily.httpUrl.root;
|
||||
|
||||
// TODO URL
|
||||
if (target == 'income') {
|
||||
url = page.daily.httpUrl.income;
|
||||
} else if (target == 'work') {
|
||||
url = page.daily.httpUrl.work;
|
||||
}
|
||||
|
||||
console.log(url.replace('{searchMonth}', searchMonth).replace('{groupNo}', groupNo));
|
||||
//location.href = url.replace('{searchMonth}', searchMonth).replace('{groupNo}', groupNo);
|
||||
}
|
||||
Reference in New Issue
Block a user