<%@ page language="java" contentType="text/html; charset=utf-8" %>
<%@ page import="java.io.*" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@ 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/apim/approval/apprequest/prodAppRequestMan.json" />';
      var url_view = '<c:url value="/onl/apim/approval/apprequest/prodAppRequestMan.view" />';
      $(document).ready(function() {
        $('#grid').jqGrid({
          datatype: "json",
          mtype: 'POST',
          url: url,
          postData: {
            cmd: 'LIST',
          },
          colNames: ['id', '기관명 ', '상태', '생성일'],
          colModel: [
            {name: 'id', align: 'center', key: true, hidden: true},
            {
              name: 'org.orgName',
              align: 'center',
              width: 150,
              label: '기업명'
            },
            {
              name: 'status',
              align: 'center',
              width: 80,
              formatter: function(cellvalue) {
                const statusMap = {
                  'PENDING': '대기중',
                  'APPROVED': '승인',
                  'REJECTED': '반려',
                  'CANCELED': '취소'
                };
                return statusMap[cellvalue] || cellvalue;
              }
            },
            {name: 'createdDate', align: 'center', width: 120}
          ],
          jsonReader: {
            repeatitems: false
          },
          pager: $('#pager'),
          rowNum: '${rmsDefaultRowNum}',
          rowList: eval('[${rmsDefaultRowList}]'),
          viewrecords: true,
          autowidth: true,
          height: 'auto',
          ondblClickRow: function(rowId) {
            var rowData = $(this).getRowData(rowId);
            var id = rowData['id'];
            var approvalType = rowData['approvalType'];
            var args = {};
            var url2 = url_view;
            url2 += '?cmd=DETAIL';
            url2 += '&menuId=' + '${param.menuId}';
            url2 += '&type=' + approvalType;
            url2 += '&id=' + id;

            showModal(url2, args, 800, 650, function() {
              $("#grid").trigger("reloadGrid");
            });
          },
          loadError: function(jqXHR, textStatus, errorThrown) {
            var location = '<%=request.getContextPath()%>/';
            comloadError(jqXHR, textStatus, errorThrown, location);
          }
        });

        resizeJqGridWidth('grid', 'content_middle', '1000');

        $("#btn_search").click(function() {
          var postData = getSearchForJqgrid("cmd", "LIST");
          $("#grid").setGridParam({url: url, postData: postData, page: 1}).trigger("reloadGrid");
        });

        $("select[name^=search], input[name^=search]").keydown(function(key) {
          if (key.keyCode == 13) {
            $("#btn_search").click();
          }
        });

        buttonControl();
      });
    </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_search" level="R"><i class="material-icons">search</i> <%= localeMessage.getString("button.search") %>
            </button>
        </div>
        <div class="title">운영 인증키 요청 목록<span class="tooltip">운영 인증키 요청을 관리합니다.</span></div>
        <form id="ajaxForm" onsubmit="return false;">
            <table class="search_condition" cellspacing="0">
                <tbody>
                <tr>
                    <th style="width:10%;">승인 상태</th>
                    <td style="width:15%;">
                        <div class="select-style">
                            <select name="searchStatus">
                                <option value="">전체</option>
                                <option value="PENDING">대기중</option>
                                <option value="CANCELED">취소됨</option>
                                <option value="DENIED">반려됨</option>
                                <option value="APPROVED">승인됨</option>
                            </select>
                        </div>
                    </td>
                </tr>
                </tbody>
            </table>
        </form>
        <table id="grid"></table>
        <div id="pager"></div>
    </div><!-- end content_middle -->
</div><!-- end right_box -->
</body>
</html>
