<%@ include file="/portal/include/include_java.jsp" %>

<sp:portalState var="ps" />
<c:set var="chid" value="${ps.currentPortletId}"/>
<p:portalRequest var="pq" />
<c:set var="isProcDashboardPage" value="${pq.currentPortalPage.type == 2 && param.$dashboardProcessId != null}"/>
<t:importAttribute name="$i" />
<script type="text/javascript">
  importStyleSheetWithSkin('/portlet/webpage/css/config.css');
</script>

<script type="text/javascript">
  
  var chid = "<c:out value='${chid}'/>";
  var selectString = '#useProcessDataId_' + chid + ' input:radio';
  var plainId = '#plainUrl_' + chid;
  var expressionId = '#expressionUrl_' + chid;
  
  // on startup, hide/show the appropriate field
  $(document).ready(function() {
     toggleUrlFields();
   });
   
   $(selectString).click(function(){
    toggleUrlFields();
   });
   
   function toggleUrlFields() {
     $(selectString).each(function(i, rb){
      if (rb.checked) {
        if (rb.value == "1") {
          $(expressionId).show();
          $(plainId).hide();
        } else {
          $(expressionId).hide();
          $(plainId).show();
        }
      }
     });
   }
  
  function openExpressionEditorForWebPage_<t:getAsString name="$i"/>(obj, formId) {
    var context; // NamedTypedValue
    var isProcDashboardPage = Boolean.parseBoolean('<asi:out encoding="js" value="${isProcDashboardPage}"/>');
    if (!isProcDashboardPage) {
      context = JSON.parse('<asi:out encoding="js"><asi:toJson value="${pq.currentPageDataContext}"/></asi:out>');
    } else {
      var processId = parseInt('<asi:out encoding="js" value="${param.$dashboardProcessId}"/>');
      context = {type:TYPE_PROCESS, value:processId};
    }
    openExprEditorForProcessAndDataContext(obj, context, formId);
  }
  
  window["cleanEEConfig_{0}".supplant(chid)] = function() {
    var chid = "<asi:out encoding="js" value="${chid}"/>";
    if(window.expressionEditorConfig != null) {
      var formId = 'ap_webPageForm_{0}'.supplant(chid);
      if(window.expressionEditorConfig[formId] != null) {
        window.expressionEditorConfig[formId] = null;
      }
    }
  }
   
</script>


<fmt:setBundle basename="text.jsp.portlet.webpage.configure"/>

<div class="dPortletCustHead"><fmt:message key="PleaseConfigureThisC"/></div>

<asi:form action="/p_webpage/saveportlet.do" name="ap_webPageForm" update="true" bundle="p-errors-i18n">

  <div class="portletConfigureSection"/>
    <h2><fmt:message key="WebPageToDisplay"/></h2>
      <asi:input id="useProcessDataId_${chid}" type="radio" property="useProcessData" legend="UseProcessData" instructions="UseProcessDataInstructions">
        <asi:inputItem label="Yes" value="1"/>
        <asi:inputItem label="No" value="0"/>
      </asi:input>
      <asi:input id="expressionUrl_${chid}" legend="UrlOfPageToDisplay" type="text" property="expressionUrl" required="true"
       expEditorCaller="openExpressionEditorForWebPage_${$i}($$('expressionUrl_${$i}_text'), 'ap_webPageForm_${$i}')"
       />
      <asi:input id="plainUrl_${chid}" legend="UrlOfPageToDisplay" property="newUrl" type="text" required="true" instructions="WebPageChannelPhishingWarning"/>
  </div>

  <div class="portletConfigureSection"/>
    <h2><fmt:message key="ChannelAppearance"/></h2>
    <asi:input type="dropdown" property="size" legend="Height" >
      <asi:inputItem label="Default" value="" />
      <asi:inputItem label="Short" value="250" />
      <asi:inputItem label="Medium" value="500" />
      <asi:inputItem label="Tall" value="750" />
      <asi:inputItem label="ExtraTall" value="2000" />
    </asi:input>
  </div>
  
  <asi:buttonset>
    <asi:button value="Save" onclick="cleanEEConfig_${chid}(); this.form.submit();"/>
    <asi:button type="cancel" value="Cancel" onclick="this.form.submit();"/>
  </asi:buttonset>

</asi:form>

<c:import url="/portal/include/document_listeners.jsp" charEncoding="UTF-8" />