<%@ page import="ro.emid.common.constants.AppConstants" %>
<%@ page import="ro.emid.Application" %>
<%@ page import="ro.emid.lib.model.Maifi" %>
<%@ page import="java.util.ArrayList" %>

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

<%
	Maifi[] list = (Maifi[])request.getAttribute("maifiList");
	int total = Integer.parseInt(request.getAttribute("total").toString());
	
	int f = Integer.parseInt(request.getAttribute("start").toString());
	int l = Integer.parseInt(request.getAttribute("stop").toString());
	
	int f_prev = f == 1 ? 1 : (l == total ? ((f  - (f % 15)) - 14) : f - 15  );
	int l_prev = f == 1 ? 15 : ( l == total ? (l  - (l % 15)) : l - 15  );
	
	int f_last = total % 15 == 0 ? (total - 15) : (((total / 15) * 15) + 1);
	int l_last = total;
	
	int f_next = (l + 15) >= total ? f_last : (f + 15);
	int l_next = (l + 15) >= total ? l_last : (l + 15);
	
	
%>
<emid:template-od title="Lista evenimente">
    <jsp:attribute name="breadcrumb">
        <emid:localizare-od>
            <span class="slash">/</span> MAIFI
        </emid:localizare-od>
    </jsp:attribute>
    <jsp:attribute name="body">
		<table border="0" cellpadding="2" cellspacing="1" width="100%" class="table">
			<thead>
				<tr>
					<td colspan="2">Eveniment accidental:</td>
					<td>Autor:</td>
					<td>Modificat:</td>
					<td>Data producerii:</td>
					<td style="width:12%;">Operatie:</td>
				</tr>
			</thead>
			
			<tbody>
				<% for(int i = 0; i < list.length; i++) {
					Maifi mf = list[i];
				%>
					<tr>
						<td align="center" width="15" title="Numar Fisa Eveniment accidental"><%=mf.getNumar()%></td>
						<td><%=mf.getDenInstalatie()%></td>
						<td><%=mf.getUserInsert()%></td>
						<td id="userUpdate"><%=mf.getUserUpdate()%></td>
						<td><%=mf.getDataProducere()%></td>
						<td>
							<a href="<%=AppConstants.APP_NAME%>?action=editMaifi&id=<%=mf.getId()%>">Modifica</a>&nbsp;&nbsp;
							<a href="javascript:">Printeaza</a>&nbsp;&nbsp;
							<a href="<%=AppConstants.APP_NAME%>?action=deleteMaifi&id=<%=mf.getId()%>">Sterge</a>
						</td>
					</tr>
				<%}%>
				<%=list.length == 0 ? "<tr><td colspan='6'>Niciun eveniment accidental inregistrat</td></tr>" : ""%>
			</tbody>
			<tfoot>
				<tr>
					<td colspan="3">
						&nbsp;
						<a class="btn" href="<%=AppConstants.APP_NAME%>?action=editMaifi">Adauga Maifi</a>
					</td>
					<td colspan="4">
						<%=f%> - <%=l%> din <%=total%>&nbsp;&nbsp;
						<a title="Prima pagina" class="btn" href="<%=AppConstants.APP_NAME%>?action=showMaifi&start=1&stop=15"><<</a>
						<a title="Precedenta pagina" class="btn" href="<%=AppConstants.APP_NAME%>?action=showMaifi&start=<%=f_prev%>&stop=<%=l_prev%>"><</a>
						<a title="Urmatoarea pagina" class="btn" href="<%=AppConstants.APP_NAME%>?action=showMaifi&start=<%=f_next%>&stop=<%=l_next%>">></a>
						<a title="Ultima pagina" class="btn" href="<%=AppConstants.APP_NAME%>?action=showMaifi&start=<%=f_last%>&stop=<%=l_last%>">>></a>
					</td>
				</tr>
			</tfoot>
		</table>
	</jsp:attribute>
</emid:template-od>

<script type="text/javascript">
jQuery(function($) {
	$('td#userUpdate').each(function(i, elm) {
		var text = $(this).html();
		if(text == 'null') {
			$(this).html("");
		}
	});
});
</script>