<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@taglib prefix="a4j" uri="http://richfaces.org/a4j"%>
<%@taglib prefix="rich" uri="http://richfaces.org/rich"%>

<%@taglib prefix="p" uri="http://primefaces.prime.com.tr/ui"%>
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<f:subview id="media_management">
    <html>
        <body>
            <h:form id="diskForm">
                <p:growl id="msg" showDetail="true"/>
                <p:panel header="Správa zálohovacíh médií">                 
                    <h:outputText value="Pripojené úložné média" style="font-weight: bold;" />
                    <p:dataTable id="disksList" var="disk" value="#{disks.connectedDisks}"
                                 styleClass="center">

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Cesta" />
                            </f:facet>
                            <h:outputText value="#{disk.fileSystem.devName}" />
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Typ" />
                            </f:facet>
                            <h:outputText value="#{disk.fileSystem.typeName} disk" />
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="System" />
                            </f:facet>
                            <h:outputText value="#{disk.fileSystem.sysTypeName}" />
                        </p:column>

                        <p:column styleClass="rightAlign">
                            <f:facet name="header">
                                <h:outputText value="Celkovo miesta" />
                            </f:facet>
                            <h:outputText value="#{disk.fsUsage.total/1048576}">
                                <f:convertNumber integerOnly="true" maxFractionDigits="1"
                                                 pattern="#.## GB" groupingUsed="false"/>
                            </h:outputText>
                        </p:column>

                        <p:column styleClass="rightAlign">
                            <f:facet name="header">
                                <h:outputText value="Volneho miesta" />
                            </f:facet>
                            <h:outputText value="#{disk.fsUsage.free/1048576}">
                                <f:convertNumber integerOnly="true" maxFractionDigits="1"
                                                 pattern="#.## GB" groupingUsed="false"/>
                            </h:outputText>
                        </p:column>

                        <p:column styleClass="rightAlign">
                            <f:facet name="header">
                                <h:outputText value="Zalohy" />
                            </f:facet>

                            <h:outputText value="#{disk.backups.diskUsage/1048576}">
                                <f:convertNumber integerOnly="true" maxFractionDigits="1"
                                                 pattern="#.## MB" groupingUsed="false"/>
                            </h:outputText>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Zalohovanych suborov" />
                            </f:facet>
                            <h:outputText value="Súborov: #{disk.backups.files}"
                                          rendered="#{disk.usedForBackup}"/>
                            <br/>
                            <h:outputText value="Adresárov: #{disk.backups.subdirs}"
                                          rendered="#{disk.usedForBackup}"/>
                            <h:outputText value="Nepouziva sa pre zalohovanie" rendered="#{!disk.usedForBackup}" />
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Akcia" />
                            </f:facet>

                            <a4j:commandButton value="Zapnut" rendered="#{!disk.usedForBackup}"
                                               actionListener="#{disks.activeBackupDrive}"
                                               reRender="diskForm">
                                <f:attribute name="drive" value="#{disk.fileSystem.devName}" />
                            </a4j:commandButton>
                            <a4j:commandButton value="Vypnut" rendered="#{disk.usedForBackup}"
                                               actionListener="#{disks.deactivateBackupDrive}"
                                               reRender="diskForm" id="deactivate">
                                <f:attribute name="drive" value="#{disk.fileSystem.devName}" />
                            </a4j:commandButton>
                            <p:tooltip for="deactivate" value="Zálohy budú prekopírované na iný disk."
                                       style="cream"/>
                        </p:column>
                    </p:dataTable>
                </p:panel>
            </h:form>
        </body>
    </html>
</f:subview>
