<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%-- JSP TAGS --%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@taglib prefix="my" tagdir="/WEB-INF/tags"%>

<%-- CONTENT --%>
<my:page>

    <jsp:attribute name="script">
        <script type="text/javascript" src="${lib}/jquery.spring-friendly/jquery.spring-friendly.js"></script>
    </jsp:attribute>
    <jsp:attribute name="pageHeaderTitle">Endorsement Key Credentials</jsp:attribute>

    <jsp:body>
        <div class="aca-input-box-header">
            <form:form method="POST" action="${portal}/certificate-request/endorsement-key-credentials/upload" enctype="multipart/form-data">
                Import Endorsement Key Credentials
                <my:file-chooser id="ek-editor" label="Import Endorsement Key Credentials">
                    <input id="importFile" type="file" name="file" multiple="multiple" />
                </my:file-chooser>
            </form:form>
        </div>
        <br/>
        <div class="aca-data-table">
            <table id="endorsementKeyTable" class="display" width="100%">
                <thead>
                    <tr>
                        <th>Device</th>
                        <th>Issuer</th>
                        <th>Type</th>
                        <th>Manufacturer</th>
                        <th>Model</th>
                        <th>Version</th>
                        <th>Valid (begin)</th>
                        <th>Valid (end)</th>
                        <th>Options</th>
                    </tr>
                </thead>
            </table>
        </div>
        <script>
            $(document).ready(function() {
                var url = pagePath +'/list';
                var columns = [
                        {
                            data: 'device.name',
                            render: function (data, type, full, meta) {
                                // if there's a device, display its name, otherwise
                                // display nothing
                                if (full.device) {
                                    // TODO render a link to a device details page,
                                    // passing the device.id
                                    return full.device.name;
                                }
                                return '';
                            }
                        },
                        {data: 'issuer'},
                        {data: 'credentialType'},
                        {data: 'manufacturer'},
                        {data: 'model'},
                        {data: 'version'},
                        {
                            data: 'beginValidity',
                            searchable:false,
                            render: function (data, type, full, meta) {
                                return formatDateTime(full.beginValidity);
                            }
                        },
                        {
                            data: 'endValidity',
                            searchable:false,
                            render: function (data, type, full, meta) {
                                return formatDateTime(full.endValidity);
                            }
                        },
                        {
                            data: 'id',
                            orderable: false,
                            searchable:false,
                            render: function(data, type, full, meta) {
                                // Set up a delete icon with link to handleDeleteRequest().
                                // sets up a hidden input field containing the ID which is
                                // used as a parameter to the REST POST call to delete
                                var html = '';
                                html += certificateDetailsLink('endorsement', full.id, true);
                                html += certificateDownloadLink(full.id, pagePath);
                                html += certificateDeleteLink(full.id, pagePath);

                                return html;
                            }
                        }
                    ];

               //Set data tables
                setDataTables("#endorsementKeyTable", url, columns);
            });
        </script>
    </jsp:body>
</my:page>
