fix: ajax call 공통처리

main
Jonguk. Lim 2 years ago
parent bbf3f49240
commit fbdbc8f089

@ -7,5 +7,5 @@ import org.apache.ibatis.session.RowBounds;
public interface Ec0100Service {
List<Map<String, Object>> findEc0100List(Map<String, Object> paramMap, RowBounds pagingInfo);
Map<String, Object> findEc0100();
Map<String, Object> findEc0100(String keyField);
}

@ -21,7 +21,7 @@ public class Ec0100ServiceImpl implements Ec0100Service {
}
@Override
public Map<String, Object> findEc0100() {
public Map<String, Object> findEc0100(String keyField) {
return mapper.selectEc0100();
}
}

@ -4,13 +4,20 @@ import java.util.Map;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import kr.xit.fims.biz.cmm.FimsConst;
import kr.xit.fims.biz.ec.service.Ec0100Service;
import kr.xit.framework.biz.mng.menu.model.ProgramMngVO;
import kr.xit.framework.core.constants.FrameworkConstants;
import kr.xit.framework.core.model.ResultResponse;
import kr.xit.framework.support.mybatis.MybatisUtils;
import kr.xit.framework.support.util.AjaxMessageMapRenderer;
import kr.xit.framework.support.util.Checks;
import kr.xit.framework.support.util.constants.MessageKey;
import lombok.AllArgsConstructor;
@AllArgsConstructor
@ -24,13 +31,54 @@ public class Ec0100Controler {
}
@GetMapping(value = "/ec0100Popup")
public ModelAndView ec0100Popup(@RequestParam(required = false) String keyField) {
ModelAndView mav = new ModelAndView();
mav.setViewName(FimsConst.FIMS_JSP_BASE_PATH +"ec/ec0100Popup.popup");
if(Checks.isEmpty(keyField)) mav.addObject("", new ProgramMngVO());
else mav.addObject("", service.findEc0100(keyField));
return mav;
}
@GetMapping(value = "/findEc0100List")
public ModelAndView findEc0100List(@RequestParam Map<String,Object> paramMap){
return ResultResponse.of(service.findEc0100List(paramMap, MybatisUtils.getPagingInfo(paramMap)));
}
@GetMapping(value = "/findEc0100")
public ModelAndView findEc0100(){
return ResultResponse.of(service.findEc0100());
public ModelAndView findEc0100(String key){
return ResultResponse.of(service.findEc0100(key));
}
@PostMapping(value = "/addEc0100")
public ModelAndView addEc0100(@RequestParam Map<String, Object> paramMap){
ModelAndView mav = new ModelAndView(FrameworkConstants.JSON_VIEW);
// 서비스 호출
AjaxMessageMapRenderer.success(mav, MessageKey.CMM_INSERT_SUCCESS);
return mav;
}
@PostMapping(value = "/modifyEc0100")
public ModelAndView modifyEc0100(@RequestParam Map<String, Object> paramMap){
ModelAndView mav = new ModelAndView(FrameworkConstants.JSON_VIEW);
// 서비스 호출
AjaxMessageMapRenderer.success(mav, MessageKey.CMM_UPDATE_SUCCESS);
return mav;
}
@PostMapping(value = "/removeEc0100")
public ModelAndView removeEc0100(@RequestParam String key){
ModelAndView mav = new ModelAndView(FrameworkConstants.JSON_VIEW);
// 서비스 호출
AjaxMessageMapRenderer.success(mav, MessageKey.CMM_INSERT_SUCCESS);
return mav;
}
}

@ -669,52 +669,37 @@
* 데이터 등록
======================== */
addData : function(){
var param = $("#frmSearch").serialize();
$.ajax({
url : "/adm/send/rqst/mng/proc.do",
data : param,
type : "POST",
dataType : "json",
success : function(data) {
},
error: function(){
fnAjax(
'post',
'<c:url value="/adm/send/rqst/mng/proc.do"/>',
$("#frmSearch").serialize(),
() => {
}
});
);
},
/* ========================
* 데이터 수정
======================== */
modifyData : function(){
var param = $("#frmSearch").serialize();
$.ajax({
url : "/adm/send/rqst/mng/proc.do",
data : param,
type : "PUT",
dataType : "json",
success : function(data) {
},
error: function(){
fnAjax(
'post',
'<c:url value="/adm/send/rqst/mng/proc.do"/>',
$("#frmSearch").serialize(),
() => {
}
});
);
},
/* ========================
* 데이터 삭제
======================== */
removeData : function(){
var param = $("#frmSearch").serialize();
$.ajax({
url : "/adm/send/rqst/mng/proc.do",
data : param,
type : "DELETE",
dataType : "json",
success : function(data) {
},
error: function(){
fnAjax(
'post',
'<c:url value="/adm/send/rqst/mng/proc.do"/>',
$("#frmSearch").serialize(),
() => {
}
});
);
},
/* ========================
* 유효성 검증

@ -0,0 +1,197 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="ui" uri="http://egovframework.gov/ctl/ui"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<style type="text/css">
h1 {font-size:12px;}
caption {visibility:hidden; font-size:0; height:0; margin:0; padding:0; line-height:0;}
</style>
<form name="frmSearch" id="frmSearch">
<div class="search r2">
<table>
<caption>검색조건</caption>
<colgroup>
<col style="width: 15%">
<col style="width: 20%;">
<col style="width: 8%;">
<col>
<col style="width: 8%;">
<col>
<col style="width: 7%;">
</colgroup>
<tbody>
<th>프로그램 한글명</th>
<td>
<input name="searchKeyword" id="searchKeyword" type="text" size="60" value="<c:out value='${searchKeyword}'/>" maxlength="60" title="검색조건">
</td>
<td colspan="6">
<input type="button" id="btnSearch" class="btn_search" title="검색" value="검색" />
</td>
</tbody>
</table>
</div>
</form>
<!-- //검색 -->
<!-- 페이지 Open 방식에 따라 버튼 표출 분기(일반페이지 or 팝업페이지) -->
<c:choose>
<c:when test="${param.tilesDef == 'popup'}">
</c:when>
<c:otherwise>
<div class="page_btn">
<span class="flr">
<a href="#" class="btn darkgray" id="btnRegist" title="등록" onClick="mngProgramMgtForm.addProgram()">등록</a>
</span>
</div>
<!-- //버튼 및 페이지정보 -->
</c:otherwise>
</c:choose>
<!-- 데이터 출력 -->
<div id="grid_t0"></div>
<script type="text/javaScript" language="javascript">
let GRID = null;
/* ========================
* 데이터 조회 : popup에서 사용
======================== */
var findEc0100List = function(){
GRID.reloadData();
};
/* ========================
* 상세 팝업 오픈 버튼 클릭
-상세 팝업을 OPEN 한다.
======================== */
const fnClickProgramBtn = (props) => {
const rowData = props.grid.getRow(props.rowKey);
CmmPopup.open(
'<c:url value="/fims/biz/ec/ec0100Popup.do"/>'
, {
progrmFileNm: rowData.progrmFileNm
}
, {
width: 720
, height: 655
}
, '프로그램 상세'
)
};
const init = () => {
const gridColumns = [ //Grid 컬럼 정보(명칭,매핑 field, 기타옵션 등)
{
header: '프로그램 파일명',
name: 'progrmFileNm',
minWidth: 200,
sortable: true,
sortingType: 'desc',
align: 'left',
<!-- 페이지 Open 방식에 따라 버튼 표출 분기(일반페이지 or 팝업페이지) -->
<c:if test="${param.tilesDef != 'popup'}">
renderer: {
type: CustomButtonRenderer,
options: {
formatter : (props) => ({
formatter : props.grid.getRow(props.rowKey).progrmFileNm
, element: "text"
})
, eventFunction: this.fnClickProgramBtn //function(){alert("1234")}
, eventType : "click"
}
}
</c:if>
},
{
header: '프로그램 한글명',
name: 'progrmKoreanNm',
minWidth: 200,
sortable: false,
align: 'left'
},
{
header: 'URL',
name: 'url',
minWidth: 300,
sortable: true,
align: 'left'
},
{
header: '프로그램 설명',
name: 'progrmDc',
width: 150,
sortable: false,
align: 'left'
}
];
const gridDatasource = { //DataSource
/* -----------------------
* DataSource API Setting
----------------------- */
//initialRequest: true, // 화면 load시 조회 안함 - default
api: {
readData: {
url: '<c:url value="/fims/biz/ec/findEc0100List.do"/>'
, method: 'get'
, serializer: (params) => {
return fnAddPageInfo(document.frmSearch, params);
}
}
}
}
const gridOptions = {
el: 'grid_t0',
rowHeaders: ['rowNum'],
columns: gridColumns,
columnOptions: {
frozenCount: 1 //고정컬럼 갯수
, minWidth: 80 //최소 사이즈
}
};
GRID = TuiGrid.of(gridOptions, gridDatasource, (res) => {
console.log('Grid~~~~~~~~~');
});
/* ******************************
* Grid end
****************************** */
/** ******************************
* Event 정의
* ******************************/
$('#btnSearch').on('click', () => {
GRID.reloadData();
//GRID.refreshLayout();
});
};
/* ========================
* 데이터 등록
======================== */
const addProgram = () => {
CmmPopup.open(
'<c:url value="/fims/biz/ec/ec0100Popup.do"/>'
, null
, {
width: 720
, height: 655
}
, 'EC ㄷㅡㅇ록'
)
};
// initialize
$(document).ready(function(){
init();
});
</script>

@ -0,0 +1,154 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="ui" uri="http://egovframework.gov/ctl/ui"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="validator" uri="http://www.springmodules.org/tags/commons-validator" %>
<form id="frmEc0100">
<div class="popup" style="min-width: 700px;">
<div class="popup_inner" style="max-width:700px;">
<p class="pop_title"> 프로그램 상세조회 /수정</p>
<table class="tbl03">
<caption>프로그램 상세조회 /수정</caption>
<colgroup>
<col style="width: 20%; height: 23px;">
<col style="width: 80%; height: 23px;">
</colgroup>
<tbody>
<tr>
<th scope="row" class="required"><label for="progrmFileNm">프로그램파일명</label>
<td nowrap="nowrap">
<c:choose>
<c:when test="${!empty progrmMngVO.progrmFileNm and fn:length(progrmMngVO.progrmFileNm) > 0}">
<input type="text" id='progrmFileNm' name='progrmFileNm' disabled="disabled" value="<c:out value='${progrmMngVO.progrmFileNm}'/>">
</c:when>
<c:otherwise>
<input type="text" id='progrmFileNm' name='progrmFileNm' value="<c:out value='${progrmMngVO.progrmFileNm}'/>">
</c:otherwise>
</c:choose>
<form:input path="progrmFileNm" size="50" maxlength="50" title="프로그램파일명" cssStyle="display:none" />
<form:errors path="progrmFileNm"/>
</td>
</tr>
<tr>
<th class="required" scope="row"><label for="progrmStrePath">저장경로</label>
<td nowrap="nowrap">
<form:input path="progrmStrePath" size="50" maxlength="50" title="저장경로" disabled="disabled"/>
<form:errors path="progrmStrePath"/>
</td>
</tr>
<tr>
<th class="required" scope="row"><label for="progrmKoreanNm">프로그램 한글명</label>
<td nowrap="nowrap">
<form:input path="progrmKoreanNm" size="60" maxlength="50" title="프로그램 한글명"/>
<form:errors path="progrmKoreanNm" />
</td>
</tr>
<tr>
<th class="required" scope="row"><label for="URL">URL</label>
<td nowrap="nowrap">
<form:input path="URL" size="100" maxlength="100" title="URL" />
<form:errors path="URL" />
</td>
</tr>
<tr>
<th class="required" scope="row"><label for="progrmDc">프로그램설명</label></th>
<td>
<form:textarea path="progrmDc" rows="14" cols="75" title="프로그램설명"/>
<form:errors path="progrmDc"/>
</td>
</tr>
</tbody>
</table>
<div class="popup_btn">
<span class="flr" colspan="4">
<c:choose>
<c:when test="${!empty progrmMngVO.progrmFileNm and fn:length(progrmMngVO.progrmFileNm) > 0}">
<a href="#LINK" class="btn blue" id="btnUpdate" onclick="mngProgramMgtPopup.modifyProgram()">변경</a>
<a href="#LINK" class="btn red" id="btnDelete" onclick="mngProgramMgtPopup.removeProgram()">삭제</a>
</c:when>
<c:otherwise>
<a href="#LINK" class="btn blue" id="btnUpdate" onClick="mngProgramMgtPopup.addProgram()">등록</a>
</c:otherwise>
</c:choose>
<a href="#" class="btn lightgray" id="btnClose" onclick="window.close()">닫기</a>
</span>
</div>
<!-- //등록버튼 -->
</div>
</div>
<!-- //popup -->
</form:form>
<script type="text/javaScript" language="javascript">
const init = () => {
//닫기 버튼 Event
$("#btnClose").click(function() {
window.close();
});
$(".popup").css("position","absolute");
$(".content_header").css("display","none");
$("#cur_loc").css("display","none");
};
const addEc0100 = () => {
//유효성 체크
//if(!validateProgrmMngVO(document.getElementById("progrmMngVO")))
// return;
const varFrom = document.getElementById("frmEc0100");
if(confirm("저장 하시겠습니까?")){
fnAjax(
'post',
'/fims/biz/ec/addEc0100.do',
$(varFrom).serialize(),
() => {
window.opener.findEc0100List();
window.close();
}
);
}
};
const modifyEc0100 = () => {
//if(!validateProgrmMngVO(document.getElementById("progrmMngVO")))
// return;
const varFrom = document.getElementById("frmEc0100");
if(confirm("변경 하시겠습니까?")){
fnAjax(
'post',
'<c:url value="/fims/biz/ec/modifyEc0100.do"/>',
$(varFrom).serialize(),
() => {
window.opener.findEc0100List();
window.close();
}
);
}
};
const removeEc0100 = () => {
if(confirm("삭제 하시겠습니까?")){
fnAjax(
'post',
'<c:url value="fims/biz/ec/modifyEc0100.do"/>',
{},
() => {
window.opener.findEc0100List();
window.close();
}
);
}
};
$(document).ready(function(){
mngProgramMgtPopup.init();
});
</script>

@ -408,49 +408,33 @@
addData: function(){
var param = $("#frmSearch").serialize();
$.ajax({
url : "/adm/send/rqst/mng/proc.do",
data : param,
type : "POST",
dataType : "json",
success : function(data) {
},
error: function(){
fnAjax(
'post',
'<c:url value="/adm/send/rqst/mng/proc.do"/>',
$("#frmSearch").serialize(),
() => {
}
});
);
},
modifyData: function(){
var param = $("#frmSearch").serialize();
$.ajax({
url : "/adm/send/rqst/mng/proc.do",
data : param,
type : "PUT",
dataType : "json",
success : function(data) {
ARR_INSTANCE[CUR_TAB_SEQ].resetData(data);
},
error: function(){
fnAjax(
'post',
'<c:url value="/adm/send/rqst/mng/proc.do"/>',
$("#frmSearch").serialize(),
() => {
}
});
);
},
removeData: function(){
var param = $("#frmSearch").serialize();
$.ajax({
url : "/adm/send/rqst/mng/proc.do",
data : param,
type : "DELETE",
dataType : "json",
success : function(data) {
},
error: function(){
fnAjax(
'post',
'<c:url value="/adm/send/rqst/mng/proc.do"/>',
$("#frmSearch").serialize(),
() => {
}
});
);
},
validate: function(flag){

@ -109,24 +109,18 @@
addProgram : function(){
if(!validateProgrmMngVO(document.getElementById("progrmMngVO")))
return;
;
var varFrom = document.getElementById("progrmMngVO");
if(confirm("저장 하시겠습니까?")){
var param = $(varFrom).serialize();
$.ajax({
url : "<c:url value='/'/>framework/biz/mng/menu/addProgram.do",
data : param,
type : "post",
dataType : "json",
success : function(data) {
alert(data.message);
fnAjax(
'post',
'<c:url value="/framework/biz/mng/menu/addProgram.do"/>',
$(varFrom).serialize(),
() => {
window.opener.findPrograms();
window.close();
},
error: function(){
}
});
);
}
}
/* ========================
@ -138,42 +132,31 @@
var varFrom = document.getElementById("progrmMngVO");
if(confirm("변경 하시겠습니까?")){
var param = $(varFrom).serialize();
$.ajax({
url : "<c:url value='/'/>framework/biz/mng/menu/modifyProgram.do",
data : param,
type : "post",
dataType : "json",
success : function(data) {
alert(data.message);
fnAjax(
'post',
'<c:url value="framework/biz/mng/menu/modifyProgram.do"/>',
$(varFrom).serialize(),
() => {
window.opener.findPrograms();
window.close();
}
});
);
}
}
/* ========================
* 데이터 삭제
======================== */
,removeProgram : function(){
var varFrom = document.getElementById("progrmMngVO");
if(confirm("삭제 하시겠습니까?")){
var param = $(varFrom).serialize();
$.ajax({
url : "<c:url value='/'/>framework/biz/mng/menu/removeProgram.do",
data : {progrmFileNm: $('#progrmFileNm').val()},
type : "post",
dataType : "json",
success : function(data) {
alert(data.message);
console.log(data)
window.opener.findPrograms();//.mngProgramMgtForm.findData();
fnAjax(
'post',
'<c:url value="/framework/biz/mng/menu/removeProgram.do"/>',
{ progrmFileNm: $('#progrmFileNm').val() },
() => {
window.opener.findPrograms();
window.close();
},
error: function(){
}
});
);
}
}
}

@ -454,3 +454,25 @@ function toStringByFormatting(source, delimiter = '-') {
return [year, month, day].join(delimiter);
}
/**
*
* @param {String} method POST / GET
* @param {String} url
* @param {Object} data
* @param {Function} callback
*/
const fnAjax = (method, url, data, callback) => {
$.ajax({
url: url,
data: data,
type: method,
dataType: "json",
success: function (data) {
alert(data.message);
if (callback) callback()
},
error: function () {
}
})
};

Loading…
Cancel
Save