<%--
  - FileName   : dlgBidHistoryDeptPop.jsp
  - Author(s)  : gyeongmo an
  - Date       : 2014-06-30
  - Copyright  : Copyright (c) 2014 www.udapsoft.co.kr, Inc.
  -
  - 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.*" %>
<%@ page import="kr.co.hsnc.common.sql.RowSet" %>
<%@ page import="kr.co.hsnc.common.util.ValueObject" %>
<%@ page import="com.udapsoft.waf.system.*" %>
<%@ page import="com.udapsoft.waf.common.*" %>
<%@ page import="kr.co.udapsoft.common.*" %>
<%@ page import="com.udapsoft.waf.common.ui.HTMLMaker" %>

<%@ 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();
	ValueObject params = ctx.getParams();
	
	HandlerStorage storage = ctx.getHandlerStorage();
	
	request.setCharacterEncoding("utf-8");
%>
<SCRIPT language="JavaScript">
/*예약함수*/
var sheet1;
var sheet1Row;
var sheet1PageNo = 1;
var pageLastRowIndex = 1;
var validationResult = false;
var filterShow = false;

var argObj = window.dialogArguments;

function _onReady(){
	gridInit(sheet1);
	
	jQuery("#btnSearch").click(function() {
		jQuery("#fevent").val("DEPTPOP");
		var url = Modular.model.PageContext.CONTEXT_ROOT + "dlgBidHistoryDeptPop_sheet.screen";
		Modular.view.IBSheet7.doSearch(sheet1, url, jQuery("#form1"), 30, "");
	});
	
	jQuery("#btnSave").click(function() {
		if (confirm("저장 하시겠습니까?")){
			var f = document.form1;
			$("#fevent").val("DEPT_SAVE");
			var url = Modular.model.PageContext.CONTEXT_ROOT + "dlgBidHistoryDeptPop_process.screen";
			var result = Modular.view.IBSheet7.doSave(sheet1, url, $("#form1"), false);
		}		
	});
	
	jQuery("#btnClose").click(function() {
		setTimeout(function(){parent.SearchUserClose(null);},100);
	});
	
	jQuery("#btnSearch").click();
}

function sheet1_OnSaveEnd(code, msg)
{
	var event = $("#fevent").val();
	if(event == "DEPT_SAVE"){
		alert("수정 하였습니다.");
		jQuery("#btnSearch").click();
	}
}

function gridInit(sheetName){
	var init_sheet = {};
	init_sheet.Cfg = {SearchMode:2, Page:30};
	init_sheet.Cols = [
	                {Header:'Status',	Type:"Status", 			SaveName:"STATUS",			Width:10, 	Align:"Center"	},
		    		{Header:'SEQ',		Type:"Text",	 		SaveName:"DETAILCD", 		Width:10, 	Align:"Left"	},
	    			{Header:'현장코드',	Type:"Text", 			SaveName:"dept_cd", 		Width:30, 	Align:"Center"  },
	    			{Header:'코드',  	Type:"Image", 			SaveName:"IMG_GB", 			Width:10, 	Align:"Center" , Edit:"false",	Cursor:'pointer'},
	    			{Header:'삭제',  	Type:"Image", 			SaveName:"IMG_DEL", 		Width:10, 	Align:"Center" , Edit:"false",	Cursor:'pointer'},
	    			{Header:'현장명',		Type:"Text", 			SaveName:"dept_nm", 		Width:100, 	Align:"Left"    },
	];

	init_sheet.HeaderMode = {Sort:1};
	IBS_InitSheet(sheetName, init_sheet);
	sheetName.SetDataAutoTrim(0);
	sheetName.SetEditable(false);
	sheetName.SetImageList(1,"/img/buyer/button/bt_search_right.gif");
	sheetName.SetImageList(2,"/img/buyer/button/bt_eraser1.gif");
	setGridSize();
	
}

function autoResize(){
	var t1_height = document.getElementById("search-table").scrollHeight + 10;
	var iframeHeight= document.body.scrollHeight - t1_height;   
	
	var iframeWidth = document.body.scrollWidth;
	sheet1.SetSheetHeight(iframeHeight); 
}	

function setGridSize() {
	sheet1.FitColWidth();
}

function sheet1_OnSearchEnd(code, message) {
    if(code == 0) {
    	setGridSize();
	} else {
		alert("조회 실패");
	}
}

function sheet1_OnDblClick(Row, Col, Value, CellX, CellY, CellW, CellH) {
	if(Row == 0)return;
	if( Col == 3){//추가
		searchAccDept();
		$("#TEMP_ROW").val(Row);
	}
	if( Col == 4){//삭제
		sheet1.SetCellValue(Row,"dept_cd",'');   //부서코드
		sheet1.SetCellValue(Row,"dept_nm",'');   //부서명
	}
}
function searchAccDept(p_dept_cd, p_dept_nm){
	var win_id = "_searchSite";
	var link = "/lib/dlgSearchSpotDept_Unitcd_New.screen";
	    link += "?sheetOpenYn=Y&pop_win_id="+win_id;
	fLayerPop(win_id, link, 550,500, '', '', 'NO');	
}

function searchSiteClose(result){
	if( result == null ){
	}else{
		sheet1.SetCellValue($("#TEMP_ROW").val(),"dept_cd",result[0]);   //부서코드
		sheet1.SetCellValue($("#TEMP_ROW").val(),"dept_nm", result[1]);   //부서명
	} 
	fLayerPopClose('_searchSite');	
}

	function prcKeyPress()
	{
  	  	if( event.keyCode == 13 )
  	  	{
  	  		jQuery("#btnSearch").click();
		}
	}
	
	//키처리
	document.onkeydown = function(){
		//F5 새로고침
		if(event.keyCode == "13"){
			jQuery("#btnSearch").click();
		}
		//ESC 창닫기
		if(event.keyCode == "27"){
    		window.close();
		} 
	}
   
</SCRIPT>
<modular:search id="form1">
	<modular:key id="fevent" />
</modular:search>
<BODY onresize="autoResize()" >
<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="TEMP_ROW" value="">

<!-- 검색조건 시작 -->
	<table id="search-table" class="search-form-table">
		<colgroup>
			<col width="100" />
			<col width="*" />
			<col width="200" />
		</colgroup>
		<tr>
			<th>현장명</th>
			<td>
				<%=InputText.get("dept_nm", "", 30, 20, "hangule, required")%> 				
			</td>
			<td class="button" rowspan="2">
				<span class="btnSearch center"><a href="javascript:void(0);" id="btnSearch">검색</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>
</body>
