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, '오류 안내'); ajaxUtil._alert(message, null); }, _alert : function (alertMessage, alertTitle, afterEvent) { if(alertTitle){ etUI.dialog.alert({ title: alertTitle, message: alertMessage, type: "alert", callback: function() { if (typeof afterEvent === 'function') { afterEvent(); } }, }); } else { etUI.dialog.alert({ message: alertMessage, type: "alert", callback: function() { if (typeof afterEvent === 'function') { afterEvent(); } }, }); } }, _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) { kri.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 { // kri.menu.main(); kri.logger.error('statusCode: 404'); } }, 401:function(){ // kri.menu.main(); kri.logger.error('statusCode: 401'); }, 403:function(rstData){ // kri.menu.main(); kri.logger.error('statusCode: 403'); }, 422:function(rstData, status) { console.log(rstData) /** * TODO * 폼이 너무 여러가지 형식이 있는데 서버에러를 가지고 처리하는게 맞는지 검토 필요 * 코드 정리는 나중에 하려고 그냥 만듬.... 정리 필요. */ let isResetDone = false; $(rstData.responseJSON.fieldErrors).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('input-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 = $('