<%@ page import="ro.emid.common.job.JobRequest" %>
<%@ page import="ro.emid.common.constants.*" %>
<%@ page import="ro.emid.common.utils.*" %>
<%@ page import="ro.emid.common.utils.pagination.PaginationData" %>
<%@ page import="ro.emid.common.utils.sort.SortData" %>
<%@ page import="ro.emid.common.utils.pagination.PaginationController" %>
<%@ page import="ro.emid.callcenter.util.CallcenterHelper" %>

<%@ include file="../declaratii.jsp"%>


<%
        /**
         * ro.emid.callcenter.sync.LoadIstoricSyncAdreseAction
         */
    final SortData sd = (SortData) request.getAttribute("sortData");
    final PaginationData pd = (PaginationData) request.getAttribute("paginationData");


    JobRequest[] result = (JobRequest[]) request.getAttribute("result");
    if (result == null) result = new JobRequest[0];
%>
<div class="spacer"></div>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td  width="180" valign="top">
            <%@ include file="../localitati-ce/menu.jsp"%>
        </td>
        <td class="pl5">
            Istoric sincronizare nomenclator adrese:
        <form action="<%=AppConstants.APP_NAME%>?action=sync-adr-history" method="post" class="mt5">
        <table width="100%" class="table">
            <thead>
                <tr>
                <th width="1%">  </th>
                <th class="align-center"> # </th>
                <th> Stare </th>
                <th> Procedura </th>
                <th> Utilizator </th>
                <th> Data lansare </th>
                <th> Data start </th>
                <th> Data finalizare </th>
                <th> Rezultat </th>
                </tr>
            </thead>

            <tbody>
                <%if(result.length == 0){%>
                <tr>
                    <td colspan="10" class="no-data">Nu exista comenzi de sincronizare ...</td>
                </tr>
                <%}else for(int i=0; i<result.length; i++){
                    JobRequest job = result[i];
                %>

                <tr id="tr<%=i%>">
                    <td style="padding-left: 4px;">
                        <span title="Click pentru vizualizare detalii" id="plus<%=job.getId()%>"></span>
                    </td>
                    <td align="center"><%=job.getId()%></td>
                    <%
                        String status = "";
                        if ("W".equals(job.getStatus())) status = "In asteptare";
                        else if ("R".equals(job.getStatus())) status = "In lucru";
                        else if ("D".equals(job.getStatus())) status = "Finalizat";
                        else if ("E".equals(job.getStatus())) status = "Eroare";
                    %>
                    <td align="center"><%=status%></td>
                    <td align="center"><%=job.getJobId()%></td>
                    <td align="center"><%=StringUtils.getNullSafe(job.getUsername())%></td>
                    <td align="center"><%=AppConstants.formatDataTime(job.getDateRequest())%></td>
                    <td align="center"><%=AppConstants.formatDataTime(job.getDateJobStart())%></td>
                    <td align="center"><%=AppConstants.formatDataTime(job.getDateJobEnd())%></td>
                    <td align="center"><%=StringUtils.getNullSafe(job.getJobResult())%></td>
                </tr>


                <% if (CallcenterHelper.isIntegratedWithSap()) { %>
                    <tr id="city<%=job.getId()%>">
                        <td>&nbsp;</td>
                        <td colspan="10" id="city_plusForId<%=job.getId()%>">
                            Se incarca ...
                        </td>
                    </tr>

                    <script type="text/javascript">
                        new Plus('plus<%=job.getId()%>', 'city<%=job.getId()%>', function () {
                            if (this.getStatus() == PlusConstants.STATUS_MINUS) {
                                $('city_plusForId<%=job.getId()%>').innerHTML = 'Se incarca ...';
                                new Ajax.Request('<%=AppConstants.APP_NAME%>?action=sync-adr-load-changes&idJob=<%=job.getId()%>',{
                                    method: 'post',
                                    onComplete: function (originalRequest) {
                                        Element.removeClassName('city_plusForId<%=job.getId()%>', "loadingLocalitati");
                                        var response = getResponseMesg(originalRequest.responseText);
                                        $('city_plusForId<%=job.getId()%>').innerHTML = response;
                                    }
                                });
                            }
                        });
                    </script>
                    <%}%>
                <%}%>


            </tbody>
            <tfoot>
                <tr class="paginationRow">
                    <td colspan="10" align="right">
                        <div class="pull-left">
                            <input type="button" value="Sincronizare nomenclator adrese" data-href="<%=AppConstants.APP_NAME%>?action=start-job-sync-adrese"
                                   title="Lansare procedură de sincronizare a nomenclatorului de adrese"
                            />
                        </div>
                        <div class="pull-right">
                            <%=PaginationController.printPaginationData(pd)%>
                        </div>
                    </td>
                </tr>
            </tfoot>
        </table>
        </form>
    </td>
</tr>
</table>
