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

<ui:composition xmlns="http://www.w3.org/1999/xhtml" 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" xmlns:c="http://java.sun.com/jsp/jstl/core">

    <!--@elvariable id="msgs" type="de.ivu.elect.business.lokalisierung.control.LokalisierungResourceBundle"-->

    <!--@elvariable id="backingView" type="de.ivu.elect.presentation.exchange.AbstractExportSearchView"-->

    <e:form id="frmExport" rendered="#{backingView.btnExportierenRendered or backingView.exportParameterModelPresent}">
        <ui:insert name="beforeDynaForm"/>
        <p:panel id="ctnExport">
            <ui:insert name="controls">
                <ui:insert name="firstInPanel"/>
                <ui:insert name="controlsFileFormat">
                    <!-- ELECT-2462: fileFormatViewSelect direkt zugreifen, um JBoss-Bug zu umgehen -->
                    <!-- <e:selectOneMenu update="@form" /> -> Auto-Update des Formulars bei Ändern des Dateiformates! -->
                    <!-- Cf. /WEB-INF/templates/exchange/import-format-festlegen.xhtml! -->
                    <e:selectOneMenu id="inFileFormat" rendered="#{backingView.supportedFileFormatsRendered}" required="true" value="#{fileFormatViewSelect.selectedFileFormat}" label="#{dateiMeta.formatEinzahlMessage}" update="@form"
                        converterId="fileFormatConverter">
                        <f:selectItem itemLabel="#{msgs['component.selection.required']}" itemValue="#{null}" />
                        <f:selectItems value="#{backingView.getSupportedFileFormats()}" var="fileFormat" itemLabel="#{fileFormatFormatter.format(fileFormat)}" />
                    </e:selectOneMenu>
                </ui:insert>

                <ui:insert />
            </ui:insert>

            <f:facet name="footer">
                <ui:insert name="buttonsFirst" />
                <p:commandButton id="btnExportieren" rendered="#{backingView.btnExportierenRendered}" disabled="#{backingView.btnExportierenDisabled}" action="#{backingView.exportieren}" ajax="false"
                    onclick="PF('ctnContentBlockUI').show();" value="#{msgs['datei.export.action.exportieren']}" icon="#{icons.iconExport}" />

                <p:commandButton id="btnCancel" rendered="#{backingView.btnCancelRendered}" action="#{backingView.cancel}" ajax="false" immediate="true" value="#{msgs['entity.edit.action.cancel']}" styleClass="ui-button--flat" />

                <!-- Cf. tags/filterPanel.xhtml -->
                <p:commandButton id="btnGoBackCustom" rendered="#{backingView.btnGoBackRendered}" disabled="#{backingView.btnGoBackDisabled}" action="#{backingView.goBack()}" ajax="false" immediate="true"
                    value="#{msgs['entity.action.back']}" icon="#{icons.iconBack}" styleClass="ui-button--flat" />

                <ui:insert name="buttons" />
            </f:facet>
        </p:panel>
    </e:form>

    <!-- ELECT-11847, ELECTMUC-2216, cf. /WEB-INF/tags/formDokumentErzeugen.xhtml... -->
    <c:if test="#{backingView.searchResultRendered}">
        <e:formSearch>
            <ui:define name="dataTable">
                <e:searchTable searchView="#{dateiExportSearchView}" value="#{backingView.getSearchResult()}" actionMenu="#{dateiExportSearchActionMenu}" columnBuilder="#{dateiExportColumnBuilder}">
                    <p:ajax event="rowDblselect" listener="#{dateiExportVorschauAction.onRowDblselect}" />
                </e:searchTable>
            </ui:define>
        </e:formSearch>
    </c:if>

    <e:modalDialog dialogName="DeleteConfirm" header="#{msgs['entity.edit.action.delete.confirm']}">
        <p:panel id="ctnDeleteConfirm" rendered="#{backingView.isBtnDeleteRendered() and backingView.isSearchResultEntrySelected()}">
            <h:outputFormat value="#{msgs['datei.import.edit.action.delete.confirm.message']}" styleClass="ui-dialog-message-multiline">
                <f:param value="#{backingView.getSelectedSearchResultEntry().datei.dateiname}" />
            </h:outputFormat>

            <f:facet name="footer">
                <p:commandButton id="btnDelete" action="#{backingView.delete}" ajax="false" immediate="true" value="#{msgs['entity.edit.action.delete']}" />

                <p:commandButton id="btnDeleteCancel" onclick="PF('dlgDeleteConfirmWidget').hide()" value="#{msgs['entity.edit.action.cancel']}" styleClass="ui-button--flat" />
            </f:facet>
        </p:panel>
    </e:modalDialog>

    <e:modalDialog dialogName="DownloadConfirm" visible="#{backingView.isNeedsDownload()}" header="#{msgs['datei.export.action.download.confirm']}">
        <p:panel id="ctnDownloadConfirm">
            <h:outputFormat value="#{msgs['datei.export.action.download.confirm.message']}" styleClass="ui-dialog-message-multiline">
                <f:param value="#{backingView.getSelectedSearchResultEntry().datei.originalDateiname}" />
            </h:outputFormat>

            <f:facet name="footer">
                <!-- ELECT-10757, bei "Download"-Aktion innerhalb eines Dialoges, diesen NICHT automatisch schließen! -->
                <p:commandButton id="btnDownload" action="#{dateiExportDownloadAction.action(backingView.getSelectedSearchResultEntry())}" ajax="false"
                        immediate="true" value="#{msgs[dateiExportDownloadAction.labelKey]}"
                        onclick="PF('ctnContentBlockUI').show(); setTimeout(function() { PF('dlgDownloadConfirmWidget').hide();PF('ctnContentBlockUI').hide(); }, 2000);"
                        icon="fa fa-save"/>

                <p:commandButton id="btnDownloadCancel" action="#{backingView.cancel}" ajax="false" immediate="true" value="#{msgs['datei.export.action.download.cancel']}" styleClass="ui-button--flat" />
            </f:facet>
        </p:panel>
    </e:modalDialog>

    <!--@elvariable id="backingView#exportConfirmDialog" type="de.ivu.elect.presentation.exchange.ExportViewConfirmDialog"-->
    <e:modalDialog dialogName="ExportConfirm" visible="#{backingView.exportConfirmDialog.visible}" header="#{backingView.exportConfirmDialog.header}">
        <p:panel id="ctnExportConfirm">
            <h:outputText rendered="#{backingView.exportConfirmDialog.messageRendered}" value="#{backingView.exportConfirmDialog.message}" styleClass="ui-dialog-message-multiline" />

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

            <f:facet name="footer">
                <p:commandButton id="btnExportConfirm" rendered="#{backingView.btnExportierenRendered}" disabled="#{backingView.btnExportierenDisabled}" action="#{backingView.exportierenConfirmed}" ajax="false"
                    onclick="PF('ctnContentBlockUI').show(); PF('dlgExportConfirmWidget').hide()" value="#{msgs['datei.export.action.exportieren']}" />

                <p:commandButton id="btnExportConfirmCancel" action="#{backingView.cancel}" ajax="false" immediate="true" value="#{msgs['entity.edit.action.cancel']}" styleClass="ui-button--flat" />
            </f:facet>
        </p:panel>
    </e:modalDialog>
</ui:composition>
