<%@page import="com.udapsoft.waf.system.HandlerStorage"%>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ include file="/jsp/work/taglib.jsp" %>
<jsp:useBean id="ctx" class="com.udapsoft.waf.system.context.SessionContext" scope="session" />
<%
	ctx.init(request, response);
%>
<script type="text/javascript">
	/**
	 *	Global variables
	 */
	var masterSheet;
	var masterSheetRow;
	var masterSheetPageNo = 1;
	var pageLastRowIndex = 1;
	var validationResult = false;
	var filterShow = false;
	
	/**
	 *	Application Init Function
	 *	Template 으로 부터 자동으로 호출되는 함수
	 */
	function _onReady(){
		/**
		 *	IBSheet object initialize
		 */
		gridInit(masterSheet);
		
		
		/**
		 *	Application Initialize
		 */
		jQuery("#btnSearch").click(function() {
			jQuery("#fevent").val("masterDataList");
			var url = Modular.model.PageContext.CONTEXT_ROOT + "/testIBSheet7MasterData.screen";
			Modular.view.IBSheet7.doSearch(masterSheet, url, jQuery("#searchForm"), 10000, "");
		});
		jQuery("#btnAdd").click(function() {
			var rowIdx = masterSheet.DataInsert(-1);
		});
		
		jQuery("#btnSave").click(function() {
			if (confirm("저장하시겠습니까?")) {
				jQuery("#fevent").val("masterDataCUD");
				var url = Modular.model.PageContext.CONTEXT_ROOT + "/testIBSheet7MasterData.screen";
				var result = Modular.view.IBSheet7.doSave(masterSheet, url, jQuery("#searchForm"), false);
			}
		});
	}

	/**
	 *	IBSheet object initialize
	 */
	function gridInit(sheetName){
		var init_sheet = {};
		init_sheet.Cfg = {SearchMode:2, Page:10000};
		init_sheet.Cols = [
			{Header:'Status',Type:"Status", SaveName:"sStatus", Width:80, Align:"Center" ,Hidden:"True"},
			{Header:'Sequence',Type:"Seq", SaveName:"sSeq", Width:0, Align:"Center"},
			{Header:'Delete',Type:"DelCheck", SaveName:"delCheck", Width:80, Align:"Center"},
			{Header:'Primary ID',Type:"Int", SaveName:"pid", Width:100, Align:"Left" , UpdateEdit:0},
			{Header:'First name',Type:"Text", SaveName:"first_name", Width:120, Align:"Left"},
			{Header:'Last name',Type:"Text", SaveName:"last_name", Width:120, Align:"Left"},
			{Header:'Birth',Type:"Date", SaveName:"birth", Width:120, Align:"Left", Format:"Ymd"},
			{Header:'Gender',Type:"Combo", SaveName:"gender", Width:120, Align:"center", ComboText:"${MASTERSHEET_GENDER['TEXT']}", ComboCode:"${MASTERSHEET_GENDER['CODE']}"},
			{Header:'Salary',Type:"Float", SaveName:"salary", Width:180, Align:"right"}
		];

		init_sheet.HeaderMode = {Sort:1};
		IBS_InitSheet(sheetName, init_sheet);
		sheetName.SetDataAutoTrim(0);
		setGridSize();
	}
	
	/**
	 *	IBSheet Event: Search End(IBSheet 데이터 조회 CallBack)
	 */
	function masterSheet_OnSearchEnd(code, message) {
	    if(code == 0) {
	    	setGridSize();
		} else {
			//조회 에러 수행
			alert(message);
		}
	}
	
	/**
	 *	IBSheet Event: Save End(IBSheet 데이터 저장 CallBack)
	 */
	function masterSheet_OnSaveEnd(code, msg) {
	    if(code >= 0) {
	    	alert("저장 성공");
	    } else {
	    	alert(msg);
        }
	}
	
	/**
	 *	IBSheet Event: Click
	 */
	function masterSheet_OnClick(Row, Col, Value, CellX, CellY, CellW, CellH) {
		 masterSheetRow = Row;
	}
	 
	/**
	 *	IBSheet size setting
	 */
	function setGridSize() {
		masterSheet.FitColWidth();
	}
</script>

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

<form id="searchForm" method="post" modular:type="search">
	<input type="text" name="fevent" value="" />

	<div style="text-align:right;">
		<input type="button" id="btnSearch" value="Search" />
		<input type="button" id="btnAdd" value="Add" />
		<input type="button" id="btnSave" value="Save" />
	</div>
	<br>
	
	<!-- IBSheet7 그리드 생성 -->
	<script>createIBSheet('masterSheet','100%', '200px');</script>
</form>
