<%-- 
/**
  * Copyright (c) 2004 Red Hat, Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  * USA
  *
  * Component of: Red Hat Application Server
  * 
  * Initial Developers: Aizaz Ahmed
  *                     Vivek Lakshmanan
  *                     Andrew Overholt
  *                     Matthew Wringe
  * Developers: Greg Lapouchnian
  * 			Patrick Smith
  */
--%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>

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

    <!-- Content begins here -->

    <div id="form">

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

    <!-- Include the form itself -->
    <form class="createForm" action="<c:url value="/admin/createItem.do"/>" method="post">
    
    <div class="formheader">
        <span>Edit or Create an Item</span>
    </div>

    <div class="row">
        <span class="label"> Item Name: </span>
        <span class="formw">
		    <spring:bind path="command.name">
    			<input name="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>" size="55"/> <br>
		    	<span class="error"><c:out value="${status.errorMessage}"/></span>
		   	</spring:bind>
	    </span>
    </div>

    <div class="row">
        <span class="label"> Price: </span>
        <span class="formw">
		    <spring:bind path="command.price">
		    	<input name="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>" size="55"/> <br>
		    	<span class="error"><c:out value="${status.errorMessage}"/></span>
		   	</spring:bind>
	    </span>
    </div>

    <div class="row">
        <span class="label"> Short Description: </span>
        <span class="formw">
		    <spring:bind path="command.shortDesc">
		    	<input name="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>" size="55"/> <br>
		    	<span class="error"><c:out value="${status.errorMessage}"/></span>
		   	</spring:bind>
	    </span>
    </div>

    <div class="row">
        <span class="label"> Long Description: </span>
        <span class="formw">
		    <spring:bind path="command.longDesc">
		    	<textarea name="<c:out value="${status.expression}"/>" cols="53" rows="5" styleClass="bodytext"><c:out value="${status.value}"/></textarea> <br>
		    	<span class="error"><c:out value="${status.errorMessage}"/></span>
		   	</spring:bind>
	    </span>
    </div>

    <div class="row">
        <span class="label"> &nbsp; </span>
        <span class="formw">
    		<spring:bind path="command.specialOffer">
	             <span style="margin-right:50px">A Special Offer </span>
		         <input type="checkbox" name="<c:out value="${status.expression}"/>" value="true" <c:if test="${status.value}">checked</c:if>/>
		    </spring:bind>

    		<spring:bind path="command.mainPage">
	             Display on Main Page
		         <input type="checkbox" name="<c:out value="${status.expression}"/>" value="true" <c:if test="${status.value}">checked</c:if>/>
		    </spring:bind>
        </span>
    </div>
    
    <br />
    <div class="formheader"><span>Add Pictures</span></div>
    
        <table class="fields">
        <tr class="header">
            <td></td>
            <td class="bodyText" >Location</td>
            <td class="bodyText" >Alternative Text</td>
            <td class="bodyText" >Ord</td>
        </tr>        
		<c:forEach items="${command.pictures}" var="prop" varStatus="loopStatus">
            <tr>
	            <td class="bodyText" ><c:out value="${loopStatus.index+1}"/></td> 
                <td>
					<div class="row">
						<spring:bind path="command.pictures[${loopStatus.index}].location">
						<input type="text" name="<c:out value="${status.expression}"/>" value="<%= status.getDisplayValue() %>">
						</spring:bind>
			        </div>
                </td>
                <td>
					<div class="row">	
						<spring:bind path="command.pictures[${loopStatus.index}].text">
						<input type="text" name="<c:out value="${status.expression}"/>" value="<%= status.getValue() %>">
						</spring:bind>
					</div>
                </td>
                <td>
					<div class="row">	
						<spring:bind path="command.pictures[${loopStatus.index}].priority">
						<input type="text" name="<c:out value="${status.expression}"/>" value="<%= status.getValue() %>">
						</spring:bind>
					</div>
                </td>
            </tr>
		</c:forEach>            
    </table>
    
 
    <div>
    <bean:size id="picsSize" property="pictures" name="CreateItemForm" /> 
    <div class="row">
    	<input type="submit" name="add-picture" value="Add a Picture">
    </div>
    </div> 

    <div class="formheader" >Associate Properties</div>
    <!-- The Type combo box -->
    <div class="row">
        <span class="label">Select the Item Type:</span>
        <span class="formw">
			<spring:bind path="command.typeId">
				<select name="typeId" onChange="this.form.submit()">
					<c:forEach var="type" items="${types}">
						<option value="<c:out value="${type.name}"/>" <c:if test="${command.typeId == type.name}">SELECTED</c:if>><c:out value="${type.name}"/></option>
					</c:forEach>
				</select>				
			</spring:bind>			
        </span>
    </div>

    <br />


    <div class="row">
        <table class="fields">
            <tr class="header">
                <td></td>
                <td class="bodyText" >Property Name</td>
                <td class="bodyText" >Value</td>
            </tr>        
				<c:forEach items="${command.properties}" var="prop" varStatus="loopStatus">
		            <tr>
			            <td class="bodyText" ><c:out value="${loopStatus.index+1}"/></td> 
		                <td>
							<div class="row">
								<spring:bind path="command.properties[${loopStatus.index}].name">
								<%= status.getDisplayValue() %>:
								</spring:bind>
					        </div>
		                </td>
		                <td>
							<div class="row">	
								<spring:bind path="command.properties[${loopStatus.index}].value">

								<c:if test="<%= status.getValue() == null %>">
									<input size="50" type="text" name="<c:out value="${status.expression}"/>" value="">
								</c:if>
								<c:if test="<%= status.getValue() != null %>">
									<input type="text" name="<c:out value="${status.expression}"/>" value="<%= status.getValue() %>">
								</c:if>
								</spring:bind>
							</div>
		                </td>
		            </tr>
				</c:forEach>            
        </table>
    </div>


	
	<input type="submit" name="save-item" value="Save"/>

    </form>

    <!-- This is necessary to force the parent to expand and include floating divs -->
    <br style="clear:both">
</div>

<jsp:include page="common/footer.jsp" />