<%--
  - FileName   : ExceptionalUserList.jsp
  - Author(s)  : gyeongmo an
  - Date       : 2014.06.22
  - 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();
	String event = storage.getEvent();
	
	String selectText 	   = (String)storage.getObject("selectText");
	String selectValue     = (String)storage.getObject("selectValue");
%>
<SCRIPT language="JavaScript">
	/*예약함수*/
	var sheet1;
	var sheet1Row;
	var sheet1PageNo = 1;
	var pageLastRowIndex = 1;
	var validationResult = false;
	var filterShow = false;
	var clickRow;
	var gubun;
	
	function _onReady(){
		gridInit(sheet1);
		
		jQuery("#btnSearch").click(function() {
			jQuery("#fevent").val("GET_USER_LIST");
			var url = Modular.model.PageContext.CONTEXT_ROOT + "/sycs/security/ExceptionalUser_sheet.screen";
			Modular.view.IBSheet7.doSearch(sheet1, url, jQuery("#form1"), 30, "");
		});
		
		jQuery("#btnClear").click(function() {
			jQuery("#p_dept_cd").val("");
			jQuery("#p_dept_nm").val("");
			jQuery("#p_jumin").val("");
			jQuery("#p_sabun").val("");
			jQuery("#p_name").val("");
		});
		
		jQuery("#btnAdd").click(function() {
			var rowIndex = sheet1.DataInsert(-1);
			
	    	sheet1.SetCellEditable(rowIndex, "SABUN", true);
	    	sheet1.SetCellEditable(rowIndex, "NAME", true);
	    	sheet1.SetCellEditable(rowIndex, "JUMIN", true);
			
			sheet1.SetCellValue(rowIndex, "P_NAME1", sheet1.GetCellText(rowIndex, "P_CODE"));
		});
		
		jQuery("#btnSave").click(function() {
			if(confirm("저장하시겠습니까?")) {
				jQuery("#fevent").val("SAVE_USER_LIST");
				var url = Modular.model.PageContext.CONTEXT_ROOT + "/sycs/security/ExceptionalUser_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:"Seq",			SaveName:"NO", 			Width:40, 	Align:"Center"},
			    			{Header:'상태',			Type:"Status",		SaveName:"STATUS",		Width:0, 	Align:"Center", Hidden:"True"},
			    			{Header:'사원번호',			Type:"Text",		SaveName:"SABUN", 		Width:70, 	Align:"Center", EditLen:"8", KeyField:"true"},
			    			{Header:'이름',				Type:"Text",		SaveName:"NAME", 		Width:75,  Align:"Center", EditLen:"30", KeyField:"true"},
			    			{Header:'주민번호',				Type:"Text", 		SaveName:"JUMIN", 		Width:100, 	Align:"Center", EditLen:"20" , Hidden:"True"},    
			    			{Header:'재임여부',	Type:"Combo",		SaveName:"DUTYC", 		Width:60, 	Align:"Center", ComboText:"재직|퇴직", ComboCode:"10|99"},
			    			{Header:'직위',		Type:"Combo",		SaveName:"P_CODE", 		Width:60, 	Align:"Center", ComboText:"<%=selectValue%>", ComboCode:"<%=selectText%>"},
			    			{Header:'부서',		Type:"Popup",		SaveName:"DEPT_NAME", 	Width:150, 	Align:"Left", KeyField:"true"},
			    			{Header:'현장',				Type:"Popup",		SaveName:"DEPT_NM", 	Width:240, 	Align:"Left"},
			    			{Header:'전화번호',			Type:"Text",		SaveName:"TEL", 		Width:90, 	Align:"Center", EditLen:"20"},
			    			{Header:'휴대폰번호',		Type:"Text",		SaveName:"HPTEL", 		Width:90, 	Align:"Center", EditLen:"30"},
			    			{Header:'시작일자',		Type:"Date",	SaveName:"ENABLEFROM", 	Width:85, 	Align:"Center"},
			    			{Header:'종료일자',			Type:"Date",	SaveName:"ENABLETO", 	Width:85, 	Align:"Center"},
			    			{Header:'부서',			Type:"Text",		SaveName:"BUSEO", 		Width:0, 	Align:"Center", Hidden:"True"},
			    			{Header:'REAL DEPT CD',		Type:"Text",		SaveName:"REAL_DEPT_CD",Width:0, 	Align:"Center", Hidden:"True"},
			    			{Header:'직위코드',	Type:"Text",		SaveName:"P_NAME1", 	Width:0, 	Align:"Center", Hidden:"True"},
			    			{Header:'부서코드',			Type:"Text",		SaveName:"D_CODE", 		Width:0, 	Align:"Center", Hidden:"True"},
			    			{Header:'SEQ',			Type:"Text",		SaveName:"SEQ", 		Width:0, 	Align:"Center", Hidden:"True"}
		];

		init_sheet.HeaderMode = {Sort:1};
		IBS_InitSheet(sheetName, init_sheet);
		sheetName.SetDataAutoTrim(0);
		setGridSize();
	}
 	
 	function setGridSize() {
		sheet1.FitColWidth();
	}
 	
	function sheet1_OnSaveEnd(code, msg) {
	    if(code >= 0) {
			alert("저장 성공!");
			jQuery("#btnSearch").click();
		}
		else {
			//alert(msg);
			alert("저장 실패");
		}
	}
	
	function searchAccDept(gubun2){
		gubun = gubun2;
		var win_id = "searchAccDept";
		var link = "/lib/dlgSearchAccDept.screen";
		    link += "?pop_win_id="+win_id;
		fLayerPop(win_id, link, 600,400, '', '', 'NO');
	}
	
	function searchAccDeptClose(result) {
		var f = document.form1;
		if( result == null ){
			f.p_dept_cd.value = "";   //부서코드
			f.p_dept_nm.value = "";   //부서명

		}else{
			if(gubun != "sheet") {
				f.p_dept_cd.value = result[0];   //부서코드
				f.p_dept_nm.value = result[1];   //부서명
			} else {
				sheet1.SetCellValue(clickRow, "D_CODE", result[0]);   //부서코드
				sheet1.SetCellValue(clickRow, "DEPT_NAME", result[1]);   //부서명
			}
		}
		
		fLayerPopClose('searchAccDept');
	}
	
	function sheet1_OnSearchEnd(code, message) {
	    if(code == 0) {
	    	for(var i=0; i<sheet1.RowCount(); i++) {
		    	sheet1.SetCellEditable(i+1, "NO", false);
		    	sheet1.SetCellEditable(i+1, "SABUN", false);
		    	sheet1.SetCellEditable(i+1, "NAME", false);
		    	sheet1.SetCellEditable(i+1, "JUMIN", false);
	    	}
	    	setGridSize();
		} else {
			alert(message);
		}
	}
	
	function sheet1_OnValidation(Row, Col, Value) {
		var sName = sheet1.ColSaveName(Col);
		  
	  switch(sName) {
			case "SABUN":
				if(Value==""){
					alert("사번을 입력해 주세요.");
					sheet1.ValidateFail(1);
					sheet1.SelectCell(Row, Col);
				}
				break;
			case "NAME":
				if(Value==""){
					alert("이름을 입력해 주세요.");
					sheet1.ValidateFail(1);
					sheet1.SelectCell(Row, Col);
				}
				break;
	    	/* case "JUMIN":
				if(Value==""){
					alert("주민번호를 입력해 주세요.");
					sheet1.ValidateFail(1);
					sheet1.SelectCell(Row, Col);
				}
				break; 2016.5.20 해제*/
	    	case "DEPT_NAME":
				if(Value==""){
					alert("부서를 입력해 주세요.");
					sheet1.ValidateFail(1);
					sheet1.SelectCell(Row, Col);
				}
				break;
	    	/*2016.5.20 case "DEPT_NM":
				if(Value==""){
					alert("현장을 입력해 주세요.");
					sheet1.ValidateFail(1);
					sheet1.SelectCell(Row, Col);
				}
				break; */
	    }
	}
	
	function sheet1_OnChange(Row, Col, Value, OldValue, RaiseFlag) {
		var sName = sheet1.ColSaveName(Col);
		  
		  if(sName=="TEL" || sName=="HPTEL"){
			  if( !checkTelno(Value)  ){
				alert("올바른 데이타를 입력해 주세요.");
				sheet1.ReturnCellData(Row,Col) ;
			}
		  }
		  
		  if(sName == "P_CODE"){
			  sheet1.SetCellValue(Row, "P_NAME1", sheet1.GetCellText(Row, "P_CODE"));
		  }
	}
	
	function sheet1_OnPopupClick(Row, Col) {
		var sName = sheet1.ColSaveName(Col);
		
		if ( sName=="DEPT_NM" ) {	// 현장
			var sColN = sheet1.SaveNameCol("BUSEO");    //BUSEO의 컬럽번호
			searchSite(Row, Col, sColN);
		} else if ( sName=="DEPT_NAME" ) {	// 부서
			clickRow = Row;
			searchAccDept('sheet');
		}
	}
	
	function searchSite(Row, Col1, Col2) {
		clickRow = Row;
		var win_id = "searchSpotDept";
		var link = "/lib/dlgSearchSpotDept_Unitcd.screen";
		    link += "?pop_win_id="+win_id+"&sheetOpenYn=Y&returnRow="+Row+"&returnCol1="+Col1+"&returnCol2="+Col2;
		fLayerPop(win_id, link, 550,540, '', '', 'NO');
	}
	 
	function searchSiteClose(result, Row, Col1, Col2) {
		if( result == null ){
			//parent.sheet1.SetCellValue(Row, Col1, "");
			//parent.sheet1.SetCellValue(Row, Col2, "");
		}else{
			sheet1.SetCellValue(Row, Col1, result[1]);   
			sheet1.SetCellValue(Row, Col2, result[0]);
		}
		fLayerPopClose('searchSpotDept');
	}   
	
function doKeyPressEvent() {
	
}

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

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" value="">
<div align="left" id="title">
    <ul>
     <li>예외 사용자 관리</li>
    </ul>
  </div> 
	<!-- 검색조건 시작 -->
	<table id="search-table" class="search-form-table">
		<colgroup>
			<col width="100" />
			<col width="350" />
			<col width="100" />
			<col width="*" />
			<col width="250" />
		</colgroup>
		<tr>
			<th>부서</th>
			<td>
		   		<%= InputText.get("p_dept_cd", params.get("p_dept_cd"), 12, 10, "ID,ReadOnly,PerSize") %>
		  		<%= InputText.get("p_dept_nm", DeptCodeManager.getDeptName(params.get("p_dept_cd")), 57, 30, "ID,ReadOnly,PerSize") %>
	  	  		<IMG onclick="searchAccDept('search')" src="/img/buyer/button/bt_search_right.gif" alt="부서찾기" border="0" align="absmiddle" style="cursor:hand;"> 				
			</td>
			<!-- <th>주민번호</th> -->
			<td colspan=2>
				&nbsp;<!--<%= InputText.get("p_jumin", params.get("p_jumin"), 60, 13, "number, PerSize") %>-->
			</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="btnClear">초기화</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>
		<tr>
			<th>사원번호</th>
			<td>
				<%= InputText.get("p_sabun", params.get("p_sabun"), 72, 13, "number, PerSize") %>
			</td>
			<th>이름</th>
			<td>
				<%= InputText.get("p_name", params.get("p_name"), 60, 13, "hangule, PerSize") %>
			</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>
  