<%@ 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="/common/acl/deploy/ruleDeployJobMan.json" />';
var url_view = '<c:url value="/common/acl/deploy/ruleDeployJobMan.view" />';
	var isDetail = false;
	var lastsel2;
	
	function unformatterFunction(cellvalue, options, rowObject) {
		return "";
	}

	function formatterFunction(cellvalue, options, rowObject) {
		var rowId = options["rowId"];
		return "<img id='btn_pop_delete' name='img_"+rowId+"' src=<c:url value='/images/bt/pop_delete.gif' /> />";
	}
	function gridRendering() {
		$('#grid').jqGrid({
			datatype:"local",
			loadonce: true,
			rowNum: 10000,
			colNames:['<%= localeMessage.getString("ruleDeployJobDetail.fileName") %>',
                  '<%= localeMessage.getString("ruleDeployJobDetail.bizCode") %>',
                  '<%= localeMessage.getString("ruleDeployJobDetail.ruleType") %>'
                  ],
			colModel:[
					{ name : 'FILENAME', align:'left', sortable:false },
					{ name : 'BIZCODE', align:'center', sortable:false },
					{ name : 'RULETYPE', align:'center', sortable:false }
					],
			jsonReader : {
				repeatitems : false
			},
			loadComplete : function() {
			},
			
			onSortCol : function(){
	        	return 'stop';	//정렬 방지
	        },   
			height : '500',
			autowidth : true,
			viewrecords : true
		});

		resizeJqGridWidth('grid', 'content_middle', '1000');
	}
	function init( key, callback) {
		if (typeof callback === 'function') {
			callback( key);
		}
	}
	function detail( key) {

		if (!isDetail)
			return;
		$.ajax({
			type : "POST",
			url : url,
			dataType : "json",
			data : {
				cmd : 'DETAIL',
				jobId : key
			},
			success : function(json) {
				var data = json;
				var detail = json.detail;

				$("#ajaxForm input[type!=checkbox],#ajaxForm select,#ajaxForm textarea").each(function(){
					var name = $(this).attr("name");
					var tag  = $(this).prop("tagName").toLowerCase();
					$(tag+"[name="+name+"]").val(detail[name.toUpperCase()]);
				});
				$("#grid")[0].addJSONData(data);
				formatDateTime();
			},
			error : function(e) {
				alert(e.responseText);
			}
		});

	}
	
	function formatDateTime() {
		var cellvalue = $("#scheduledDateTime").val();
		if (cellvalue.length == 14) {
			var display = "";
			display=display+cellvalue.substr(0,4)+"-";
			display=display+cellvalue.substr(4,2)+"-";
			display=display+cellvalue.substr(6,2)+" ";
			display=display+cellvalue.substr(8,2)+":";
			display=display+cellvalue.substr(10,2)+":";
			display=display+cellvalue.substr(12,2);
			$("#scheduledDateTime").val(display);
		}
		
		cellvalue = $("#lastJobTime").val();
		if (cellvalue.length == 14) {
			var display = "";
			display=display+cellvalue.substr(0,4)+"-";
			display=display+cellvalue.substr(4,2)+"-";
			display=display+cellvalue.substr(6,2)+" ";
			display=display+cellvalue.substr(8,2)+":";
			display=display+cellvalue.substr(10,2)+":";
			display=display+cellvalue.substr(12,2);
			$("#lastJobTime").val(display);
		}
	}
	
	$(document).ready(function() {
		var returnUrl = getReturnUrlForReturn();
		var key = "${param.jobId}";

		if (key != "" && key != "null") {
			isDetail = true;
		}

		gridRendering();

		init( key, detail);

		$("#btn_delete").click(function() {
			if(confirm("<%= localeMessage.getString("common.checkDelete") %>")){
				var postData = $('#ajaxForm').serializeArray();
				postData.push({
					name : "cmd",
					value : "DELETE"
				});
				$.ajax({
					type : "POST",
					url : url,
					data : postData,
					success : function(args) {
						alert("<%= localeMessage.getString("common.deleteMsg") %>");
						goNav(returnUrl);//LIST로 이동
	
					},
					error : function(e) {
						alert(e.responseText);
					}
				});
			}
		});
		
		$("#btn_previous").click(function() {
			goNav(returnUrl);//LIST로 이동
		});

		buttonControl(key);
		titleControl(key);
	});
</script>
</head>
	<body>
		<div class="right_box">
			<div class="content_top">
				<ul class="path">
					<li><a href="#">${rmsMenuPath}</a></li>					
				</ul>					
			</div><!-- end content_top -->
			<div class="content_middle" id="content_middle">
				<div class="search_wrap">
					<button type="button" class="cssbtn" id="btn_delete" level="W" status="DETAIL"><i class="material-icons">delete</i> <%= localeMessage.getString("button.delete") %></button>
<%-- 					<button type="button" class="cssbtn" id="btn_previous" level="R" status="DETAIL,NEW"><i class="material-icons">arrow_back</i> <%= localeMessage.getString("button.previous") %></button> --%>
					<button type="button" class="cssbtn" id="btn_previous" level="R" status="DETAIL,NEW" style="display: none;" ><i class="material-icons">arrow_back</i><%=localeMessage.getString("button.previous")%></button>
				</div>
				<div class="title"><%= localeMessage.getString("ruleDeployJobDetail.title") %></div>
				
				<form id="ajaxForm">
					<table class="table_row" cellspacing="0">
						<tr>
							<th style="width:20%;"><%= localeMessage.getString("ruleDeployJobMan.jobId") %></th>
							<td><input type="text" name="jobId"/></td>
						</tr>
						<tr>
							<th><%= localeMessage.getString("ruleDeployJobMan.jobName") %></th>
							<td><input type="text" name="jobTitle"/></td>
						</tr>
						<tr>
							<th><%= localeMessage.getString("ruleDeployJobMan.serviceType") %></th>
							<td><input type="text" name="serviceType"/></td>
						</tr>
						<tr>
							<th><%= localeMessage.getString("ruleDeployJobMan.schduledDateTime") %></th>
							<td><input type="text" name="scheduledDateTime" id="scheduledDateTime"/></td>
						</tr>
						<tr>
							<th><%= localeMessage.getString("ruleDeployJobMan.lastJobTime") %></th>
							<td><input type="text" name="lastJobTime" id="lastJobTime"/></td>
						</tr>
						<tr>
							<th><%= localeMessage.getString("ruleDeployJobMan.userId") %></th>
							<td><input type="text" name="userId"/></td>
						</tr>
						<tr>
							<th><%= localeMessage.getString("ruleDeployJobDetail.userIp") %></th>
							<td><input type="text" name="userIp"/></td>
						</tr>
						<tr>
							<th><%= localeMessage.getString("ruleDeployJobMan.status") %></th>
							<td><input type="text" name="status"/></td>
						</tr>
						<tr>
							<th><%= localeMessage.getString("ruleDeployJobDetail.failedCnt") %></th>
							<td><input type="text" name="failedCnt"/></td>
						</tr>
						<tr>
							<th><%= localeMessage.getString("ruleDeployJobDetail.failedMsg") %></th>
							<td><textarea name="failedMsg" rows="2"></textarea></td>
						</tr>
					</table>
				</form>
				
				<!-- grid -->
				<table id="grid"></table>
				
			</div><!-- end content_middle -->
		</div><!-- end right_box -->	
	</body>
</html>