<%--
  /**
   * Copyright (c) 2003 by Sun Microsystems, Inc. All rights reserved.
   * Use is subject to license terms.
   *
   * "@(#)jobs_general.jsp    1.32    03/05/30     SMI"
   * 
   */
 --%>
<%@ include file="/layout/toptags.jsp"%>
<!-- locale stuff -->
<html:html locale="true">
<!-- end locale -->

<!-- Place Java Script Here -->

<!-- HTML -->
<head>
<script language="JavaScript">
var refreshInterval=<bean:write name="JobsForm" property="autorefreshInt"/>;
var oldRefreshInt=refreshInterval;
function submitJobsForm(bi) {
     document.forms[0].beginIndex.value=bi;
     document.forms[0].prev_next_pressed.value="true";
     oldRefreshInt=1;
     submitForm("show");
}
function changeFilter() {
     document.forms[0].beginIndex.value=0;
     oldRefreshInt=1;
     submitForm("show");
	
}
function doRefresh() {
   //refreshInterval=document.forms[0].autorefreshInt.value;
   refreshInterval=document.forms[0].autorefreshInt[document.forms[0].autorefreshInt.selectedIndex].value; 
   if(refreshInterval > oldRefreshInt && oldRefreshInt != 0) {
   	oldRefreshInt=refreshInterval;
   } else {
	if(refreshInterval != 0 && formSubmitted == 0) {
   		submitForm("show");
	} 
   }
}
function setAutoRefresh() {
   //refreshInterval=document.forms[0].autorefreshInt.value;
   refreshInterval=document.forms[0].autorefreshInt[document.forms[0].autorefreshInt.selectedIndex].value; 
   window.setTimeout(doRefresh, refreshInterval*1000);
}

</script>

<%@include file="/layout/page_head_section.jsp"%>
	<title>
		<bean:message  key="jobs.general.title"/>
	</title>
</head>
<%@ include file="/layout/bodytag.jsp"%>
<html:form action="/root.menu.item4.item0.do">
<%@include file="/layout/top.jsp"%>
<%@include file="/layout/breadcrumb.jsp"%>
<%@include file="/layout/spacer.jsp"%>
<%@include file="/layout/user_messages.jsp"%>


<% boolean hasList = false;%>
<logic:present name="<%=Constants.HttpSessionFields.JOBS_LIST_PARAM%>"> 
<%
  if (((List)request.getSession().getAttribute(Constants.HttpSessionFields.JOBS_LIST_PARAM)).size() > 0 ){
    hasList = true;
  }
  
%>
</logic:present>

<%try {
  selectedSubItem="root.menu.item4.item0";
com.sun.netstorage.array.mgmt.cfg.ui.forms.JobsForm myform = (com.sun.netstorage.array.mgmt.cfg.ui.forms.JobsForm)session.getAttribute("JobsForm");
%>


<!-- hidden element which specifies the action for this form -->
<input type="hidden" name="action" value="<%=request.getAttribute("action")%>">
<input type="hidden" name="beginIndex" value="<%=request.getParameter("beginIndex")%>">
<input type="hidden" name="prev_next_pressed" value="">
<div class="content-layout">
<! -- title -->
<%if(myform.getJobListFilter() == Constants.JobTypes.ALL) { %>
<jsp:include page="/layout/section_header.jsp" flush="true">
	<jsp:param name="sectionname" value="jobs.general.alljobs" />
</jsp:include>
<% } else {%>
<jsp:include page="/layout/section_header.jsp" flush="true">
	<jsp:param name="sectionname" value="jobs.general.outstandingjobs" />
</jsp:include>

<% } %>
<table>
          <tr width="100%">
            <td >
	    	<bean:message key="jobs.inlinehelp"/>
	    </td>
          </tr>
          <tr width="100%">
            <td nowrap ><img alt border="0" src="images/general/dot.gif" width="1" height="5"></td>
          </tr>
</table>

  <!-- Button row -->
  <table border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td nowrap>
      	<table border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td align="left">
              <table border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td>
                    <component:button text="jobs.general.killjob" href="javascript:submitForm('killjobsconfirm');" title="jobs.general.killjob.title" isEnabled="<%=!readOnly && hasList %>" />
				  </td>
				  <td>
				  	<img width="10" height="1" border="0" src="images/general/dot.gif">
				  </td>
				  <td>
				    <component:button text="jobs.general.deletejobs" href="javascript:submitForm('deletejobsconfirm')" title="jobs.general.deletejobs.title" isEnabled="<%=!readOnly && hasList && (myform.getJobListFilter() == Constants.JobTypes.ALL) %>" />
				  </td>
				  <td>
				  	<img width="10" height="1" border="0" src="images/general/dot.gif">
				  </td>
				  <td>
                    <!-- refresh button is available to all users -->
				    <component:button text="jobs.general.refreshlist" href="javascript:submitForm('show')" title="jobs.general.refreshlist.title" isEnabled="<%=true%>" />
				  </td>
				  <td>
				  	<img width="10" height="1" border="0" src="images/general/dot.gif">
				  </td>
            <td nowrap>
              <html:select property="jobListFilter" onchange="changeFilter()">
            	<html:option key="jobs.general.alljobs" value="<%=Integer.toString(Constants.JobTypes.ALL)%>"/>
            	<html:option key="jobs.general.outstandingjobs" value="<%=Integer.toString(Constants.JobTypes.OUTSTANDING)%>"/>
              </html:select>
				</td>
				  <td>
				  	<img width="10" height="1" border="0" src="images/general/dot.gif">
				  </td>
<td nowrap >
              <html:select property="autorefreshInt" onchange="setAutoRefresh()">
            	<html:option key="jobs.autorefresh.30" value="30"/>
            	<html:option key="jobs.autorefresh.60" value="60"/>
            	<html:option key="jobs.autorefresh.0" value="0"/>
              </html:select>
	    </td>

				</tr>
		      </table>
		    </td>
		  </tr>
		</table>  
      </td>
    </tr>
  </table>
  <!-- end button row-->
  <%@include file="/layout/spacer.jsp"%>

<table>      
  <%@include file="/layout/prevnext.jsp"%>   
 <tr>
  <td nowrap>
   <table class="back-table" border="0" cellspacing="0" cellpadding="1" width-"100%">
    <tr>
      <td>
        <table class="front-table" border="0" cellspacing="0" cellpadding="0" width="100%">
          <tr class="header-row">
            <td align="center" valign="middle" nowrap><a href="javascript:checkAll(document.forms[0])"><img src="images/icons/select-all-small.gif" alt='<bean:message key="table.select.all"/>' vspace="2" border="0" width="11" height="13"></a><a href="javascript:unCheckAll(document.forms[0])"><img src="images/icons/deselect-all-small.gif" alt='<bean:message key="table.deselect.all"/>' vspace="2" border="0" width="11" height="13"></a></td>
            <td nowrap>
              <div class="table-header-text">
                <bean:message key="jobs.general.jobid" />
              </div>
            </td>
            <td nowrap>
              <div class="table-header-text">
                <bean:message key="jobs.general.array" />
              </div>
            </td>
            <td nowrap>
              <div class="table-header-text">
                <bean:message key="jobs.general.description" />
              </div>
            </td>
            <td nowrap>
              <div class="table-header-text">
                <bean:message key="jobs.general.percentcomplete" />
              </div>
            </td>
            <td nowrap>
              <div class="table-header-text">
                <bean:message key="jobs.general.status" />
              </div>
            </td>
          </tr>
          <logic:present name="<%=Constants.HttpSessionFields.JOBS_LIST_PARAM%>"> 
           <%@include file="/layout/listingCalc.jsp"%>
           <logic:iterate id="job" indexId="index" name="<%=Constants.HttpSessionFields.JOBS_LIST_PARAM%>" type="com.sun.netstorage.array.mgmt.cfg.jobs.business.JobInterface" offset='<%=offsetStr%>' length='<%=lengthStr%>'>
          <tr>
            <td align="center">
              <div class="table-normal-text">
	      <%  com.sun.netstorage.array.mgmt.cfg.jobs.business.JobInterface jobInt = 
	      			(com.sun.netstorage.array.mgmt.cfg.jobs.business.JobInterface)
				pageContext.getAttribute("job");

	      	String jobDesc = jobInt.getDescription();
		//prevent canceling of running volume job or delete pool job
	      if(!((jobDesc != null && !(jobDesc.indexOf("job.description.createvolume") < 0 &&
	      	 jobDesc.indexOf("job.description.deletevolume") < 0 &&
		 jobDesc.indexOf("job.description.deletepool") < 0) && 
		 jobInt.getStatusKey()!= null &&
		 jobInt.getStatusKey().equals("job.status.running")))) {
		 %>
                <input <% if(readOnly) {%>disabled <% } %> type="checkbox" name="id" value="<%=index%>">
		<% } else {%>
		&nbsp;
		<% } %>
              </div>
            </td>
            <td>
              <div class="table-normal-text">
                <html:link href="root.menu.item4.item0details.do"
                 paramId="jobid" paramName="job" paramProperty="id">
                  <bean:write name="job" property="id"/>
                </html:link>
              </div>
            </td>
            <td>
              <div class="table-normal-text">
                <bean:write name="job" property="array" />
              </div>
            </td>
            <td>
              <div class="table-normal-text">
                <component:partialTextDisplay textLength="35" 
                text='<%=((com.sun.netstorage.array.mgmt.cfg.jobs.business.JobInterface)pageContext.getAttribute("job")).getDescription()%>' />
              </div>
            </td>
            <td align="right">
              <div class="table-normal-text">
                <bean:write name="job" property="percentComplete"/>
              </div>
            </td>
            <td>
              <div class="table-normal-text">
	        <%
 		String status = ((com.sun.netstorage.array.mgmt.cfg.jobs.business.JobInterface)
					pageContext.getAttribute("job")).getStatusKey();
		if(status != null && status.equals("job.status.error.done")) { %>
			<img src="images/icons/critical_10.gif" border="0" width="10" height="10"/>
		<% } else if(status != null && status.equals("job.status.dormant")){%>
			<img src="images/icons/major_10.gif" border="0"  width="10" height="10"/>
		<% } else if(status != null && status.equals("job.status.aborted.done")){%>
			<img src="images/icons/down_10.gif" border="0"/>
		<% } else if(status != null && status.equals("job.status.running")){%>
			<img src="images/icons/minor_10.gif" border="0" width="10" height="10"/>
		<% } else if(status != null && status.equals("job.status.ok.done")){%>
			<img src="images/icons/success_10.gif" border="0" width="10" height="10"/>
		<% } %>
                <component:partialTextDisplay textLength="35" 
                text='<%=((com.sun.netstorage.array.mgmt.cfg.jobs.business.JobInterface)pageContext.getAttribute("job")).getStatusKey()%>' />
              </div>
            </td>
          </tr>
          </logic:iterate>
        </logic:present>
        </table>
      </td>
    </tr>
   </table>
  </td>
 </tr>
 <%@include file="/layout/prevnext.jsp"%>
</table>

  <!-- put spacer in table to avoid problem in netscape 7.0 where the page was -->
  <!-- too wide for no good reason.  this fixes it for no good reason. -->
  <table border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td>
        <%@include file="/layout/spacer.jsp"%>
      </td>
    </tr>
  </table>

</div>
<% } catch (Throwable t) {
        Trace.error(this, "jobs_general.jsp", "Page exception:" + t);
   } %>

</html:form>
<script>
window.setTimeout(setAutoRefresh, 3000); 
</script>
</body>

</html:html>
