<!--

    DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.

    Copyright (c) 2010-2011 Oracle and/or its affiliates. All rights reserved.

    The contents of this file are subject to the terms of either the GNU
    General Public License Version 2 only ("GPL") or the Common Development
    and Distribution License("CDDL") (collectively, the "License").  You
    may not use this file except in compliance with the License.  You can
    obtain a copy of the License at
    https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
    or packager/legal/LICENSE.txt.  See the License for the specific
    language governing permissions and limitations under the License.

    When distributing the software, include this License Header Notice in each
    file and include the License file at packager/legal/LICENSE.txt.

    GPL Classpath Exception:
    Oracle designates this particular file as subject to the "Classpath"
    exception as provided by Oracle in the GPL Version 2 section of the License
    file that accompanied this code.

    Modifications:
    If applicable, add the following below the License Header, with the fields
    enclosed by brackets [] replaced by your own identifying information:
    "Portions Copyright [year] [name of copyright owner]"

    Contributor(s):
    If you wish your version of this file to be governed by only the CDDL or
    only the GPL Version 2, indicate your decision by adding "[Contributor]
    elects to include this software in this distribution under the [CDDL or GPL
    Version 2] license."  If you don't indicate a single choice of license, a
    recipient has the option to distribute your version of this file under
    either the CDDL, the GPL Version 2 or to extend the choice of license to
    its licensees as provided above.  However, if you add GPL Version 2 code
    and therefore, elected the GPL Version 2 license, then the option applies
    only if the new code is made subject to such option by the copyright
    holder.

-->

<!initPage
    setResourceBundle(key="i18ncs" bundle="org.glassfish.cluster.admingui.Strings")
    setResourceBundle(key="i18nc" bundle="org.glassfish.common.admingui.Strings")
    setResourceBundle(key="help_cluster" bundle="org.glassfish.cluster.admingui.Helplinks");
/>
<!composition template="/templates/default.layout"  guiTitle="$resource{i18ncs.cluster.GeneralTitle}">
<!define name="content">
    <event>
    <!beforeCreate
        setSessionAttribute(key="clusterTabs" value="general");
        getRequestValue(key="clusterName" value="#{pageSession.clusterName}");
        urlencode(value="#{pageSession.clusterName}" encoding="UTF-8" result="#{pageSession.encodedClusterName}");
        setPageSessionAttribute(key="selfPage" value="#{request.contextPath}/cluster/cluster/clusterGeneral.jsf?clusterName=#{pageSession.encodedClusterName}");
        setPageSessionAttribute(key="parentPage" value="#{request.contextPath}/cluster/cluster/clusters.jsf");
        setPageSessionAttribute(key="parentUrl", value="#{sessionScope.REST_URL}/clusters");
        setPageSessionAttribute(key="childType" value="cluster");
        setPageSessionAttribute(key="resourceUrl", value="#{pageSession.parentUrl}/#{pageSession.childType}/#{pageSession.encodedClusterName}");
        setPageSessionAttribute(key="rest-api" value="true");

        gf.getEntityAttrs(endpoint="#{pageSession.resourceUrl}.json", valueMap="#{pageSession.valueMap}");
        gf.getChildrenNamesList(endpoint="#{pageSession.resourceUrl}/server-ref" id="ref" result="#{pageSession.instanceList}" );
        gf.listInstances(optionKeys={"id"} optionValues={"$pageSession{clusterName}"}, statusMap="#{requestScope.statusMap}");
        gf.getClusterStatusSummary(statusMap ="#{requestScope.statusMap}" ,
            numRunning="#{pageSession.numRunning}"  numNotRunning="#{pageSession.numNotRunning}" numRequireRestart="#{pageSession.numRequireRestart}"
            disableStart="#{pageSession.disableStart}"  disableStop="#{pageSession.disableStop}" disableEjb="#{pageSession.disableEjb}");
        setPageSessionAttribute(key="convertToFalseList" value={ "gmsEnabled"} );
        //set the following for including buttons.inc
        setPageSessionAttribute(key="edit" value="#{true}" );
        setPageSessionAttribute(key="showDefaultButton" value="#{true}" );
        setPageSessionAttribute(key="showCancelButton" value="#{true}" );
        setPageSessionAttribute(key="hasPropertySheet" value="#{true}" );
        setPageSessionAttribute(key="hasPropertyTable" value="#{false}" );
    />
    </event>
            <sun:form id="propertyForm">
#include "/cluster/cluster/clusterTabs.inc"
#include "/common/shared/alertMsg.inc"

    <!-- Page Title -->
    <sun:title id="propertyContentPage" title="$resource{i18ncs.cluster.GeneralTitle}" helpText="$resource{i18ncs.cluster.GeneralTitleHelp}">
        <!facet pageButtonsTop>
            <sun:panelGroup id="topButtons">
                <sun:button id="saveButton" rendered="#{edit}" text="$resource{i18n.button.Save}"
                        onClick="if (guiValidate('#{reqMsg}','#{reqInt}','#{reqPort}')) {submitAndDisable(this, '$resource{i18n.button.Processing}');}; return false;" >
                    <!command
                        gf.updateEntity(clusterName="#{pageSession.clusterName}" endpoint="#{pageSession.resourceUrl}" attrs="#{pageSession.valueMap}"  convertToFalse="#{pageSession.convertToFalseList}");
                        prepareSuccessfulMsg();
                        gf.redirect(page="#{pageSession.selfPage}&alertType=${alertType}&alertSummary=${alertSummary}&alertDetail=${alertDetail}");
                    />
                </sun:button>
                <sun:button id="cancelButton" immediate="#{true}" primary="#{false}" rendered="#{pageSession.showCancelButton}" text="$resource{i18n.button.Cancel}" >
                    <!command
                        gf.redirect(page="#{pageSession.parentPage}");
                    />
                </sun:button>
            </sun:panelGroup>
        </facet>
    </sun:title>

    <sun:button id="startButton" text="$resource{i18ncs.button.startCluster}" disabled="#{disableStart}" primary="#{false}"
        onClick="if ( getConfirm(this,'$resource{i18ncs.msg.JS.confirmStartClusters}') )
                { return submitAndDisable(this, '$resource{i18n.button.Processing}');}  else {return false;} " >
        <!command
            println("Starting Cluster...");
            println("#{sessionScope.REST_URL}/clusters/cluster/#{pageSession.encodedClusterName}/start-cluster");
            gf.restRequest(endpoint="#{sessionScope.REST_URL}/clusters/cluster/#{pageSession.encodedClusterName}/start-cluster" method="POST");
            gf.redirect(page="#{pageSession.selfPage}&alertType=${alertType}&alertSummary=${alertSummary}&alertDetail=${alertDetail}");
        />
    </sun:button>

    <sun:button id="stopButton" text="$resource{i18ncs.button.stopCluster}" disabled="#{disableStop}" primary="#{false}"
        onClick="if ( getConfirm(this,'$resource{i18ncs.msg.JS.confirmStopClusters}') )
                { return submitAndDisable(this, '$resource{i18n.button.Processing}');}  else {return false;} " >
        <!command
            println("Stopping Cluster...");
            println("#{sessionScope.REST_URL}/clusters/cluster/#{pageSession.encodedClusterName}/stop-cluster");
            gf.restRequest(endpoint="#{sessionScope.REST_URL}/clusters/cluster/#{pageSession.encodedClusterName}/stop-cluster" method="POST");
            gf.redirect(page="#{pageSession.selfPage}&alertType=${alertType}&alertSummary=${alertSummary}&alertDetail=${alertDetail}");
        />
    </sun:button>

    <sun:button id="migrateTimesButton" text="$resource{i18ncs.button.migrateEjbTimer}"  disabled="#{disableEjb}" primary="false">
        <!command
            gf.redirect(page="#{request.contextPath}/cluster/migrateEjbTimers.jsf?clusterName=#{pageSession.encodedClusterName}");
        />
    </sun:button>

    <sun:button id="rotateLog" text="$resource{i18n.button.rotateLog}" primary="#{false}"
        onClick="if ( getConfirm(this, '$resource{i18nc.msg.JS.confirmRotateLog}') )
        { return submitAndDisable(this, '$resource{i18n.button.Processing}', target='_top');}
            else {return false;} " >
            <!command
                createMap(result="#{requestScope.map}");
                mapPut(map="#{requestScope.map}", key="target", value="#{pageSession.encodedClusterName}");
                gf.restRequest(
                    endpoint="#{sessionScope.REST_URL}/rotate-log"
                    attrs="#{requestScope.map}"
                    method="POST"
                    result="#{pageSession.props}");
            gf.redirect("#{pageSession.selfPage}");/>
    </sun:button>

    <sun:propertySheet id="propertySheet">

        <!-- Text Field section -->
        <sun:propertySheetSection id="propertSectionTextField">
            <sun:property id="clusterNameProp"  labelAlign="left" noWrap="#{true}" overlapLabel="#{false}" label="$resource{i18ncs.cluster.ClusterName}" >
                <sun:staticText id="clusterName"text="#{pageSession.clusterName}" />
            </sun:property>
            <sun:property id="configNameProp"  labelAlign="left" noWrap="#{true}" overlapLabel="#{false}" label="$resource{i18n.common.Configuration}" >
                <sun:hyperlink id="configlink" text="#{pageSession.valueMap['configRef']}"
                    url="#{request.contextPath}/common/configuration/configuration.jsf?configName=#{pageSession.valueMap['configRef']}" />
            </sun:property>

            <sun:property id="gmsEnabledProp"  labelAlign="left" noWrap="#{true}" overlapLabel="#{false}" label="$resource{i18ncs.cluster.GMS}" helpText="$resource{i18ncs.cluster.GMSHelp}">
                <sun:checkbox id="gmscb" label="$resource{i18n.common.Enabled}" selected="#{pageSession.valueMap['gmsEnabled']}" selectedValue="true" />
            </sun:property>

           <sun:property id="gmsMulticastPort"  labelAlign="left" noWrap="#{true}" overlapLabel="#{false}" label="$resource{i18ncs.cluster.gmsMulticastPort}" helpText="$resource{i18ncs.cluster.gmsMulticastPortHelp}">
                <sun:textField id="gmsMulticastPort"  styleClass="port" columns="$int{60}" maxLength="#{sessionScope.fieldLengths['maxLength.cluster.gmsMulticastPort']}" text="#{pageSession.valueMap['gmsMulticastPort']}"/>
            </sun:property>
            <sun:property id="gmsMulticastAddress"  labelAlign="left" noWrap="#{true}" overlapLabel="#{false}" label="$resource{i18ncs.cluster.gmsMulticastAddress}" helpText="$resource{i18ncs.cluster.gmsMulticastAddressHelp}">
                <sun:textField id="gmsMulticastAddress"  columns="$int{60}" maxLength="#{sessionScope.fieldLengths['maxLength.cluster.gmsMulticastAddress']}" text="#{pageSession.valueMap['gmsMulticastAddress']}"/>
            </sun:property>

            <sun:property id="GmsBindInterfaceAddress"  labelAlign="left" noWrap="#{true}" overlapLabel="#{false}" label="$resource{i18ncs.cluster.gmsBindInterfaceAddress}" helpText="$resource{i18ncs.cluster.gmsBindInterfaceAddressHelp}">
                <sun:textField id="GmsBindInterfaceAddress"  columns="$int{60}" maxLength="#{sessionScope.fieldLengths['maxLength.cluster.gmsBindInterfaceAddress']}" text="#{pageSession.valueMap['gmsBindInterfaceAddress']}"/>
            </sun:property>

            <sun:property id="instanceStatusProp"  labelAlign="left" noWrap="#{true}" overlapLabel="#{false}" label="$resource{i18n.common.status}" >
                <if condition="#{pageSession.numNotRunning}">
                    <sun:staticText id="instanceStatusStopped" text=" #{pageSession.numNotRunning}" />
                    "<br />
                </if>
                <if condition="#{pageSession.numRequireRestart}">
                    <sun:staticText id="instanceStatusRequireRestart" text="#{pageSession.numRequireRestart}" />
                    "<br />
                </if>
                <sun:staticText id="instanceStatusRunning" text="#{pageSession.numRunning}" />
                "<br />
            </sun:property>
        </sun:propertySheetSection>

    </sun:propertySheet>

	<sun:hidden id="helpKey" value="$resource{help_cluster.clusterGeneral}" />
</sun:form>
</define>
</composition>
