<%--
  -- @(#)events.jsp	1.6 05/08/02
  -- Copyright 2001 Sun Microsystems, Inc., All Rights Reserved.
  -- A page to display the events.
  -- @version 1.6, 05/08/02
  -- @author  Pascal Ledru
  --
  --%>

<%@ page language="java" contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/tlds/app.tld" prefix="app" %>
<%@ taglib uri="/WEB-INF/tlds/component.tld" prefix="component" %>
<%@ taglib uri="/WEB-INF/tlds/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/tlds/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/tlds/component.tld" prefix="component" %>
<%@ page import="com.sun.jade.web.util.BreadCrumbBean" %>

<html:html locale="true">

<script language="JavaScript1.2" src="../js/checkbox.js">
</script>
<script language="JavaScript1.2" src="../js/util.js">
</script>


<script language="JavaScript">

  function LinkUpForSearch(theForm) {
          document.eventListForm.submitControl.value = "Search";
          document.eventListForm.submit();
  }

  function validate() {
    ret = numOfChecked(document.eventListForm, "id");
    if(document.eventListForm.submitControl.value == "Ack") {
      if (ret[0] == 0) {
        alert('<bean:message key="note.atLeastOneAlarmToAcknowledge"/>');
        return false;
      }   
    }

    return true;
   }
   
   function sort(sortedProp, sortRule, tableIndex) {
      document.eventListForm.sortedProperty.value = sortedProp;
      document.eventListForm.sortRule.value   = sortRule;
      document.eventListForm.submit();
   }

   function direction(dir) {
    document.eventListForm.Direction.value = dir;
    document.eventListForm.submitControl.value = "Direction";
    document.eventListForm.submit();
   }
   function go() {
    document.eventListForm.submitControl.value = "Go";		
    document.eventListForm.submit();
   }
</script>


<app:contentState/>
<app:eventState mode="alarms"/>

<app:eventLog mode="alarms"/>
<% 
   String sortedProperty = request.getParameter("sortedProperty");
   String sortRule = request.getParameter("sortRule");
   String severity = request.getParameter("Severity");
   if(sortedProperty == null) sortedProperty = "severity";
   if(sortRule == null) sortRule = "desc";
   if(severity == null) severity = "all";
%>


<app:sortOption/>
<jsp:setProperty name="sortOption" property="beanListName" value="events"/>
<jsp:setProperty name="sortOption" property="beanClassName" value="com.sun.jade.web.notification.Event"/>
<jsp:setProperty name="sortOption" property="propertyList" value="severity,sourceTime,isCleared,device,deviceType,topic,shortDescription"/>
<jsp:setProperty name="sortOption" property="sortedProperty" value="<%=sortedProperty%>"/>
<jsp:setProperty name="sortOption" property="sortRule" value="<%=sortRule%>"/>
<app:sort/>

 
<% 
   String mode = com.sun.jade.web.util.ElementFinder.getMode(request);
   String category = com.sun.jade.web.util.ElementFinder.getCategory(request);
   String OID = com.sun.jade.web.util.ElementFinder.getOID(request);
   String deviceType = request.getParameter("Device");
   String topic = request.getParameter("Topic");
   String closedAlarm    = request.getParameter("closedAlarm");
   String openAlarm      = request.getParameter("openAlarm");
   String ackedAlarm     = request.getParameter("ackedAlarm");
   String unackedAlarm   = request.getParameter("unackedAlarm");

   if(closedAlarm == null) closedAlarm = (String) session.getAttribute("closedAlarmState");
   if(openAlarm == null) openAlarm = (String) session.getAttribute("openAlarmState");
   if(ackedAlarm == null) ackedAlarm = (String) session.getAttribute("ackedAlarmState");
   if(unackedAlarm == null) unackedAlarm = (String) session.getAttribute("unackedAlarmState");
%>

<jsp:include page="header.jsp"/>

<body bgcolor="#FFFFFF" leftmargin="0" marginwidth="0" marginheight="0" topmargin="0">

  <jsp:include page="masthead.jsp">
    <jsp:param name="category"    value="alarms"/>
    <jsp:param name="subCategory" value="<%=severity%>"/>
  </jsp:include>


<% if("Device".equals(mode)) { %>

<app:breadCrumb/>

<% } %>
<%
    java.util.ArrayList breadCrumb = new java.util.ArrayList();

    if("Device".equals(mode)) {
        BreadCrumbBean bcb1 = new BreadCrumbBean();	
        BreadCrumbBean bcb2 = new BreadCrumbBean();		
        bcb1.setDisplayName("allDevices");
        bcb1.setLink("/jade/jsp/alarms.jsp?useEventState=no&mode=Summary");
        breadCrumb.add(bcb1);
        bcb2.setDisplayName(category);
        bcb2.setLink("/jade/jsp/alarms.jsp?useEventState=no&mode=Category&category=" + category);
        breadCrumb.add(bcb2);
    
        java.util.ArrayList breadCrumb_dev = (java.util.ArrayList) pageContext.getAttribute("BreadCrumbBeanList");
        for( int i = 0; i < breadCrumb_dev.size() - 1; i ++ ) {
           BreadCrumbBean bcb_dev = (BreadCrumbBean)breadCrumb_dev.get(i);
           bcb_dev.setLink("/jade/jsp/alarms.jsp?useEventState=no&mode=Device&OID=" + bcb_dev.getOidName());
           breadCrumb.add(bcb_dev);
        }
        breadCrumb.add(breadCrumb_dev.get(breadCrumb_dev.size()-1));
    } else if("Domain".equals(mode) || "Summary".equals(mode)) {
	BreadCrumbBean bcb1 = new BreadCrumbBean();		
        bcb1.setDisplayName("allDevices");
        breadCrumb.add(bcb1);
    } else if("Category".equals(mode)) {
	BreadCrumbBean bcb1 = new BreadCrumbBean();	
        BreadCrumbBean bcb2 = new BreadCrumbBean();		
        bcb1.setDisplayName("allDevices");
        bcb1.setLink("/jade/jsp/alarms.jsp?useEventState=no&mode=Summary");
        breadCrumb.add(bcb1);
        bcb2.setDisplayName(category);
        breadCrumb.add(bcb2);
    }

    pageContext.setAttribute("breadCrumbBeanList",breadCrumb);
%>

<component:breadCrumb beanListName = "breadCrumbBeanList" />

<form name="eventListForm" method=POST>
<input type=hidden name="submitControl" value="">

<input type=hidden name="mode" value="<%=mode%>">
<input type=hidden name="category" value="<%=category%>">
<input type=hidden name="OID" value="<%=OID%>">
<% if(severity != null) { %>
<input type=hidden name="Severity" value="<%=severity%>">
<% } %>
<% if(deviceType != null) { %>
<input type=hidden name="Device" value="<%=deviceType%>">
<% } %>
<% if(topic != null) { %>
<input type=hidden name="Topic" value="<%=topic%>">
<% } %>

<input type=hidden name="OldNumber" value="<bean:write name="currentPageNumber"/>">

<% if(closedAlarm != null) { %>
<input type=hidden name="closedAlarm" value="<%=closedAlarm%>">
<% } %>
<% if(openAlarm != null) { %>
<input type=hidden name="openAlarm" value="<%=openAlarm%>">
<% } %>
<% if(ackedAlarm != null) { %>
<input type=hidden name="ackedAlarm" value="<%=ackedAlarm%>">
<% } %>
<% if(unackedAlarm != null) { %>
<input type=hidden name="unackedAlarm" value="<%=unackedAlarm%>">
<% } %>
<% if(sortedProperty != null) { %>
<input type=hidden name="sortedProperty" value="<%=sortedProperty%>">
<% } %>
<% if(sortRule != null) { %>
<input type=hidden name="sortRule" value="<%=sortRule%>">
<% } %>
<input type=hidden name="Direction" value="no">

<DIV class="content-layout">
<table cellspacing="0" cellpadding="0" border="0">
<tr><td>

<component:bigHorizontalSpacer />
<div class="table-title-text"><bean:message key="title.alarmList"/></div>
<component:smallHorizontalSpacer />

<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td>
<component:buttonGroup formName="eventListForm" buttonNames="button.acknowledge"
	                       buttonValues="Ack" buttonChecks="no" controlName="submitControl" 
                               validateFunction="validate" buttonType="mini" buttonGroupIndex = "0" />
</td>
<td>
<IMG src="../images/dividerbar.gif" alt="Divider Bar" border="0" align="ABSMIDDLE">
</td>

<td>
  <%
     String context = (String)pageContext.getAttribute("pageContext");
     String link = "/jade/jsp/alarmFilter.jsp?" + context;
     String scriptLink = "javascript:openNewWindow(\'" + link + "\',\'alarmFilter\',\'width=540,height=420,resizable\')"; 
   %>

<A href=<%=scriptLink%>><IMG src="../images/filter.gif" alt="Open Table Filter in a New Window" border="0" align="ABSMIDDLE"></A>
</td>
<td>
   <bean:write name="filterStr" filter="false"/>	
</td>
</tr>
</table>

<component:smallHorizontalSpacer />
<component:table propertyList="severityIcon,date,clearIcon,device,deviceType,topic,shortDescriptionWithLinkForAlarm" 
                 categoryList="header.severity,header.date,header.state,header.device,header.deviceType,header.topic,header.description"
                 beanListName="events"
                 beanClassName="com.sun.jade.web.notification.Event" 
                 hasSort="yes"  width="100%"
                 hasCheckbox="yes" checkboxName="id" checkboxValue="eventID" 
		 wrap="nowrap,nowrap,nowrap,nowrap,nowrap,nowrap,nowrap"
	         align="center,left,center,left,left,left,left" 
                 emptyTableIndication="noAlarmsAvailable"
                 formName="eventListForm" sourcePage="javascript:sort" />  


<table border="0" cellspacing="0" width="100%">
<tr>
<td align="center">
        <table border="0" cellspacing="0" cellpadding="4">
          <tr valign="middle"> 
            <!-- Cell containing up button graphics -->
	    <logic:equal name="isBack" value="true">
            <td align="right"><a href='javascript:direction("backwardtofirst");'><img src="../images/upend.gif" width="19" height="19" border="0" alt="First Page"></a> <a href='javascript:direction("backward");'><img src="../images/up.gif" width="19" height="19" border="0" alt="Previous Page"></a></td>
	    </logic:equal>
            <logic:equal name="isBack" value="false">
            <td align="right"><img src="../images/upend_disabled.gif" width="19" height="19" border="0" alt="First Page"></a><img src="../images/up_disabled.gif" width="19" height="19" border="0" alt="Previous Page"></a></td>
	    </logic:equal>
            <td align="center"> 
              <!-- Begin table containing text input field and Go button -->
              <table border="0" cellspacing="8" cellpadding="0">
                <tr valign="middle"> 
                  <td nowrap> <span class="table-vertpag-label-text">Page:</span> 
                    <input type="text" name="pageNumber" maxlength="4" value='<bean:write name="currentPageNumber"/>' size="4">
                    <span class="table-vertpag-pages-text">of <bean:write name="totalPageNumber"/></span> </td>
                  <td>
                    <!-- Begin Go button outer table -->
                    <component:buttonGroup formName="null" buttonNames="button.go"
	                       buttonValues="javascript:go()" buttonChecks="no" controlName="null" 
                               buttonType="regular" buttonGroupIndex="1" />
                    <!-- End Go button outer table -->
                  </td>
                </tr>
              </table>
              <!-- End table containing text input field and Go button -->
            </td>
            <!-- Cell containing down button graphics -->
	    <logic:equal name="isForward" value="true">
            <td align="left"><a href='javascript:direction("forward");'><img src="../images/downPagination.gif" width="19" height="19" border="0" alt="Next Page"></a> <a href='javascript:direction("forwardtolast");'><img src="../images/downend.gif" width="19" height="19" border="0" alt="Last Page"></a></td>
	    </logic:equal>
            <logic:equal name="isForward" value="false">
            <td align="left"><img src="../images/down_disabled.gif" width="19" height="19" border="0" alt="Next Page"></a><img src="../images/downend_disabled.gif" width="19" height="19" border="0" alt="Last Page"></a></td>
	    </logic:equal>
          </tr>
        </table>
</td>
</tr>
</table>      

</td></tr>
</table>
</DIV>

</form>
</body>
</html:html>

