<%--
  - FileName   : CommCodeDescList.jsp
  - Author     : gyeongmo an
  - Date       : 2014.08.01
  - Copyright  : Copyright (c) 2014 www.udapsoft.co.kr, Inc.
  - All rights reserved.
  - Description: 기준코드 등록
--%>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="com.udapsoft.waf.system.HandlerStorage" %>
<%@ page import="com.udapsoft.waf.common.ui.*" %>
<%@ page import="kr.co.udapsoft.common.code.*" %>
<%@ page import="kr.co.hsnc.common.util.*"%>
<%@ page import="kr.co.hsnc.common.sql.*" %>
<%@ include file="/jsp/work/taglib.jsp" %>
<jsp:useBean id="ctx" class="com.udapsoft.waf.system.context.SessionContext" scope="session" />
<%
	ctx.init(request, response);
	HandlerStorage storage = ctx.getHandlerStorage();
	
	ValueObject params = storage.getParams();
	ValueObject user = storage.getUser();
    String fevent = storage.getEvent();
%>
<SCRIPT language="JavaScript" src="/js/menu.js"></SCRIPT>
<SCRIPT language="JavaScript">
/*예약함수*/
var sheet1;
var sheet1Row;
var sheet1PageNo = 1;
var pageLastRowIndex = 1;
var validationResult = false;
var filterShow = false;

function _onReady(){
	gridInit(sheet1);
	
	jQuery("#btnSave").click(function() {
		if(confirm("저장하시겠습니까?")) {
			for(var i=sheet1.LastRow(); i>=1; i--) {
				if(sheet1.GetCellValue(i, "STATUS2") == "D") {
					sheet1.SetCellValue(i, "STATUS", "D");
				}
			}
			
			jQuery("#fevent").val("SAVE_DESC");
			var url = Modular.model.PageContext.CONTEXT_ROOT + "/sycs/code/CommCodeDescList_sheet.screen";
			var result = Modular.view.IBSheet7.doSave(sheet1, url, jQuery("#form1"), false);	
		}
		
	});
	
	jQuery("#btnClose").click(function() {
		setTimeout(function(){
			parent.searchCommCodeDescList();
 		},100);
	});

    doSearch();
}

function searchCommCodeDescList(){
	fLayerPopClose('_searchCommCodeDescList');
}

function gridInit(sheetName){
		var init_sheet = {};
		init_sheet.Cfg = {SearchMode:2, Page:10};
		init_sheet.Cols = [
		       			{Header:'삭제',				Type:"CheckBox",		SaveName:"DEL_CHECK", 		Width:45, 	Align:"Center"},
		    			{Header:'순번',			Type:"Seq", 			SaveName:"NO", 			Width:25, 	Align:"Center"},
		    			{Header:'상태',				Type:"Status", 			SaveName:"STATUS",				Width:0, 	Align:"Center", Hidden:"True"},
		    			{Header:'상태2',				Type:"Text", 			SaveName:"STATUS2",				Width:0, 	Align:"Center", Hidden:"True"},
		    			{Header:'테이블명',		Type:"Text", 			SaveName:"TABLE_NM", 		Width:150,	Align:"Left",	Hidden:"True", EditLen:50},
		    			{Header:'기준코드',			Type:"Text", 			SaveName:"BASE_CD", 		Width:150, 	Align:"Left",	Hidden:"True", EditLen:50},
		    			{Header:'컬럼영문명',			Type:"Text", 			SaveName:"COL_ENG", 		Width:100, 	Align:"Center", EditLen:50, Edit:"false"},
		    			{Header:'컬럼설명',		Type:"Text",	 		SaveName:"COL_KOR", 		Width:100, 	Align:"Center", EditLen:100},
		    			{Header:'',		Type:"Text", 			SaveName:"CODE_ID", 		Width:80, 	Align:"Left",	Hidden:"True"},
		    			{Header:'',		Type:"Text", 			SaveName:"CRE_DATE", 		Width:80, 	Align:"Left",	Hidden:"True"},
		    			{Header:'ID',		Type:"Text", 			SaveName:"CRE_BY", 		Width:80, 	Align:"Left",	Hidden:"True"},
		    			{Header:'참조',		Type:"Text", 			SaveName:"COL_DESC", 		Width:300, 	Align:"Left", EditLen:2000}
		];

		init_sheet.HeaderMode = {Sort:1};
		IBS_InitSheet(sheetName, init_sheet);
		sheetName.SetDataAutoTrim(0);
		//sheetName.SetEditable(false);
		
		setGridSize();
}


function sheet1_OnSearchEnd(code, message) {
    if(code == 0) {

    	var rownum = sheet1.GetTotalRows();
   	 
    	var col_temp = "DETAILCD|DETAILNM|DETAILSORTNM|CHG_CODE01|CHG_CODE02|CHG_CODE03|CHG_CODE04|CHG_CODE05|"+
		"CHG_CODE06|CHG_CODE07|CHG_CODE08|CHG_CODE09|CHG_CODE10|CHG_CODE11|CHG_CODE12|CHG_CODE13|CHG_CODE14|CHG_CODE15|CHG_CODE16|CHG_CODE17|"+
		"CHG_CODE18|CHG_CODE19|CHG_CODE20|REMARK";
   	 
   	 var col_text_temp = "내역코드|내역코드명|약어명|변환코드01|변환코드02|변환코드03|변환코드04|변환코드05|변환코드06|변환코드07"+
		"|변환코드08|변환코드09|변환코드10|변환코드11|변환코드12|변환코드13|변환코드14|변환코드15|변환코드16|변환코드17|변환코드18|변환코드19|변환코드20"+
		"|REMARK|기준코드";
   	 
   	 var colNames = col_temp.split("|");
   	 var colTexts = col_text_temp.split("|");
   	 var isExist  = false;
   	 
   	 var sheetNameValue   = new Array(rownum);
   	 var sheetTextValue   = new Array(rownum);
   	 var sheetCodeIdValue = new Array(rownum);
   	 var sheetDescValue   = new Array(rownum);
   	 
   	 var j=0;
   	 for(var k = sheet1.HeaderRows(); k < sheet1.GetTotalRows()+sheet1.HeaderRows(); k++ ){
   	                  sheetNameValue[sheet1.GetCellValue(k, "COL_ENG")]   =   sheet1.GetCellValue(k, "COL_ENG");
   	                  sheetTextValue[sheet1.GetCellValue(k, "COL_ENG")]   =   sheet1.GetCellValue(k, "COL_KOR");
   	                  sheetCodeIdValue[sheet1.GetCellValue(k, "COL_ENG")] =   sheet1.GetCellValue(k, "CODE_ID");
   	                  sheetDescValue[sheet1.GetCellValue(k, "COL_ENG")]   =   sheet1.GetCellValue(k, "COL_DESC");
   	 }
   	 sheet1.RemoveAll();  // DB의 데이터순이아닌 파라미터로 넘어오는 col 순서로 재조정
   	 
   	 for (var i=0; i<colNames.length; i++){
   			       var Row = sheet1.DataInsert(-1);
   			       sheet1.SetCellValue(Row, "TABLE_NM", "<%= params.get("p_table_nm") %>");
   			       sheet1.SetCellValue(Row, "BASE_CD", "<%= params.get("p_base_cd") %>");
   			       
   			       if( sheetNameValue[colNames[i]] !="" && sheetNameValue[colNames[i]] !=undefined){
   			          sheet1.SetCellValue(Row, "COL_ENG", sheetNameValue[colNames[i]]);
   			          sheet1.SetRowBackColor(Row, "#eeecff");
   			       }else{
   			         sheet1.SetCellValue(Row, "COL_ENG", colNames[i]);
   			       }

   			       if(sheetTextValue[colNames[i]] !="" && sheetTextValue[colNames[i]] !=undefined){
   			         sheet1.SetCellValue(Row, "COL_KOR", sheetTextValue[colNames[i]]);
   			       }else{
   			         sheet1.SetCellValue(Row, "COL_KOR", colTexts[i]);
   			       }
   			       
   			        if(sheetCodeIdValue[colNames[i]] !="" && sheetCodeIdValue[colNames[i]] !=undefined ){
   			          sheet1.SetCellValue(Row, "CODE_ID", sheetCodeIdValue[colNames[i]]);
   			       }
   			       
   			       if(sheetDescValue[colNames[i]] !="" && sheetDescValue[colNames[i]] !=undefined ){
   			          sheet1.SetCellValue(Row, "COL_DESC", sheetDescValue[colNames[i]]);
   			       }

   			    	sheet1.SetCellValue(Row, "STATUS", "");
   			    
   			    
   	 }
   	setGridSize();
    	
	} else {
		//조회 에러 수행
		//alert(message);
		alert("조회 실패");
	}
}

function sheet1_OnSaveEnd(code, msg) {
    if(code >= 0) {
    	alert("저장하였습니다.");
    	doSearch();
    } else {
    	alert("저장실패");
    }
}

function sheet1_OnClick(Row, Col, Value, CellX, CellY, CellW, CellH) {
	
	if(sheet1.ColSaveName(0, Col) == "DEL_CHECK") {
		if(sheet1.GetCellValue(Row, "DEL_CHECK") == 0) {
			sheet1.SetCellValue(Row, "STATUS2", "");
			sheet1.SetCellEditable(Row, "COL_ENG", true);
			sheet1.SetCellEditable(Row, "COL_KOR", true);
			sheet1.SetCellEditable(Row, "COL_DESC", true);
			
		} else if(sheet1.GetCellValue(Row, "DEL_CHECK") == 1) {
			sheet1.SetCellValue(Row, "STATUS2", "D");
			sheet1.SetCellEditable(Row, "COL_ENG", false);
			sheet1.SetCellEditable(Row, "COL_KOR", false);
			sheet1.SetCellEditable(Row, "COL_DESC", false);
		}
	}
}


function sheet1_OnCheckAllEnd(Col, Value) {
	var deleteYn = "";
	var editYn = "";
	if(Value == 1) {
		deleteYn = "D";
		editYn = false;
	} else {
		deleteYn = "";
		editYn = true;
	}
	for(var i=sheet1.LastRow(); i>=1; i--) {
		sheet1.SetCellValue(i, "STATUS2", deleteYn);
		sheet1.SetCellEditable(i, "COL_ENG", editYn);
		sheet1.SetCellEditable(i, "COL_KOR", editYn);
		sheet1.SetCellEditable(i, "COL_DESC", editYn);
	}

}


/**
 *	IBSheet size setting
 */
function setGridSize() {
	sheet1.FitColWidth();
}

	// 검색
	function doSearch(sheetObj) {
		jQuery("#fevent").val("GET_DESC");
		var url = Modular.model.PageContext.CONTEXT_ROOT + "/sycs/code/CommCodeDescList_sheet.screen";
		Modular.view.IBSheet7.doSearch(sheet1, url, jQuery("#form1"), 10, "");
	}
</SCRIPT>

<modular:search id="form1">
	<modular:key id="fevent" />
</modular:search>

<form id="form1" name="form1" method="post" modular:type="search">
<INPUT type="hidden" name="fevent" id="fevent" value="">
	<!-- 검색조건 시작 -->
	<table id="search-table" class="search-form-table">
		<colgroup>
			<col width="100" />
			<col width="200" />
			<col width="100" />
			<col width="*" />
			<col width="200" />
		</colgroup>
		<tr>
			<th>테이블명</th>
			<td>
				<INPUT type="text" name='p_table_nm' class="input" READONLY value="<%= params.get("p_table_nm") %>" style="width:90%"> 
			</td>
			<th>기준코드</th>
			<td>
				<INPUT type="text" name='p_base_cd' class="input" READONLY value="<%= params.get("p_base_cd") %>" style="width:90%"> 
			</td>
			<td class="button">
				<span class="btnSearch center"><a href="javascript:void(0);" id="btnSave">저장</a></span>
				<span class="btnSearch center"><a href="javascript:void(0);" id="btnClose">닫기</a></span>
			</td>
		</tr>
	</table>
	<!-- 검색조건 종료 -->
	<div id="sheet1_div" style="padding-top:5px; height: auto; min-height: 330px; overflow: auto;">
		<script>createIBSheet('sheet1','100%', '330px');</script>
	</div>
	<table width="100%">
		<tr>
			<TD height="5">※ 설정이 된 항목은  <font color="red">열의 바탕색이   있습니다. </font> </TD>
		</tr>
	</table>
</FORM>