<%--
  /**
   * Copyright (c) 2003 by Sun Microsystems, Inc. All rights reserved.
   * Use is subject to license terms.
   *
   * "@(#)sm_chgprofilewiz_selecttrays.jsp    1.22    03/06/02     SMI"
   * 
   */
 --%>
<%@ include file="/layout/toptags.jsp"%>
<html:html>

<head>
<%@include file="/layout/page_head_section.jsp"%>
</head>

<%@ include file="/layout/wizard_body_tag.jsp" %>
<html:form action="/ChangeProfileWizard.do">
<%@ include file="/wizard/wizard_framework_fields.jsp"%>

<div class="content-layout">

<%@ include file="/layout/user_messages.jsp"%>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr class="wizard-content-title-row">
    <td>
      <div class="wizard-content-title-text"> <bean:message key="storage.mgmt.system.chgprofile.wizard.deselect"/>
      </div>
    </td>
  </tr>
  <tr>
    <td class="wizard-content-divider"><img alt width="1" height="1" src="/image
s/general/dot.gif" border="0"></td>
  </tr>
</table>


 <!-- spacer between two sections -->
<table bgcolor="#ffffff" border="0" cellpadding="0" cellspacing="0" width="100%">
  <tr>
    <td><img alt border="0" height="20" width="1" src="images/general/dot.gif"></td>
  </tr>
</table>
<%
      String profileName = 
        ((ProfileForm)session.getAttribute("Profile")).getNewProfileName();
      MessageResources messages = 
		    (MessageResources) application.getAttribute(Action.MESSAGES_KEY);
      String localizedProfileName =
         "<b>" + messages.getMessage(request.getLocale(), profileName) + "</b>"; 
%>

<!-- if there are no trays available, show info message -->
<logic:notPresent name="Profile" property="traysWithSpace">
<table width="80%">
  <tr><td width="100%">
    <table border="0" cellspacing="0" cellpadding="2" align="left" bgcolor="#9999CC" width="100%">
      <tr><td>
        <table cellspacing="0" cellpadding="5" border="0"  bgcolor="#FFFFFF" width="100%">
          <tr>
            <td valign="top"><img src="images/icons/info_16.gif" width="16" height="16" alt='<bean:message key="icon.warning"/>' border="0"></td>
            <td><div class="error-message-header-text">
                  <bean:message key="storage.mgmt.system.chgprofile.wizard.notrays" arg0="<%=localizedProfileName%>"/>
                </div>
          </tr>
        </table>
      </td></tr>
    </table>
  </td></tr>
  <tr><td>
    <img src="images/general/dot.gif" width="1" height="10" border="0">
  </td></tr>
</table>
</logic:notPresent>

<!-- otherwise, show the tray listing -->
<logic:present name="Profile" property="traysWithSpace"> 

<%@ page import="com.sun.netstorage.array.mgmt.cfg.ui.forms.ProfileForm"%>
  <!-- spacer between two sections -->
<table bgcolor="#ffffff" border="0" cellpadding="0" cellspacing="0" width="100%">
  <tr>
        <td><bean:message key="storage.mgmt.system.chgprofile.wizard.traydirections" arg0="<%=localizedProfileName%>"/>          
    </td>
  </tr>
  <tr>
    <td><img alt border="0" height="20" width="1" src="images/general/dot.gif"></td>
  </tr>
  <tr>
  	<td>
	  <bean:message key="storage.mgmt.system.chgprofile.wizard.selectinfo" />          
	</td>
  </tr>
</table>


<!-- spacer between two sections -->
<table bgcolor="#ffffff" border="0" cellpadding="0" cellspacing="0" width="100%">
  <tr>
    <td><img alt border="0" height="20" width="1" src="images/general/dot.gif"></td>
  </tr>
</table>

<!-- BEGIN SECTION:  variable length table populated with items contained in major
                     object displayed on this page -->
<!-- OPTIONAL section, dependig on purpose of page -->
<!-- NOTE:  the buttons above the table are optional.  They exist on pages where
            they are required.  If the buttons are not there, then the first column
            with the checkboxes also has to be removed -->
  <table border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>
      <td>
        <table border="0" cellpadding="0" cellspacing="0" width="100%">
          <tr>

            <td nowrap>
              <div class="major-category-text">
                <bean:message key="storage.mgmt.system.profile.wizard.tray.section" arg0='<%=((T4Interface)session.getAttribute(Constants.HttpSessionFields.CURRENT_T4)).getName()%>'/>                
              </div>
            </td>
            <td valign="bottom" width="99%">
              <table border="0" cellpadding="0" cellspacing="0" width="100%">
                <tr>
                  <td class="property-separator" valign="bottom"><img alt border="0" height="2" src="/images/general/dot.gif" width="1"></td>

                </tr>
              </table>
            </td>
          </tr>
        </table>
      </td>
    </tr>
    <tr>
      <td><img alt border="0" height="5" src="/images/general/dot.gif" width="1"></td>

    </tr>
  </table>
  <table border="0" cellpadding="0" cellspacing="0" width="100%">
    
    <tr>
      <td><img alt border="0" height="5" src="/images/general/dot.gif" width="1"></td>

    </tr>
  </table>
  
  <!-- whole tray listing table-->
  <table border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td nowrap>
        <table border="0" cellspacing="0" cellpadding="0">          
          <tr>
            <td><img alt width="1" height="2" border="0" src="images/general/dot.gif"></td>
          </tr>           
          <tr>
            <td nowrap>
              <table class="back-table" border="0" cellspacing="0" cellpadding="1">
                <tr>
                  <td>
                    <table class="front-table" border="0" cellspacing="0" cellpadding="0">
                      <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="tray.table.id"/>
                          </div>
                        </td>      
                        <td nowrap>
                          <div class="table-header-text">
                            <bean:message key="tray.table.drivenum.short"/> 
                          </div>
                        </td>       
                        <td nowrap>
                          <div class="table-header-text">
                            <bean:message key="tray.table.drivecapacity"/> 
                          </div>
                        </td>           
                        <td nowrap>
                          <div class="table-header-text">
                           <bean:message key="tray.table.hotspare"/> 
                          </div>
                        </td>
                        <td nowrap>
                          <div class="table-header-text">
                           <bean:message key="tray.table.driveavailable"/> 
                          </div>
                        </td>                        
                        <td nowrap>
                          <div class="table-header-text">
                            <bean:message key="tray.table.drivetoallocate"/> 
                          </div>
                        </td>
                      </tr>
                      <!-- Begin tray row listing(s) -->              
                                                              
 				 	    <logic:iterate id="trayW" name="Profile" property="traysWithSpace" type="TrayWrapper" indexId="idx"> 				 	      
 <%                                   
                                   //int avail = trayW.getTray().getNumberOfDrives() - trayW.getTray().getNumberOfHotSpare();                           
                                   List possibleDrives = trayW.getPossibleDrivesToAdd();
                                      
                                   int avail = 0;
                                   avail = ((Integer)possibleDrives.get(possibleDrives.size()-1)).intValue(); 
				   if(avail >= 3) {
                                %>

                          <tr>           
                            <td>
                              <logic:present name="Profile" property="trayIndicesToConfigure">
                                 <%
                                    boolean shouldCheck = false;
                                    if(((ProfileForm)session.getAttribute("Profile")).getTrayIndicesToConfigure().contains(idx)) {
                                       shouldCheck = true; 
                                    }
                                 %>
                                 <input <% if(shouldCheck) {%>checked <% } %> type="checkbox" name="tray<%=idx%>" value="<%=idx%>">
                              </logic:present>
                              <logic:notPresent name="Profile" property="trayIndicesToConfigure">
                                 <input checked type="checkbox" name="tray<%=idx%>" value="<%=idx%>">
                              </logic:notPresent>
                            </td>                  
                            <td>     
                              <div class="table-label-text">                    
                                <bean:write name="trayW" property="tray.id"/>
                              </div>
                            </td>     
                            <td>  
                              <div class="table-label-text">                        
			      <% int numOfDrives = trayW.getTray().getNumberOfDrives(); %>
			      <%=numOfDrives%>
			      <% /*
                                <bean:write name="trayW" property="tray.numberOfDrives"/>
				*/ %>
                              </div>
                            </td>                    
                            <td>        
                              <div class="table-label-text">                  
                                <%=nf.format(nf.parse(Convert.bytesToGB(trayW.getTray().getDriveCapacity())))%>        
                                <bean:message key="size.GB"/>                        
                              </div>
                            </td>      
                            <td>    
                              <div class="table-label-text">                      
                                <bean:write name="trayW" property="tray.numberOfHotSpare"/>
                              </div>
                            </td> 
                            <td>
                              <div class="table-label-text">
                                 <%= avail %>
                              </div>
                            </td>
                           
                            <td>                         
                              <div class="table-label-text"> 
                                <select name="numdrives<%=idx%>">    
                                  <%
				     if(avail+1 != numOfDrives) {
				     %>
				     	<option><%=avail%> 
				  <%   } else {
                                      java.util.Hashtable trayObjsToConfigure = 
                                       ((ProfileForm)session.getAttribute("Profile")).getTraysToConfigureHash();
                                      TrayWrapper t = null;
                                      if(trayObjsToConfigure != null) {
                                         List trayIdxs = 
                                           ((ProfileForm)session.getAttribute("Profile")).getTrayIndicesToConfigure();
                                         // if we're on a tray previously selected 
                                         if(trayIdxs.contains(idx)) {
                                             // get the tray wrapper with the current tray id
                                             t = (TrayWrapper)trayObjsToConfigure.get(trayW.getTray().getId());
                                         }
                                      }
                                      for(int j = 0; j < possibleDrives.size(); j++) {
                                      	int drive = ((Integer)possibleDrives.get(j)).intValue();
                                        // if the tray wrapper is not null, then
                                        //  the back button was pressed and we have
                                        //  the selected drives to add already
                                        if(t != null) {
                                           if(t.getDrivesToAdd() == drive) { 
                                  %>
 	    	                                  <option selected><%=drive%>
                                  <%       } else {  %>
 	    	                                  <option><%=drive%>
                                  <%
                                           }
                                        }  else { 
                                           // otherwise, no data has been selected yet,
                                           //  so preselect the maximum value by default
                                           if(drive == 
                                                ((Integer)possibleDrives.get(
                                                   possibleDrives.size()-1)).intValue()) {
                                  %>
 	    	                                   <option selected><%=drive%>
                                  <%       } else { %>
                                              <option><%=drive%>
                                  <%
                                           }
                                        }
                                      }// end for
				    }// end else 
 	    	                    %>
                                  <select> 

                                
                              </div>
                            </td>
                         </tr>
			 <% } %>
                        </logic:iterate>                                                                                                                              
                                  
                    </table>
                  </td>
                </tr>             
              </table>
            </td>
          </tr>           
        </table>
      </td>
    </tr>
  </table> <!-- end whole tray table listing -->


</logic:present>   

</div>

</html:form>
</body>

</html:html>
