<%@ page import="ro.emid.callcenter.obj.AlocareLocalitateCentru" %>
<%@ page import="ro.emid.callcenter.util.CallcenterHelper" %>
<%@ page import="ro.emid.common.constants.AppConstants" %>
<%@ page import="ro.emid.common.utils.pagination.PaginationController" %>
<%@ page import="ro.emid.common.utils.pagination.PaginationData" %>
<%@ page import="ro.emid.common.utils.sort.SortController" %>
<%@ page import="ro.emid.common.utils.sort.SortData" %>
<%@ page import="ro.emid.callcenter.action.localitatice.LoadLocalitatiAlocateAction" %>
<%@ page import="ro.emid.common.utils.RequestUtils" %>

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

<%
    /**
     * @see LoadLocalitatiAlocateAction
     */

    final String search = RequestUtils.getString(request, "search");

    final AlocareLocalitateCentru[] alocari = (AlocareLocalitateCentru[]) request.getAttribute("items");

    final SortData sd = (SortData) request.getAttribute("sd");
    final PaginationData pd = (PaginationData) request.getAttribute("pd");
%>

<div class="spacer"></div>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td width="180" valign="top">
            <%@ include file="menu.jsp"%>
        </td>
        <td class="pl5">
            <%@ include file="../../layout/messages.jspf"%>
            <form action="<%=AppConstants.APP_NAME%>" method="get" id="ze-form">
                <input type="hidden" name="action" value="alocare-localitati"/>
                <input type="hidden" name="t" value="<%=System.currentTimeMillis()%>"/>
                <%=SortController.initSort(sd)%>

                <div class="pull-left mb5">
                    <label>
                        Căutare: <input type="text" name="search" id="search" value="<%=search%>"/>
                    </label>
                    <input type="submit" value="Caută"/>
                    <input type="button" value="Reset filtru" id="reset-filtru"/>
                </div>

                <table class="table" cellpadding=2 cellspacing=1 width="100%" >
                    <thead>
                    <tr>
                        <th>
                            <%=SortController.printSortableColumn("Judet", AlocareLocalitateCentru.Constants.JUDET, sd)%>
                        </th>
                        <th>
                            <%=SortController.printSortableColumn(CallcenterHelper.getConfiguration().getLabelLocalitate1(), AlocareLocalitateCentru.Constants.MUN, sd)%>
                        </th>
                        <th>
                            <%=SortController.printSortableColumn(CallcenterHelper.getConfiguration().getLabelLocalitate2(), AlocareLocalitateCentru.Constants.LOCALITATE, sd)%>
                        </th>
                        <th width="40" title="Dacă alocarea contine localitate conform nomenclator de localităţi">
                            <%=SortController.printSortableColumn("Corectă", AlocareLocalitateCentru.Constants.CORECTA, sd)%>
                        </th>
                        <th>
                            <%=SortController.printSortableColumn("Centru", AlocareLocalitateCentru.Constants.DEN_CE, sd)%>
                        </th>
                        <th width="200">Acţiuni</th>
                    </tr>
                    </thead>
                    <tbody>
                    <% if( alocari == null || alocari.length == 0 ){ %>
                    <tr>
                        <td colspan="5" class="no-data">Nu exista alocari ... </td>
                    </tr>
                    <% } else for (final AlocareLocalitateCentru alocare : alocari) { %>
                    <tr id="row<%=alocare.getId()%>">
                        <td>
                            <%=AppConstants.format(alocare.getJudet())%>
                        </td>
                        <td>
                            <%=AppConstants.format(alocare.getMunicipiu())%>
                        </td>
                        <td>
                            <%=AppConstants.format(alocare.getLocalitate())%>
                        </td>
                        <td style="color:<%=alocare.isCorecta()?"green":"red"%>" align="center">
                            <%=alocare.isCorecta()?"DA":"NU"%>
                        </td>
                        <td data-id="<%=alocare.getIdCentru()%>">
                            <%=AppConstants.format(alocare.getNumeCentru())%>
                        </td>
                        <td>
                            <nobr>
                                <a href="<%=AppConstants.APP_NAME%>?action=edit-alocare-localitate-ce&id=<%=alocare.getId()%>" class="link">Modifică</a> |
                                <a href="<%=AppConstants.APP_NAME%>?action=load-realocare-reclamatii&idAlocare=<%=alocare.getId()%>"
                                   class="link"
                                   title="Pentru repartizarea reclamatiilor inregistrate pe aceasta adresa la C.E. conform mapare. Se vor realoca reclamatiile neprocesate."
                                >Realocare reclamații</a> |
                                <a onclick="return confirm('Doriți să ștergeți alocarea ?');"
                                   href="<%=AppConstants.APP_NAME%>?action=delete-alocare-localitate-ce&id=<%=alocare.getId()%>"
                                   class="link" title="Ștergere alocare">Șterge</a>
                            </nobr>
                        </td>
                    </tr>
                    <%}%>
                    </tbody>
                    <tfoot>
                    <tr><td colspan="6" valign="middle">
                        <div class="pull-left">
                            <input type="button" value="Adaugă alocare nouă" data-href="<%=AppConstants.APP_NAME%>?action=edit-alocare-localitate-ce"/>
                        </div>
                        <div class="pull-right">
                            <%=PaginationController.printPaginationData(pd)%>
                        </div>
                    </td>
                    </tfoot>
                </table>
            </form>
        </td>
    </tr>
</table>

<script type="text/javascript">
    jQuery(function(){
        jQuery("#reset-filtru").click(function(){
            jQuery("#search").val("");
            jQuery("#ze-form").submit();
        });
    });
</script>

