<?xml version="1.0" encoding="UTF-8"?>

<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://xmlns.jcp.org/jsp/jstl/core" xmlns:f="http://xmlns.jcp.org/jsf/core" xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
    xmlns:p="http://primefaces.org/ui" xmlns:e="http://www.ivu.de/elect/tags">

    <!--@elvariable id="selectionView" type="de.ivu.elect.presentation.personenregister.AbstractEntityMitPersonendatenSelectionView"-->

    <ui:param name="id" value="#{not empty id ? id : 'frmPersonenregisterFilter'}" />

    <!-- Dadurch werden seitenspezifische FacesMessages angezeigt, siehe auch ELECT-2244. -->
    #{selectionView.preRenderView()}

    <h:form id="#{id}">
        <ui:param name="btnSearchId" value="btnSearch" />

        <p:panel>
            <ui:fragment rendered="#{selectionView.searchByPersonendatenSupported}">
                <ui:decorate template="/WEB-INF/templates/dyna-form.xhtml">
                    <ui:param name="model" value="#{selectionView.searchByPersonendatenSearchParametersModel}" />
                </ui:decorate>

                <ui:fragment rendered="#{selectionView.searchByMaschinenlesbarerBereichSupported}">
                    <ui:param name="maschinenlesbarerBereichId" value="maschinenlesbarerBereich" />

                    <e:inputMaschinenlesbarerBereich id="#{maschinenlesbarerBereichId}" required="false" autofocus="#{selectionView.maschinenlesbarerBereichFocused}" value="#{selectionView.maschinenlesbarerBereich}"
                        mapper="#{selectionView.maschinenlesbarerBereichMapper}">
                        <p:ajax listener="#{selectionView.onMaschinenlesbarerBereichChanged}" process="@this" update="@form" oncomplete="handleMaschinenlesbarerBereichChanged(xhr, status, args);" />

                        <!-- Cf. AbstractEntityMitPersonendatenSelectionView#onMaschinenlesbarerBereichChanged! -->
                        <e:cdata><h:outputScript>/* <![CDATA[ */
                            function handleMaschinenlesbarerBereichChanged(xhr, status, args) {
                                if(args && args.searchParametersMapped && #{selectionView.btnSearchRendered}) {
                                    var maschinenlesbarerBereichWidget = PF('#{componentHelper.getWidgetVar(maschinenlesbarerBereichId)}');

                                    if(maschinenlesbarerBereichWidget && maschinenlesbarerBereichWidget.jq) {
                                        if(maschinenlesbarerBereichWidget.jq.val().trim().length > 0) {
                                            var btnSearchWidget = PF('#{btnSearchId}Widget');

                                            if(btnSearchWidget && btnSearchWidget.jq) {
                                                btnSearchWidget.jq.click();
                                            }
                                        }
                                    }
                                }
                            }
                        /* ]]> */</h:outputScript></e:cdata>
                    </e:inputMaschinenlesbarerBereich>

                    <ui:decorate template="/WEB-INF/templates/dyna-form.xhtml">
                        <ui:param name="model" value="#{selectionView.searchByMaschinenlesbarerBereichSearchParametersModel}" />
                    </ui:decorate>
                </ui:fragment>
            </ui:fragment>

            <ui:fragment rendered="#{selectionView.searchByOrdnungsmerkmalSupported}">
                <ui:decorate template="/WEB-INF/templates/dyna-form.xhtml">
                    <ui:param name="model" value="#{selectionView.searchByOrdnungsmerkmalSearchParametersModel}" />
                </ui:decorate>
            </ui:fragment>

            <ui:insert />

            <f:facet name="footer">
                <ui:insert name="customSearchFooterButtonsPreceding" />

                <p:commandButton id="btnTestErreichbarkeit" rendered="#{selectionView.btnTestErreichbarkeitRendered}" disabled="#{selectionView.btnTestErreichbarkeitDisabled}" action="#{selectionView.testErreichbarkeit}" ajax="false"
                    immediate="true" value="#{selectionView.btnTestErreichbarkeitLabel}" onclick="PF('ctnContentBlockUI').show();" />

                <p:commandButton id="#{btnSearchId}" rendered="#{selectionView.btnSearchRendered}" disabled="#{selectionView.btnSearchDisabled}" action="#{selectionView.search}" ajax="false" value="#{selectionView.btnSearchLabel}"
                    onclick="PF('ctnContentBlockUI').show();" widgetVar="#{btnSearchId}Widget" />

                <ui:insert name="customSearchFooterButtonsSucceeding" />

                <p:commandButton id="btnCreate" rendered="#{selectionView.btnCreateRendered}" disabled="#{selectionView.btnCreateDisabled}" action="#{selectionView.create}" ajax="false" value="#{selectionView.btnCreateLabel}"
                    onclick="PF('ctnContentBlockUI').show();" />

                <ui:insert name="customCreateFooterButtonsSucceeding" />

                <p:commandButton id="btnReset" rendered="#{selectionView.btnResetRendered}" disabled="#{selectionView.btnResetDisabled}" action="#{selectionView.reset}" ajax="false" immediate="true" onclick="PF('ctnContentBlockUI').show();"
                    value="#{msgs['entity.edit.action.reset']}" styleClass="ui-button--flat" />

                <p:commandButton id="btnCancel" rendered="#{selectionView.btnCancelRendered}" disabled="#{selectionView.btnCancelDisabled}" action="#{selectionView.cancel}" ajax="false" immediate="true"
                    value="#{msgs['entity.edit.action.cancel']}" styleClass="ui-button--flat" />
            </f:facet>
        </p:panel>
    </h:form>

    <h:form id="frmSearchResultEntries" rendered="#{not empty selectionView.searchResultEntries}">
        <p:dataTable id="tblSearchResultEntries" widgetVar="tblSearchResultEntriesWidget" value="#{selectionView.searchResultEntries}" var="searchResultEntry" rowKey="#{searchResultEntry.uuid}" rowIndexVar="rowIndexZeroBased" selectionMode="single"
            selection="#{selectionView.searchResultEntrySelection}" emptyMessage="#{msgs['component.data.table.empty.message']}">
            <c:if test="#{not empty selectionView.searchResultEntryActionMenu and selectionView.searchResultEntryActionMenu.rendered}">
                <p:ajax event="rowDblselect" listener="#{selectionView.searchResultEntryActionMenu.onRowDblselect}" />
            </c:if>

            <e:dataTableActionMenuColumns rowEntity="#{searchResultEntry}" rowSelection="#{selectionView.searchResultEntrySelection}" columnBuilder="#{selectionView.searchResultEntryColumnBuilder}" disableSort="#{false}"
                actionMenu="#{selectionView.searchResultEntryActionMenu}" onActionMenuClick="PF('tblSearchResultEntriesWidget').selectActionMenuRow(#{rowIndexZeroBased}); return false;" />
        </p:dataTable>
    </h:form>

    <ui:insert name="customSearchResults" />
</ui:composition>
