<%--
  - FileName  :  SYSRightPgmListAddForm.jsp
  - Author(s)  : chj
  - Date       : 2014-06-18 
  - Copyright  : Copyright (c) 2014 www.udapsoft.co.kr, Inc.
  -
  - Description: 프로그램 추가
  --%>

<%@ page contentType="text/html; charset=utf-8" %>
<%@ page buffer="128K" %>
<%@ page import="com.udapsoft.waf.common.ui.*" %>
<%@ page import="kr.co.hsnc.common.util.*"%>
<%@ page import="com.udapsoft.waf.system.HandlerStorage" %>
<%@ 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;
   	String message = null;
	
   	HandlerStorage storage = ctx.getHandlerStorage();
	ValueObject params = storage.getParams();
	String fevent = storage.getEvent();
	
	String pgmGrSelectStr = (String)storage.getObject("PgmGrSelectStr");
	String systemSelectTag = (String)storage.getObject("SystemSelectTag");
	
%>

<SCRIPT language="JavaScript">
var sheet1;
var sheet1Row;
var sheet1PageNo = 1;
var pageLastRowIndex = 1;
var validationResult = false;
var filterShow = false;

function _onReady(){
	gridInit(sheet1);
	
	jQuery("#btnSearchProc").click(function() {
		var f = document.form1;
		f.system_id.value = getSelectedValue(f.system_id);
		f.search_gb_value.value = getCheckedValue(f.search_gb);
		f.gubun.value = getCheckedValue(f.gubun);
		
		jQuery("#fevent").val("GET_SYS_RIGHT_PGM_LIST_ADD_FORM");
		var url = Modular.model.PageContext.CONTEXT_ROOT + "/sycs/security/SYSRightPgmListAddForm_sheet.screen";
		Modular.view.IBSheet7.doSearch(sheet1, url, jQuery("#form1"), 10, "");
	});
	
	jQuery("#btnSaveProc").click(function() {
		var f = document.form1;
		var temp = "N";

		//var sf = window.frames['search_worker'].form1;

		if( getSelectedValue(f.pgm_gr_seq) == "" ) {
			alert("프로그램 그룹을 선택해 주세요.");
			return;
		}

		if( getCheckedValue(f.gubun) == "P" ) {	// 검색조건 Reg Type 값이 '프로그램' 이면
			 for(var i=0; i<sheet1.LastRow(); i++) {
				 if(sheet1.GetCellValue(i+1, "check") == "1") {
					 temp = "Y";
				 }
			 }
			 
			 if(temp == "N") {
				 alert("추가할 프로그램을 선택해 주세요.");
				 return;
			 }
		}
		
		f.gubun.value = getCheckedValue(f.gubun);
		f.pgm_gr_seq.value = getSelectedValue(f.pgm_gr_seq);
			
		jQuery("#fevent").val("SAVE_SYS_RIGHT_PGM_LIST_ADD_FORM");
		var url = Modular.model.PageContext.CONTEXT_ROOT + "/sycs/security/SYSRightPgmListAddForm_sheet.screen";
		var result = Modular.view.IBSheet7.doSave(sheet1, url, jQuery("#form1"), false);
	});
	
	jQuery("#btnClose").click(function() {
		//parent.addPgmProcClose();
		setTimeout(function(){parent.addPgmProcClose('close');},100);
	});
	

	jQuery("#btnSearchProc").click();
}

function gridInit(sheetName){
	var init_sheet = {};
	init_sheet.Cfg = {SearchMode:2, Page:10};
	init_sheet.Cols = [
	       			{Header:'선택',				Type:"CheckBox",		SaveName:"check", 		Width:20, 	Align:"Center"},
	       			{Header:'status',				Type:"Status",		SaveName:"status", 		Width:0, 	Align:"Center", Hidden:"True"},
	       			{Header:'pgm_id',				Type:"Text",		SaveName:"pgm_id", 		Width:20, 	Align:"Center", Hidden:"True"},
	       			{Header:'번호',				Type:"Seq",		SaveName:"", 		Width:15, 	Align:"Center", Edit:"false"},
	       			{Header:'시스템',				Type:"Text",		SaveName:"name", 		Width:50, 	Align:"Center", Edit:"false"},
	    			{Header:'프로그램',			Type:"Text", 			SaveName:"pgm_name", 			Width:80, 	Align:"Center", Edit:"false"},
	    			{Header:'Screen',				Type:"Text", 			SaveName:"screen_name",				Width:80, 	Align:"Left", Edit:"false"},
	    			{Header:'비고',		Type:"Text", 			SaveName:"dscr", 		Width:50,	Align:"Center", Edit:"false"}
	];

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

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

function prcKeyPress() {
 	if( event.keyCode == 13 ) {
 		jQuery("#btnSearchProc").click();
	}
}

function sheet1_OnSaveEnd(code, msg) {
    if(code >= 0) {
		alert("저장 성공!");
		//jQuery("#btnSearch").click();
		setTimeout(function(){parent.addPgmProcClose('save');},100);
	}
	else {
		//alert(msg);
		alert("저장 실패");
		
	}
}

function setDisabled(disabledValue) {
	for(var i=0; i<sheet1.RowCount(); i++) {
		sheet1.SetCellEditable(i+1, "check", disabledValue);
	}
}

</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="text" value="자동 Submit을 막기 위해서 있는 필드" size="0" style="display:none;">

<INPUT type="hidden" name="right_id" value="<%= params.get("right_id") %>">
<INPUT type="hidden" name="pgm_id" value="">
<INPUT type="hidden" name="fevent" id="fevent" value="">
<INPUT type="hidden" name="search_gb_value" id="search_gb_value">

<TABLE border="0" cellspacing="0" cellpadding="0" width="100%">
	<TR>
		<TD>
			<!-- 검색조건 영역 : 시작 -->
			<table id="search-table" class="search-form-table" width="100%">
				<TR height="25"> 
				<!-- 검색조건 타이틀 1 -->
					<Th>
						프로그램 그룹                        
					</Th>
					<TD witdh="30%">
						<%=pgmGrSelectStr %> 
					</TD>
					<Th>
						등록 구분
					</Th>
					<TD witdh="30%">
						<LABEL for="gubun_1"><INPUT id="gubun_1" type="radio" name="gubun" value="P" onClick="setDisabled(true)" checked>프로그램</LABEL>
						<LABEL for="gubun_2"><INPUT id="gubun_2" type="radio" name="gubun" value="L" onClick="setDisabled(false)">LINE</LABEL>
					</TD>
					<td class="button" rowspan="4">
						<span class="btnSearch center"><a href="javascript:void(0);" id="btnSearchProc">검색</a></span>
						<span class="btnSearch center"><a href="javascript:void(0);" id="btnSaveProc">저장</a></span>
						<span class="btnSearch center"><a href="javascript:void(0);" id="btnClose">닫기</a></span>
					</td>
				</TR>
				<TR height="25"> 
				<!-- 검색조건 타이틀 1 -->
					<th>
						시스템 구분
					</th>
					<TD>
						<%= systemSelectTag %>
					</TD>
					<th>
						등록 여부
					</th>
					<TD>
						<LABEL for="search_gb_1"><INPUT id="search_gb_1" type="radio" name="search_gb" value="">All</LABEL>
						<LABEL for="search_gb_2"><INPUT id="search_gb_2" type="radio" name="search_gb" value="REG">Add</LABEL>
						<LABEL for="search_gb_3"><INPUT id="search_gb_3" type="radio" name="search_gb" value="NOT" checked>미등록</LABEL>
					</TD>
				</TR>
				<TR height="25"> 
				<!-- 검색조건 타이틀 1 -->
					<Th>
						프로그램
					</Th>
					<TD>
						<%= InputText.get("pgm_name", "", 90, 35, "hangul, PerSize", "", " onKeyPress='prcKeyPress()'") %>
					</TD>
					<Th>
						Screen
					</th>
					<TD>
						<%= InputText.get("screen_name", "", 90, 35, "english, PerSize", "", " onKeyPress='prcKeyPress()'") %>
					</TD>
				</TR>
			</TABLE>
			<!-- 검색조건 영역 : 종료 -->
		</TD>
	</TR>
	<!-- 검색조건 영역, 테이터 영역 구분 여백 : 시작 -->
		<TR>
			<TD height="5">
				<TABLE border="0" cellspacing="0" cellpadding="0"
					class="search_data_div_height">
					<TR>
						<TD></TD>
					</TR>
				</TABLE>
			</TD>
		</TR>
		<!-- 검색조건 영역, 테이터 영역 구분 여백 : 종료 -->
</TABLE>
<div id="sheet1_div" style="padding-top:5px; height: auto; min-height: 410px; overflow: auto;">
	<script>createIBSheet('sheet1','100%', '410px');</script>
</div>
</FORM>