<%-- 
/**
  * 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
  *
  */
--%>

<%@ page contentType="text/html"
		 import="olstore.entity.*"
         import="olstore.framework.EJBHomeFactory"
         import="java.util.Collection"
%>

<%
    EJBHomeFactory factory = EJBHomeFactory.getInstance();
%>

    <%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html" %>
    <%@ taglib uri="/WEB-INF/tld/struts-bean.tld" prefix="bean" %>
    <%@ taglib uri="/WEB-INF/tld/struts-logic.tld" prefix="logic" %>

    <% request.setAttribute ( "page_title", "Create or Edit an Item" ); %>
    <jsp:include page="../nav/Header.jsp" />
    <%-- <html:javascript formName="CreateItemForm"/> --%>

    <!-- Content begins here -->

    <div id="form">

    <jsp:include page="../general/Messages.jsp" />

    <!-- Include the form itself -->
    <html:form action="/admin/createItem.do" >
    <html:hidden property="itemId" />
    <html:hidden property="submitType" />
    <div class="formheader">
        <span>Edit or Create an Item</span>
    </div>

    <div class="row">
        <span class="label"> Item Name: </span>
        <span class="formw">
            <html:text property="name" size="55" maxlength="19" />
	    </span>
    </div>

    <div class="row">
        <span class="label"> Price: </span>
        <span class="formw">
            <html:text property="price" size="55" maxlength="9"/>
	    </span>
    </div>

    <div class="row">
        <span class="label"> Short Description: </span>
        <span class="formw">
            <html:text property="shortDesc" size="55" maxlength="55"/>
	    </span>
    </div>

    <div class="row">
        <span class="label"> Long Description: </span>
        <span class="formw">
            <html:textarea property="longDesc" cols="53" rows="5" styleClass="bodytext" />
	    </span>
    </div>

    <div class="row">
        <span class="label"> &nbsp; </span>
        <span class="formw">
            <html:checkbox property="specialOffer" >
                <span style="margin-right:50px">A Special Offer </span>
            </html:checkbox>
            <html:checkbox property="mainPage" > Display on Main Page </html:checkbox>
        </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>


	<logic:iterate name="CreateItemForm" property="pictures" id="pic" indexId="i" >
            <tr>
                <td class="bodyText" ><%= i.intValue() +1+") " %></td>
                <td><div class="row"><html:text indexed="true" name="pic" property="location" size="20" maxlength="40"/></div></td>
                <td><div class="row"><html:text indexed="true" name="pic" property="text" size="44" maxlength="44" /></div></td>
                <td><div class="row"><html:text indexed="true" name="pic" property="priority" size="2" maxlength="2"/></div></td>
            </tr>
        </logic:iterate> 
    </table> 

    <div>
    <bean:size id="picsSize" property="pictures" name="CreateItemForm" /> 
    <div class="row">
    	Total number of fields: <html:text property="numPics" size="2" value="<%= picsSize.toString() %>" maxlength="3"/>
    </div>
    </div> 
    
    <html:submit value="Update" onclick="this.form.submitType.value='updatePictures'" /> 


    <div class="formheader" >Associate Properties</div>
    <!-- The Type combo box -->
    <div class="row">
        <span class="label">Select the Item Type:</span>
        <span class="formw">
<%
            TypeLocalHome typeHome = (TypeLocalHome) factory.getLocalHome( EJBHomeFactory.TYPE );
            Collection types = typeHome.findAll();
            pageContext.setAttribute("types", types, PageContext.REQUEST_SCOPE);
%>
           <html:select name="CreateItemForm" 
                         property="typeId"
                         onchange="this.form.submitType.value='changeType' ; this.form.submit()">
                <html:options collection="types" property="name" labelProperty="name" />
            </html:select>
			
        </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>

<!-- Needed to use these jsp style tags as the struts indexed tags do not produce correct output -->
            <logic:iterate name="CreateItemForm" property="properties" id="prop" indexId="i" type="olstore.dto.PropertyValue" >
                <tr>
                    <td class="bodyText" ><%= i.intValue() +1+") " %></td> 
                   <td>
					<div class="row">
						<html:text 
                               name="CreateItemForm"
                               property='<%= "prop[" + i + "].name" %>'
                               size="20" maxlength="20"/> </div>
                    </td>
                    <td>
					<div class="row">	
						<html:text 
                               name="CreateItemForm"
                               property='<%= "prop[" + i + "].value" %>'
                               size="45" maxlength="45"/> </div>
                    </td>

                </tr>
            </logic:iterate>

        </table>
    </div>

    <div>
    <bean:size id="propsSize" property="properties" name="CreateItemForm" /> 
    Total number of fields: <html:text property="numProps" size="2" value="<%= propsSize.toString() %>" maxlength="3"/>
    </div>

        <div class="row">
        </div>

<html:submit value="Update" onclick="this.form.submitType.value='updateProperties'" />
<html:submit value="Save"
             onclick="this.form.submitType.value='saveItem';
                      if ( validateCreateItemForm(this) ) {
                        return true;
                      } else {
                        return false;
                      }" />

    </html:form>

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

    <jsp:include page="../nav/Footer.jsp" />
