<%@ 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.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);
	ValueObject user = null;
	user = ctx.getUser();
	
	HandlerStorage storage = ctx.getHandlerStorage();

	ValueObject params  = storage.getParams();
	
	request.setCharacterEncoding("utf-8");
%>

<SCRIPT language="JavaScript" src="/js/common.js"></SCRIPT>
<script type="text/javascript">
<!--
/*예약함수*/
var sheet1 = new ibsheetObject();
var sheet1Row;
var sheet1PageNo = 1;
var pageLastRowIndex = 1;
var validationResult = false;
var filterShow = false;


$(function(){
    
    $.gridInit = function(sheetName)
	{
	    var init_sheet = {};
		
		init_sheet.Cfg = {SearchMode:2, Page:30, MergeSheet:msHeaderOnly};
		init_sheet.Cols = [
									{Header:"Status",					Type:"Status", 		SaveName:"STATUS", 					Width:0, 	Align:"Center",  Hidden:"True"},
									{Header:"No.",						Type:"Seq", 			SaveName:"NO",							Width:20, 	Align:"Center"},
									{Header:"선택",					Type:"Radio", 			SaveName:"DEL_CHECK", 				Width:50, 	Align:"Center"},
									{Header:"Type",					Type:"Text", 			SaveName:"CAL_TP_CODE",			Width:140, 	Align:"Center"},
									{Header:"SPEC1",					Type:"Text", 			SaveName:"SPEC1",						Width:140, 	Align:"Left"},
									{Header:"SPEC2",					Type:"Text", 			SaveName:"SPEC2", 						Width:100, 	Align:"Left"},
									{Header:"SPEC3",					Type:"Text", 			SaveName:"SPEC3", 						Width:100, 	Align:"Left"},
									{Header:"SPEC4",					Type:"Text", 			SaveName:"SPEC4", 						Width:100, 	Align:"Center"}
		                   		];
		
		
		init_sheet.HeaderMode = {Sort:1};
		IBS_InitSheet(sheetName, init_sheet);
		sheetName.SetDataAutoTrim(0);
		sheetName.SetEditable(true);
		sheetName.FitColWidth();
	}
    
    
    $.searchList = function()
	{
		$("#fevent").val("GET_CALTYPE_LIST");
		
		var url = Modular.model.PageContext.CONTEXT_ROOT + "/common/MatlCategoryCalTypePopup_sheet.screen";
		Modular.view.IBSheet7.doSearch(sheet1, url, $("#form1"), 30, "");
	}
    
    $("#brn_close").click(function(){
        window.close();
    });
    
    $("#btn_search").click(function(){
        $.searchList();
    });
    
    $("#btn_add").click(function(){
        sheet1.SetDataAutoTrim(0);
        sheet1.DataInsert(-1);
    });
    
    $("#brn_select").click(function(){
        
        var iCheckRowCnt = sheet1.CheckedRows(2);
        var iCheckRow = sheet1.FindCheckedRow(2).replace("|", "");
        
        if(iCheckRowCnt == 0)
		{
			alert("Type을 선택해 주세요.");
			return;
		}
		else
		{
			opener.document.form1.levelType.value = sheet1.GetCellValue(iCheckRow, "CAL_TP_CODE");
			window.close();
		}
    });
    
    
    $("#btn_save").click(function(){
    	var iCheckRowCnt = sheet1.CheckedRows(2);
		var iCheckRow = sheet1.FindCheckedRow(2).replace("|", "");
		
		if(iCheckRowCnt != 0)
		{
		    sheet1.SetCellValue(iCheckRow, "S_STATUS", "D");
			document.form01.calTpCode.value = sheet1.GetCellValue(iCheckRow, "CAL_TP_CODE");
		}
		
		var cnt = 0;
		var Row = sheet1.ColValueDup("3");
		if(Row != -1)
		{
			dlgAlert( Row + "행에 중복된 코드가 존재합니다");
		}else{
			//submitIBSheetRequest("/common/MatlCategoryCalTypePopup_process.screen", "SAVE_CALTYPE_LIST", document.form01, sheetObj);
		 	$("#fevent").val("SAVE_CALTYPE_LIST");
	        
	        var url = Modular.model.PageContext.CONTEXT_ROOT + "/common/MatlCategoryCalTypePopup_form.screen";
			var result = Modular.view.IBSheet7.doSave(sheet1, url, $("#form1"), false);
				
		}
		
    });
    
    
});

function sheet1_OnSaveEnd(code, msg) {
	alert(code);
    if(code >= 0) {
    	alert("저장 성공");
    } else {
    	alert(msg);
    }
}


$(document).ready(function(){
	
    $.gridInit(sheet1);
	$.searchList();
	
	autoResize();
	
});



	function autoResize(){
		var t1_height = document.getElementById("search-table").scrollHeight + document.getElementById("title").scrollHeight + 24;
		var iframeHeight= document.body.scrollHeight - t1_height;   
		var iframeWidth= document.body.scrollWidth;   
		
		
		sheet1.SetSheetHeight(iframeHeight); 
	}	
	
	
	function doResult(resultObj) {
		var f = document.form01;
		try {
			
			if(resultObj.getRequestEvent() == "SAVE_CALTYPE_LIST")
			{
				if( resultObj.getSuccess() ) {

					dlgAlert("저장되었습니다.");
					doSearch(document.all.sheet1);
				}
				else 
				{
					if(Row != -1){
						//dlgAlert(Row+"행에 중복된 인원이 있습니다.");
						//sheetObj.SelectCell(Row, 0, false);
// 						dlgAlert("중복된 자재코드가 있습니다. 자재코드를 확인하세요.");
						dlgErrorMsg(resultObj);
						return;
					}
				}
				document.form01.isSubmit = false;
			}
			else
			{
				document.form01.isSubmit = false;
			}
		}
		catch(errorObject) {
	        showErrorDlg("doResult()", errorObject);
		}
	}
	
	
//-->
</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="">

	<input type="text" value="auto summit for disable" size="0" style="display:none;">

	<!-- 검색하고자 하는 계정타입 : 현재는 SUB(외주)로 고정되어 있음.-->
	<INPUT type="hidden" name="acct_type_code">
	<INPUT type="hidden" name="calTpCode" value="" />



<div align="left" id="title">
	<ul>
    	<li>플랜트자재코드</li>
   	</ul>
</div> 
 
 
<table border="0" cellspacing="0" cellpadding="0" width="660" id="search-table">
	<!-- 검색조건 영역 : 시작 -->
	<tr>
		<td height="1">
			<table cellspacing="1" cellpadding="0" class="search-form-table">
				<col width="30%">
				<col width="70%">

				<tr height="25"> 
    			<!-- 검색조건 타이틀 1 -->
    				<th>
    					CAL_TYPE 조회/등록
    				</th>
				    <td class="search_button" align="right"> 
				    	<span class="btnSearch center"><a href="javascript:void(0);" id="btn_search">검색</a></span>
       					<span class="btnSearch center"><a href="javascript:void(0);" id="brn_select">선택</a></span>
       					<span class="btnSearch center"><a href="javascript:void(0);" id="btn_add">추가</a></span>
       					<span class="btnSearch center"><a href="javascript:void(0);" id="btn_save">저장</a></span>
       					<span class="btnSearch center"><a href="javascript:void(0);" id="brn_close">닫기</a></span>
    				</td>
  				</tr>
			</table>
		</td>
	</tr>
	<!-- 검색조건 영역 : 종료 -->

	<!-- 검색조건 영역, 테이터 영역 구분 여백 : 시작 -->
	<tr>
		<td height="1">
		</td>
	</tr>
	<!-- 검색조건 영역, 테이터 영역 구분 여백 : 종료 -->
</table>

<div id="sheet1_div" style="padding-top:5px; width:660px; height:300px">
	<script>createIBSheet("sheet1","100%", "100%");</script>
</div>

</form>
