<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ page import="java.io.*"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ include file="/jsp/common/include/localemessage.jsp" %>
<%
	response.setHeader("Pragma", "No-cache");
	response.setHeader("Cache-Control", "no-cache");
	response.setHeader("Expires", "0");
%>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<jsp:include page="/jsp/common/include/css.jsp"/>
<jsp:include page="/jsp/common/include/script.jsp"/>
<script language="javascript" >
var url      = '<c:url value="/onl/admin/control/controlMan.json" />';
var url_view = '<c:url value="/onl/admin/control/controlMan.view" />';


$(document).ready(function() {
	
	var gridPostData = getSearchForJqgrid("cmd","LIST"); //jqgrid에서는 object 로

	$('#grid').jqGrid({
		datatype:"json",
		mtype : 'POST',
		colNames:[
				  'num',
                  '<%= localeMessage.getString("control.interfaceId") %>',
                  '통제여부',
                  '결과메시지',
                  ],
		colModel:[
				{ name : 'SEQ'   		, align:'left'	 ,width:'10',sortable:false  },
				{ name : 'EAISVCNAME'   , align:'left'	 ,width:'35',sortable:false  },
				{ name : 'STATUS' 		, align:'center' ,width:'10'},
				{ name : 'RESULT' 		, align:'left'   ,width:'35'}
				],
        jsonReader: {
             repeatitems:false
        },	          
	    autoheight: true,
	    height : "500px",
		autowidth: true,
		viewrecords: true,
		gridComplete:function (d){
			var colModel = $(this).getGridParam("colModel");
			for(var i = 0 ; i< colModel.length; i++){
				$(this).setColProp(colModel[i].name, {sortable : false});	//그리드 헤더 화살표 삭제(정렬X)		
			}
		},				
		ondblClickRow: function(rowId) {
        },		
		onSelectRow: function(rowId) {
			var rowData = $(this).getRowData(rowId);
			
       }
	});
	
	resizeJqGridWidth('grid','content_middle','1000');
	
	// 통제 등록
	$("#btn_modify").click(function(e){
		var postData = $('#ajaxForm').serializeArray();
		var serviceNames = $("textarea[name=serviceName]").val();
		
		if(serviceNames.trim() == ""){
			alert('<%= localeMessage.getString("control.chkAlert") %>');
			return;
		}
		
		if(confirm('<%= localeMessage.getString("control.modifyConfirm") %>') == false){
			return;
		}
		
		postData.push({ name: "cmd" , value:"TRANSACTION_SERVICE"});
		postData.push({ name: "flag" , value:"I"});
		postData.push({ name: "serviceNames" , value:serviceNames});
		
		$.ajax({
			type : "POST",
			url:url,
			data:postData,
			 success: function(json, textStatus, jqXHR){
				//$("#insertForm").hide();
				
				var data = json;
				if (!data.rows){
					alert(data.message);
					return ;
				}
				$("#grid").jqGrid('clearGridData');
				var rows = $("#grid")[0].rows;
				var index = Number($(rows[rows.length-1]).attr("id"));
				if (isNaN(index)) index=0;
				for(var i=0;i<data.rows.length;i++){
				    var rowid = index + 1 + i;
					$("#grid").jqGrid('addRow', {
			           rowID : rowid,          
			           initdata : data.rows[i],
			           position :"last",    //first, last
			           useDefValues : false,
			           useFormatter : false,
			           addRowParams : {extraparam:{}}
					});
				}
			},
			error:function(e){
				alert(e.responseText);
			}
		});
	});
	
	
	// 헤제 등록
	$("#btn_delete").click(function(e){
		var postData = $('#ajaxForm').serializeArray();
		var serviceNames = $("textarea[name=serviceName]").val();
		
		if(serviceNames.trim() == ""){
			alert('<%= localeMessage.getString("control.chkAlert") %>');
			return;
		}
		
		if(confirm('<%= localeMessage.getString("control.deleteConfirm") %>') == false){
			return;
		}
		
		postData.push({ name: "cmd" , value:"TRANSACTION_SERVICE"});
		postData.push({ name: "flag" , value:"D"});
		postData.push({ name: "serviceNames" , value:serviceNames});
		
		$.ajax({
			type : "POST",
			url:url,
			data:postData,
			 success: function(json, textStatus, jqXHR){
				var data = json;
				if (!data.rows){
					alert(data.message);
					return ;
				}
				$("#grid").jqGrid('clearGridData');
				var rows = $("#grid")[0].rows;
				var index = Number($(rows[rows.length-1]).attr("id"));
				if (isNaN(index)) index=0;
				for(var i=0;i<data.rows.length;i++){
				    var rowid = index + 1 + i;
					$("#grid").jqGrid('addRow', {
			           rowID : rowid,          
			           initdata : data.rows[i],
			           position :"last",    //first, last
			           useDefValues : false,
			           useFormatter : false,
			           addRowParams : {extraparam:{}}
					});
				}
			},
			error:function(e){
				alert(e.responseText);
			}
		});
	});
	
	
	
	$("#btn_initialize").click(function(){
		if(confirm('<%= localeMessage.getString("control.initializeConfirm") %>') == false){
			return;
		}
		$("textarea[name=serviceName]").val("");
		$("#grid").jqGrid('clearGridData');
	});
	
	
	
	$("#btn_close").click(function(){
		window.close();
	});
	
	buttonControl();
	
});
 
</script>
</head>
	<body>		
		<div class="popup_box">
		<div class="search_wrap">
			<img id="btn_modify" src="<c:url value="/img/btn_regist.png"/>" level="W">
			<img id="btn_delete" src="<c:url value="/img/btn_release.png"/>" level="W">
			<img id="btn_initialize" src="<c:url value="/img/btn_initialize.png"/>" alt=""  level="W" />
			<img id="btn_close" src="<c:url value="/img/btn_close.png"/>"  level="R" status="DETAIL,NEW"/>
		</div>
		<div class="title">통제 등록</div>	&nbsp;&nbsp;<span>'<%= localeMessage.getString("control.info") %>'</span>
		<form id="ajaxForm">
			<table class="table_row" cellspacing="0" >
				<tr>
					<th style="width:100px"><%= localeMessage.getString("control.interfaceId") %></th>
					<td><textarea  name="serviceName" style="width:100%;height:200px"></textarea></td>
				</tr>
			</table>
			
			<table id="grid"></table>
			
		</form>
		
		<div id="pager"></div>
	</div><!-- end content_middle -->
	
	</body>	
</html>

