<%@ page import="ro.emid.common.constants.AppConstants" %>
<%@ page import="ro.emid.common.constants.EvenimentDispecerConstants" %>
<%@ page import="ro.emid.common.types.EvenimentDispecer" %>
<%@ page import="ro.emid.common.types.User" %>
<%@ page import="ro.emid.common.utils.*" %>
<%@ 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.lpod.action.dispecer.DeleteEvenimentDispecerAction" %>
<%@ page import="ro.emid.lpod.action.dispecer.EditEvenimentDispecerAction" %>
<%@ page import="java.util.List" %>

<%@ taglib prefix="emid" tagdir="/WEB-INF/tags" %>

<%

    /**
     * lista-evenimente-dispecer
     * @see ro.emid.lpod.action.dispecer.ListaEvenimenteDispecerAction
     */

    final User user = SessionUtils.getUserLogat(session);

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

    final List<EvenimentDispecer> list = (List<EvenimentDispecer>) request.getAttribute("list");
%>

<emid:template-od title="Lista evenimente">
    <jsp:attribute name="breadcrumb">
        <emid:localizare-od>
            <span class="slash">/</span> Evenimente dispecer
        </emid:localizare-od>
    </jsp:attribute>
    <jsp:attribute name="body">

        <form name="zaforma" action="<%=AppConstants.APP_NAME%>?action=lista-evenimente-dispecer" method=post>
            <%=SortController.initSort(sd)%>
            <DIV id=divFiltru>


                <% final long nr = RequestUtils.getLong(request, "numar", -1); %>
                Numar F.D.: <INPUT class=gsapinputtext name="numar" value="<%= nr != -1 ? String.valueOf(nr) : ""%>" >&nbsp;
                <INPUT style="FONT-SIZE: 11px" type="submit" value="Caută">

                <% if ( AppConstants.runAtFiliala() && UserUtils.hasRoleUtilizatorOperatiuniDispecer(user)){%>
                &nbsp;&nbsp;<input style=" FONT-SIZE: 11px;"  type="button" onclick="window.location = '<%=AppConstants.APP_NAME%>?action=edit-eveniment-dispecer'; " value="Adaugă eveniment">
                <% } %>
            </DIV>

            <div class="spacer"></div>

            <table class="table" cellspacing=1 cellpadding=2 width="100%">
                <thead>
                <tr>
                    <th nowrap colSpan=2 height=25><%=SortController.printSortableColumn("Eveniment:", EvenimentDispecerConstants.SQL.ID, sd)%></th>
                    <th nowrap height=25 width="100"><%=SortController.printSortableColumn("Autor:", EvenimentDispecerConstants.SQL.USER_INSERT, sd)%></th>
                    <th nowrap height=25 width="100"><%=SortController.printSortableColumn("Modificat:", EvenimentDispecerConstants.SQL.USER_UPDATE, sd)%></th>
                    <th nowrap height=25 width="150"><%=SortController.printSortableColumn("Data producerii:", EvenimentDispecerConstants.SQL.DATA_PRODUCERE, sd)%></th>
                    <th nowrap height=25 width="150"><%=SortController.printSortableColumn("Data realimentare:", EvenimentDispecerConstants.SQL.DATA_REALIMENTARE, sd)%></th>
                    <th nowrap width="1%">Operatie:</th>
                </tr>
                </thead>
                <tbody>
                <% if( list == null || list.size() == 0){ %>
                <tr>
                    <td colspan="7" class="no-data"> Nu exista date ...</td>
                </tr>
                <% } else for (EvenimentDispecer item : list) { %>
                    <tr valign=top>
                        <td title="Numar Fisa Eveniment" width="20" align=middle><%=item.getNumar()%>
                        </td>
                        <td title="Localizare Eveniment">
                            &nbsp;
                            <% int z = 0; %>
                            <% if (!StringUtils.isZeroLength(item.getDenInstalatie())) {
                                z++; %>
                                    <span <%if (item.getIdInstalatie() <= 0) {%> style="color: red;"
                                                                                 title="Instalatia nu se regaseste in nomenclator" <% } %> >
                                        <%=StringUtils.getNullSafe(item.getDenInstalatie())%>, &nbsp;
                                    </span>
                            <% } %>

                            <% if (!StringUtils.isZeroLength(item.getDenInstalatie2())) {
                                z++;%>
                                    <span <%if (item.getIdInstalatie2() <= 0) {%> style="color: red;"
                                                                                  title="Instalatia nu se regaseste in nomenclator" <% } %> >
                                        <%=StringUtils.getNullSafe(item.getDenInstalatie2())%>
                                    </span>
                            <% } %>

                            <% if (z == 0) { %>
                                    <span style="color: red;">
                                        Fara instalatie selectata ...
                                    </span>
                            <% } %>
                        </td>
                        <td title="Autor" align="center"><%=item.getUserInsert()%>
                        </td>
                        <td title="Modificat" align="center"><%=AppConstants.format(item.getUserUpdate())%>
                        </td>
                        <td title="Data producere"
                            align="center"><%=DateUtils.format(item.getDataProducere(), DateUtils.RO.DATE_TIME_FORMAT)%>
                        </td>
                        <td title="Data realimentare"
                            align="center"><%=DateUtils.format(item.getDataRealimentare(), DateUtils.RO.DATE_TIME_FORMAT)%>
                        </td>
                        <td nowrap align=left>
                            <% if (AppConstants.runAtFiliala()) { %>
                            <% if (UserUtils.hasRoleUtilizatorOperatiuniDispecer(user)) { %>
                            <a class="link" href="<%=EditEvenimentDispecerAction.buildUrl( item.getId())%>">Modifică</a>
                            <a class="link" title="Sterge Eveniment" onclick="return confirm('Stergeti evenimentul ?')"
                               href="<%=new DeleteEvenimentDispecerAction().buildUrl( item.getId())%>">Șterge</a>
                            <% } %>
                            <a class="link" href="#" onclick="print( <%=item.getId()%>)">
                                <%= UserUtils.hasRoleViewOperatiuniDispecer(user) ? "Vizualizare" : "Printează"%>
                            </a>
                            <% } else { %>
                            <a class="link" href="#" onclick="print( <%=item.getId()%>)">Vizualizare</a>
                            <% } %>
                        </td>
                    </tr>
                <% }%>
                </tbody>
                <tfoot>
                <tr>
                    <td colspan="7">
                        <div class="pull-left">
                            <% if (AppConstants.runAtFiliala() && UserUtils.hasRoleUtilizatorOperatiuniDispecer(user)){%>
                            &nbsp; <input type="button" data-href="<%=AppConstants.APP_NAME%>?action=edit-eveniment-dispecer" value="Adaugă Eveniment"/>
                            <% } %>
                        </div>
                        <div class="pull-right">
                            <%=PaginationController.printPaginationData( pd)%>
                        </div>
                    </td>
                </tr>
                </tfoot>
            </table>
        </form>
    </jsp:attribute>
</emid:template-od>

<script type=text/javascript>
    var printWindow = null;
    function print( id){
        if( printWindow != null) printWindow.close();
        printWindow = window.open('<%=AppConstants.APP_NAME%>?action=print-eveniment&id=' + id);
    }
</script>

