<%@ page session="false" contentType="text/html;charset=UTF-8" %> 
<%@ page import="java.util.Locale" %>
<%@ page import="java.util.ResourceBundle" %>
<%@ page import="oracle.portal.provider.v2.http.HttpCommonConstants" %>
<%@ page import="oracle.portal.provider.v2.render.PortletRenderRequest" %>
<%@ page import="oracle.portal.provider.v2.render.PortletRendererUtil" %>
<%@ page import="oracle.portal.sample.v2.devguide.eventform.EventFormCustomization" %>
<%@ page import="oracle.portal.sample.v2.devguide.eventform.resource.EventFormBundle" %>

<%
    //
    // This JSP both displays the customization form and processes it.
    //

    //
    // Get the portlet render request object.
    //
    PortletRenderRequest prr = (PortletRenderRequest)
        request.getAttribute(HttpCommonConstants.PORTLET_RENDER_REQUEST);

    //
    // Get the customization data.
    //
    EventFormCustomization data = 
        (EventFormCustomization)PortletRendererUtil.getEditDefaultData(prr);

    //
    // This JSP can be rendered either as the result of 
    //
    //   1) clicking a customization link from show MODE
    //   2) clicking the OK or APPLY button after this JSP was previously 
    //      rendered, i.e. submitting the customization data
    //      (Note that clicking CANCEL automitically redirects to show MODE.)
    //
    // If the edit form parameter has a value then the customization data
    // is being submitted.
    //
    String actionParam = PortletRendererUtil.getEditFormParameter(prr);
        String action = request.getParameter(actionParam);
    if (action != null) {

        //
        // The customization data is being submitted.
        // Get the customization values that were passed as parameters 
        // save them into the customization store.
        //
        String splashText = request.getParameter("eventform_splashText");
        String parameter1Label = 
            request.getParameter("eventform_parameter1Label");
        String parameter2Label = 
            request.getParameter("eventform_parameter2Label");
        String parameter1Value = 
            request.getParameter("eventform_parameter1Value");
        String parameter2Value = 
            request.getParameter("eventform_parameter2Value");
        String submitLabel = request.getParameter("eventform_submitLabel");
        String cancelLabel = request.getParameter("eventform_cancelLabel");

        data.setSplashText(splashText);
        data.setParameter1Label(parameter1Label);
        data.setParameter2Label(parameter2Label);
        data.setParameter1ValueForMobile(parameter1Value);
        data.setParameter2ValueForMobile(parameter2Value);
        data.setSubmitLabel(submitLabel);
        data.setCancelLabel(cancelLabel);
        PortletRendererUtil.submitEditData(prr, data);
        return;
    }

    //
    // The customization data is not being submitted.
    // Display the customization form that will allow the user to change
    // and submit the customization values.
    //

    //
    // Get the labels for the various edit fields.
    //
    Locale locale = prr.getPortletReference().getLocale();
    ResourceBundle bundle = 
        prr.getPortletDefinition().getResourceBundle(locale);

    String splashTextLabel = 
            bundle.getString(EventFormBundle.SPLASHTEXT_LABEL_KEY);
    String parameter1LabelLabel = 
            bundle.getString(EventFormBundle.PARAMETER1_LABEL_LABEL_KEY);
    String parameter2LabelLabel = 
            bundle.getString(EventFormBundle.PARAMETER2_LABEL_LABEL_KEY);
    String parameter1ValueLabel = 
            bundle.getString(EventFormBundle.PARAMETER1_VALUE_LABEL_KEY);
    String parameter2ValueLabel = 
            bundle.getString(EventFormBundle.PARAMETER2_VALUE_LABEL_KEY);
    String submitLabelLabel = 
            bundle.getString(EventFormBundle.SUBMIT_LABEL_LABEL_KEY);
    String cancelLabelLabel = 
            bundle.getString(EventFormBundle.CANCEL_LABEL_LABEL_KEY);

    //
    // Get the initial values for the various edit fields.
    //
    String splashText      = data.getSplashText();
    String parameter1Label = data.getParameter1Label();
    String parameter2Label = data.getParameter2Label();
    String parameter1Value = data.getParameter1ValueForMobile();
    String parameter2Value = data.getParameter2ValueForMobile();
    String submitLabel     = data.getSubmitLabel();
    String cancelLabel     = data.getCancelLabel();
%>

<TABLE BORDER="0">
  <TR>
    <TD WIDTH="40%">
      <P ALIGN="RIGHT"><%=splashTextLabel%>
    </TD>
    <TD WIDTH="60%">
      <INPUT TYPE="TEXT" NAME="eventform_splashText" VALUE="<%= splashText %>" SIZE="30">
    </TD>
  </TR>
  <TR>
    <TD WIDTH="40%">
      <P ALIGN="RIGHT"><%=parameter1LabelLabel%>
    </TD>
    <TD WIDTH="60%">
      <INPUT TYPE="TEXT" NAME="eventform_parameter1Label" VALUE="<%= parameter1Label %>" SIZE="30">
    </TD>
  </TR>
  <TR>
    <TD WIDTH="40%">
      <P ALIGN="RIGHT"><%=parameter1LabelLabel%>
    </TD>
    <TD WIDTH="60%">
      <INPUT TYPE="TEXT" NAME="eventform_parameter2Label" VALUE="<%= parameter2Label %>" SIZE="30">
    </TD>
  </TR>
  <TR>
    <TD WIDTH="40%">
      <P ALIGN="RIGHT"><%=parameter1ValueLabel%>
    </TD>
    <TD WIDTH="60%">
      <INPUT TYPE="TEXT" NAME="eventform_parameter1Value" VALUE="<%= parameter1Value %>" SIZE="30">
    </TD>
  </TR>
  <TR>
    <TD WIDTH="40%">
      <P ALIGN="RIGHT"><%=parameter2ValueLabel%>
    </TD>
    <TD WIDTH="60%">
      <INPUT TYPE="TEXT" NAME="eventform_parameter2Value" VALUE="<%= parameter2Value %>" SIZE="30">
    </TD>
  </TR>
  <TR>
    <TD WIDTH="40%">
      <P ALIGN="RIGHT"><%=submitLabelLabel%>
    </TD>
    <TD WIDTH="60%">
      <INPUT TYPE="TEXT" NAME="eventform_submitLabel" VALUE="<%= submitLabel %>" SIZE="30">
    </TD>
  </TR>
  <TR>
    <TD WIDTH="40%">
      <P ALIGN="RIGHT"><%=cancelLabelLabel%>
    </TD>
    <TD WIDTH="60%">
      <INPUT TYPE="TEXT" NAME="eventform_cancelLabel" VALUE="<%= cancelLabel %>" SIZE="30">
    </TD>
  </TR>
</TABLE>

