<%--
  - FileName  :  SYSRightPgmList.jsp
  - Author(s)  : gyeongmo an
  - Date       : 2014-06-22 
  - 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.hsnc.common.sql.*" %>
<%@ page import="kr.co.hsnc.common.sql.util.*" %>
<%@ page import="kr.co.hsnc.common.util.*"%>
<%@ 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();
	String event = storage.getEvent();
  	ValueObject user = storage.getUser();
	ValueObject params = storage.getParams();
    
	String systemSelectTag = (String)storage.getObject("SystemSelectTag");

    RowSet listRowSet = storage.getRowSet("ListRowSet");

	String url = request.getRequestURL().toString();
	 url = url.substring(0, url.indexOf("/",7));
%>
<SCRIPT language="JavaScript">
/*예약함수*/
var sheet1;
var sheet1Row;
var sheet1PageNo = 1;
var pageLastRowIndex = 1;
var validationResult = false;
var filterShow = false;

function _onReady(){
	gridInit(sheet1);
	
    jQuery("#btnSearch").click(function() {
    	jQuery("#fevent").val("GET_RIGHT_PGM_LIST");
		var url = Modular.model.PageContext.CONTEXT_ROOT + "/sycs/security/SYSRightPgmList_sheet.screen";
		Modular.view.IBSheet7.doSearch(sheet1, url, jQuery("#form1"), 30, "");
    });
	
	jQuery("#btnClear").click(function() {
		jQuery("#system_id").val("");
		jQuery("#pgm_gr_name").val("");
		jQuery("#pgm_name").val("");
		jQuery("#screen_name").val("");
	});
	
	jQuery("#btnDelete").click(function() {
		var temp = false;
		
		for( var i=0; i<sheet1.RowCount(); i++ ) {
			if(sheet1.GetCellValue(i+1, "check") != "0") {
				temp = true;
			} 
		}
		
		if(temp == true) {
			if( confirm("삭제 하시겠습니까?")) {
				jQuery("#fevent").val("DELETE_RIGHT_PGM_LIST");
				var url = Modular.model.PageContext.CONTEXT_ROOT + "/sycs/security/SYSRightPgmList_sheet.screen";
				var result = Modular.view.IBSheet7.doSave(sheet1, url, jQuery("#form1"), false);
			}
		} else {
			alert("삭제할 대상을 선택해 주십시오.");
		}
	}); 
	
	jQuery("#btnModGroupSeqProc").click(function() {
		var win_id = "_modGroupSeqProc";
		var right_id = document.form1.right_id.value;
		var link = "/sycs/security/SYSRightPgmListGrSortForm.screen";
		    link += "?pop_win_id="+win_id+"&right_id="+right_id;
		fLayerPop(win_id, link, 450,400, '', '', 'NO');
	}); 
	
	jQuery("#btnAddPgmProc").click(function() {
		var win_id = "_addPgmProc";
		var right_id = document.form1.right_id.value;
		var link = "/sycs/security/SYSRightPgmListAddForm.screen";
		    link += "?pop_win_id="+win_id + "&right_id="+right_id;
		fLayerPop(win_id, link, 820,530, '', '', 'NO');
	}); 
	
	jQuery("#btnList").click(function() {
		var f = document.form1;

		f.target = "_self";
		f.action = "/sycs/security/SYSRightList.screen";
		f.fevent.value = "";

		formSubmit(f);
	}); 
	
	autoResize();
	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:0, 	Align:"Center", Hidden:"True"},
		       			{Header:'그룹번호',				Type:"Text",		SaveName:"pgm_gr_id", 	Width:20, 	Align:"Center", Hidden:"True"},
		    			{Header:'☞그룹명',			Type:"Text", 		SaveName:"pgm_gr_name",		Width:50, 	Align:"Center", Edit:"false", Cursor:"Pointer"},
		    			{Header:'삭제',			Type:"DelCheck", 	SaveName:"check", 		Width:20, 	Align:"Center", ColMerge:"false"},
		    			{Header:'번호',			Type:"Text", 		SaveName:"pgm_seq", 	Width:20,  	Align:"Center", Edit:"false"},
		    			{Header:'유형',			Type:"Text", 		SaveName:"gubun", 	Width:20, 	Align:"Center", Edit:"false"},    
		    			{Header:'프로그램',				Type:"Text", 		SaveName:"pgm_name", 	Width:70, 	Align:"Left", Edit:"false"  },
		    			{Header:'시스템',				Type:"Text",		SaveName:"name", 	Width:30, 	Align:"Center", Edit:"false"  },
		    			{Header:'Screen',	Type:"PopupEdit", 		SaveName:"screen_name", 	Width:250, 	Align:"Left"},
		    			{Header:'pgm_list_id',	Type:"Text", 		SaveName:"pgm_list_id", 	Width:30, 	Align:"Left", Hidden:"True"}
	];

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

	sheetName.SetMergeSheet(msPrevColumnMerge);

	setGridSize();
}

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

function sortPgmProc(pgmGrID) {
	var win_id = "_sysRightPgmListSortForm";
	var right_id = document.form1.right_id.value;
	var link = "/sycs/security/SYSRightPgmListSortForm.screen";
	    link += "?pop_win_id="+win_id+"&right_id="+right_id+"&pgm_gr_id="+pgmGrID;
	fLayerPop(win_id, link, 450,400, '', '', 'NO');
}

function sysRightPgmListSortFormClose(result) {
	fLayerPopClose('_sysRightPgmListSortForm');
	if(result != "close") {
	    reloadProc();
	}
}

function reloadProc() {
	document.form1.scrollTopValue.value = document.body.scrollTop;
	jQuery("#btnSearch").click();
}

function modGroupSeqProcClose(result) {
	fLayerPopClose('_modGroupSeqProc');
	if(result != "close") {
	    reloadProc();
	}
}

function addPgmProcClose(result) {
	fLayerPopClose('_addPgmProc');
	if(result != "close") {
		reloadProc();
	}
}

function enterKeyPress(param) {
	if (event.keyCode == 13) {
		jQuery("#btnSearch").click();
	}
}

function doKeyPressEvent(param1, param2) {
	
}

function sheet1_OnSaveEnd(code, msg) {
    if(code >= 0) {
    	alert("삭제 성공!");
    } else {
    	alert(msg);
    	
    }
    jQuery("#btnSearch").click();
}

function sheet1_OnSearchEnd(code, message) {
    if(code == 0) {
    	setGridSize();
    	sheet1.SetColFontColor("pgm_gr_name", "#0000ff");
	} else {
		//조회 에러 수행
		alert(message);
		//alert("조회 실패");
	}
}

function sheet1_OnPopupClick(Row, Col) {
      var sName = sheet1.ColSaveName(Col);
      var sScreen = sheet1.GetCellValue(Row,Col);
      var url = "<%=url%>";
      
      if(sName == "screen_name")
      {
 	      var sUrl = url + sScreen;
	      window.open(sUrl);
     }
}

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

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

function sheet1_OnClick(Row, Col, Value, CellX, CellY, CellW, CellH) {
	if(sheet1.ColSaveName(Col) == "pgm_gr_name") {
		sortPgmProc(sheet1.GetCellValue(Row, "pgm_gr_id"));
	}
}

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="">
<INPUT type="hidden" name="right_id" value="<%= params.get("right_id") %>">
<INPUT type="hidden" name="scrollTopValue" value="<%= params.get("scrollTopValue") %>"> 
<div align="left" id="title">
    <ul>
     <li>권한 관리</li>
    </ul>
  </div> 

<!-- 검색조건 시작 -->
	<table id="search-table1" class="search-form-table">
		<colgroup>
			<col width="100" />
			<col width="400" />
			<col width="100" />
			<col width="*" />
			<col width="200" />
		</colgroup>
		<tr>
			<th>시스템</th>
			<td>
				<%= systemSelectTag %>
			</td>
			<th>그룹명</th>
			<td>
				<%= InputText.get("pgm_gr_name", params.get("pgm_gr_name"), 80, 30, "hangul, enterTab,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>
			</td>
		</tr>
		<tr>
			<th>프로그램명</th>
			<td>
				<%= InputText.get("pgm_name", params.get("pgm_name"), 79, 30, "hangul, enterTab,PerSize") %>
			</td>
			<th>Screen</th>
			<td>
				<%= InputText.get("screen_name", params.get("screen_name"), 80, 30, "english, PerSize") %>
			</td>
		</tr>
	</table>
	<!-- 검색조건 종료 -->
	
	<table id="search-table2" width="100%">
		<tr>
			<td class="button" align="right">
				<span class="btnSearch center"><a href="javascript:void(0);" id="btnModGroupSeqProc">그룹순서변경</a></span>
				<span class="btnSearch center"><a href="javascript:void(0);" id="btnAddPgmProc">추가</a></span>
				<span class="btnSearch center"><a href="javascript:void(0);" id="btnDelete">삭제</a></span>
				<span class="btnSearch center"><a href="javascript:void(0);" id="btnList">목록</a></span>
			</td>
		</tr>
	</table>
	
<!-- 본문시작 -->
<div id="sheet1_div" style="padding-top:5px; height: auto; min-height: 400px; overflow: auto;">
	<script>createIBSheet('sheet1','100%', '400px');</script>
</div>
</FORM>
