  <%--
  - FileName   : QuotPjtCodeList.jsp
  - Author     : hoonseok choi
  - Date       : 2023.01.10
  - Copyright  : Copyright (c) www.udapsoft.co.kr, Inc.
  - All rights reserved.
--%>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="com.udapsoft.waf.system.HandlerStorage" %>
<%@ page import="kr.co.hsnc.common.util.ValueObject"%>
<%@ include file="/jsp/work/taglib.jsp" %>
<jsp:useBean id="ctx" class="com.udapsoft.waf.system.context.SessionContext" scope="session" />
<%
 	ctx.init(request, response);
 	ValueObject user    = ctx.getUser();
 	String USER_ID = user.get("ACCT_ID");
 
 	HandlerStorage storage = ctx.getHandlerStorage(); 
 	String url = request.getRequestURL().toString();
 	url = url.substring(0, url.indexOf("/",7));
 
 	//본부구분 코드 가져오기
 	String hq_gubun = (String) storage.getObject("selectHqText");
	String hq_gubun_code = (String) storage.getObject("selectHqValue");
	System.out.println("hq_gubun : "+hq_gubun);
	System.out.println("hq_gubun_code : "+hq_gubun_code);
	hq_gubun = hq_gubun.substring(0, hq_gubun.lastIndexOf("|"));
	hq_gubun_code = hq_gubun_code.substring(0, hq_gubun_code.lastIndexOf("|"));
%>

<SCRIPT language="JavaScript">
/*예약함수*/
var sheet1;
var sheet1Row;
var sheet1PageNo = 1;
var pageLastRowIndex = 1;
var validationResult = false;
var filterShow = false;
function _onReady(){
	gridInit(sheet1);

	jQuery("#btnSearch").click(function() {
		var f = document.form1;
	    f.isSubmit = false;
		jQuery("#fevent").val("GET_DEPT_LIST");
		var url = Modular.model.PageContext.CONTEXT_ROOT + "/quot/outside/getDept_sheet.screen";
		Modular.view.IBSheet7.doSearch(sheet1, url, jQuery("#form1"), 10, "");
	});
	
	jQuery("#btnAdd").click(function() {
		var rowIdx = sheet1.DataInsert(-1);
		sheet1.SetCellValue(rowIdx,"BASECD","QUOT_DEPT");
	});
	
	jQuery("#btnSave").click(function() {
		if (confirm("저장하시겠습니까?")) {
			jQuery("#fevent").val("SAVE_DEPT_LIST");
			var url = Modular.model.PageContext.CONTEXT_ROOT + "/quot/outside/saveDept_sheet.screen";
			var result = Modular.view.IBSheet7.doSave(sheet1, url, jQuery("#form1"), false);
		}
	}); 
	
	autoResize();
}

	function gridInit(sheetName){
		var init_sheet = {};
		init_sheet.Cfg = {SearchMode:2, Page:30};
		init_sheet.Cols = [
			       			{Header:'삭제',			Type:"DelCheck",	SaveName:"DEL_CHECK", 	Width:50, 	Align:"Center"},
			    			{Header:'순번',			Type:"Text", 		SaveName:"NO", 			Width:40, 	Align:"Center",	Hidden:"True"},
			    			{Header:'상태',			Type:"Status", 		SaveName:"STATUS",		Width:0, 	Align:"Center",	Hidden:"True"},
			    			{Header:'공통코드',		Type:"Text", 		SaveName:"BASECD",		Width:0, 	Align:"Center",	Hidden:"True"},
			    			{Header:'순번',			Type:"Text", 		SaveName:"SORT_NO", 	Width:50,	Align:"Center"},
			    			{Header:'현장코드',		Type:"Text", 		SaveName:"DETAILCD", 	Width:80, 	Align:"Center", EditLen:10,		KeyField:"True"},
			    			{Header:'현장명',			Type:"Text", 		SaveName:"DETAILNM", 	Width:200, 	Align:"Left", 	EditLen:200,	KeyField:"True"},
			    			{Header:"구분",			Type:"Combo", 		SaveName:"CHG_CODE01", 	Width:150, 	Align:"Center", ComboText:"<%=hq_gubun%>", ComboCode:"<%=hq_gubun_code%>", KeyField:"True"},
			    			/* {Header:'구분',			Type:"Combo", 		SaveName:"CHG_CODE01",  Width:150, 	Align:"Center", Edit:"true", ComboText:"토건|플랜트" , ComboCode:"C|P"}, */
			    			{Header:'생성자',			Type:"Text", 		SaveName:"CRE_NAME",	Width:60, 	Align:"Center", Edit:"false"},
			    			{Header:'생성일자',		Type:"Date", 		SaveName:"CRE_DATE",	Width:100, 	Align:"Center", Edit:"false"}
		];

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

	function sheet1_OnSearchEnd(code, message) {
	    if(code == 0) {
	    	setGridSize();
		} else {
			//조회 에러 수행
			//alert(message);
			alert("조회 실패");
		}
	}
	
	function sheet1_OnSaveEnd(code, msg) {
	    if(code >= 0) {
	    	alert("현장코드목록을 처리 완료했습니다.");
	    } else {
	    	alert(msg);
        }
	    jQuery("#btnSearch").click();
	}

	function setGridSize() {
		sheet1.FitColWidth();
	}
	
	function sheet1_OnSmartResize(Width, Height) { 
		sheet1.FitColWidth();
		autoResize();
	}

	function sheet1_OnChange(Row, Col, Value, OldValue, RaiseFlag) { 
		if(sheet1.ColSaveName(0, Col) == "DETAILCD") {
			if(sheet1.GetCellValue(Row, "STATUS") != "I") {
				alert("현장코드는 수정할 수 없습니다.");
				sheet1.SetCellValue(Row, Col, OldValue, 0);
				return;	
				
			}
			
		}
	}
	
	function autoResize(){
		var t1_height = document.getElementById("search-table").scrollHeight + document.getElementById("title").scrollHeight + 24;
		var iframeHeight= document.body.scrollHeight - t1_height;   
		
		sheet1.SetSheetHeight(iframeHeight); 
	}	
	
	document.body.onresize = addEvent( document.body.onresize, "autoResize()");
</SCRIPT>

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

<form id="form1" name="form1" method="post" modular:type="search" style="width:100%;height:100%;">
<INPUT type="hidden" name="fevent" id="fevent" value="">
<INPUT type="hidden" name="basecd" id="basecd" value="QUOT_DEPT">

<div align="left" id="title">
    <ul>
     <li>견적용 현장코드 관리</li>
    </ul>
  </div> 
	<!-- 검색조건 시작 -->
	<table id="search-table" class="search-form-table">
		<colgroup>
			<col width="*" />
			<col width="250" />
		</colgroup>
		<tr>
			<td>
			</td>
			<td class="button" >
				<span class="btnSearch center"><a href="javascript:void(0);" id="btnSearch">검색</a></span>
				<span class="btnSearch center"><a href="javascript:void(0);" id="btnAdd">추가</a></span>
				<span class="btnSearch center"><a href="javascript:void(0);" id="btnSave">저장</a></span>
			</td>
		</tr>
	</table>
	<!-- 검색조건 종료 -->
	
<div id="sheet1_div" style="padding-top:5px; height: auto; min-height: 350px; overflow: auto;">
	<script>createIBSheet('sheet1','100%', '350px');</script>
</div>
</FORM>
