<div ng-controller="localizacaoController">

    <div class="modal-header">
        <h3>Localização</h3>
        <nav class="navbar navbar-default" role="navigation">
            <div class="container-fluid">
                <ul class="nav navbar-nav">
                    <li ng-click="mostrarTab(0)" ng-class="{active:tabActiva[0]}"><a href="">Edificios</a></li>
                    <li ng-click="mostrarTab(1); " ng-class="{active:tabActiva[1]}" ng-show="selectedEdificio!=null"><a href="">Pisos</a></li>
                    <li ng-click="mostrarTab(2); " ng-class="{active:tabActiva[2]}" ng-show="selectedPiso!=null"><a href="">Salas</a></li>
                </ul>
                <form class="navbar-form navbar-right" role="navigation" ng-show="showEdificios">
                    <div class="form-group">
                        <input type="text" class="form-control" placeholder="Procurar..." ng-model="procurar" ng-change="selectedEdificio=null; selectedPiso=null; selectedSala=null">
                    </div>

                    <button popover-placement="top"
                            popover-trigger="mouseenter"
                            data-popover="Remover Edificio"
                            ng-click="confirmarApagarEdificio(selectedEdificio)"
                            type="button"
                            ng-show="edificios.length>0 && selectedEdificio!=null"
                            ng-disabled="selected.item.perm.PApagar==false"
                            class="btn btn-default">
                        <span class="glyphicon glyphicon-remove"></span>
                    </button>
                    <button popover-placement="top"
                            popover-trigger="mouseenter"
                            data-popover="Novo Edificio"
                            ng-click="edificioEditRow()"
                            ng-disabled="selected.item.perm.PCriar==false"
                            type="button"
                            class="btn btn-default">
                        <span class="glyphicon glyphicon-plus"></span>
                    </button>
                    <button popover-placement="top"
                            popover-trigger="mouseenter"
                            data-popover="Editar Edificio"
                            ng-click="edificioEditRow(selectedEdificio)"
                            type="button"
                            ng-disabled="selected.item.perm.PEditar==false"
                            ng-show="edificios.length>0 && selectedEdificio!=null"
                            class="btn btn-default">
                        <span class="glyphicon glyphicon-pencil"></span>
                    </button>
                </form>
               
            </div>
        </nav>
        <h5>
            <span class="glyphicon glyphicon-folder-open" style="margin-right:5px"></span>
            <label>{{caminhoLocalizacao}}</label>
        </h5>
    </div>

    <div class="modal-body">

        <div style="height:270px; overflow:auto" ng-show="showEdificios" ng-init="carregarEdificios(selected.item)">
            
            
            <div class="table-responsive">
                <table class="table table-hover table-striped">
                    <tr>
                        <th>Descrição</th>
                        <th>Pisos</th>
                        <!--<th></th>-->
                    </tr>
                    <tr ng-click="selEdificio(selected.item,edificio)"
                        ng-repeat="edificio in edificios | filter:procurar"
                        ng-selected=""
                        class="apontar"
                        ng-class="{info:edificio.PK_Edificio==selected.item.FK_Edificio}">
                        <td>{{edificio.Descricao}}</td>
                        <td><span class="badge" ng-click="mostrarInfoPisos(selected.item,edificio)">{{edificio.LstPiso.length}}</span></td>

                    </tr>
                </table>
            </div>
        </div>
        <div style="height:270px; overflow:auto" ng-show="showPisos">
            
            <div class="table-responsive">
                <table class="table table-hover table-striped">
                    <tr>
                        <th>Descrição</th>
                        <th style="text-align:right">Salas</th>
                        <th style="text-align:right">
                            <button popover-placement="top"
                                    popover-trigger="mouseenter"
                                    data-popover="Remover Piso"
                                    ng-click="confirmarApagarPiso(selectedPiso)"
                                    ng-disabled="selected.item.perm.PApagar==false"
                                    type="button" class="btn btn-default btn-xs">
                                <span class="glyphicon glyphicon-remove"></span>
                            </button>
                            <button popover-placement="top"
                                    popover-trigger="mouseenter"
                                    data-popover="Novo Piso" ng-click="pisoEditRow()"
                                    ng-disabled="selected.item.perm.PCriar==false"
                                    type="button" class="btn btn-default btn-xs">
                                <span class="glyphicon glyphicon-plus"></span>
                            </button>
                            <button popover-placement="top"
                                    popover-trigger="mouseenter"
                                    data-popover="Editar Piso"
                                    ng-click="pisoEditRow(selectedPiso)"
                                    ng-disabled="selected.item.perm.PEditar==false"
                                    type="button" class="btn btn-default btn-xs">
                                <span class="glyphicon glyphicon-pencil"></span>
                            </button>
                        </th>
                    </tr>
                    <tr ng-click="selPiso(selected.item,piso)"
                        ng-repeat="piso in selectedEdificio.LstPiso"
                        ng-selected=""
                        class="apontar"
                        ng-class="{info:piso.PK_Piso==selected.item.FK_Piso}">
                        <td>{{piso.Descricao}}</td>
                        <td style="text-align:right"><span class="badge" ng-click="mostrarInfoSalas(selected.item,piso)">{{piso.LstSala.length}}</span></td>
                        <td style="text-align:right"></td>
                    </tr>
                </table>
            </div>
        </div>
        <div style="height:270px; overflow:auto" ng-show="showSalas">
            
            <div class="table-responsive">
                <table class="table table-hover table-striped">
                    <tr>
                        <th>Descrição</th>
                        
                        <th style="text-align:right">
                            <button popover-placement="top"
                                    popover-trigger="mouseenter"
                                    data-popover="Remover Sala"
                                    ng-click="confirmarApagarSala(selectedSala)"
                                    ng-disabled="selected.item.perm.PApagar==false"
                                    type="button" class="btn btn-default btn-xs">
                                <span class="glyphicon glyphicon-remove"></span>
                            </button>
                            <button popover-placement="top"
                                    popover-trigger="mouseenter"
                                    data-popover="Nova Sala"
                                    ng-click="salaEditRow()"
                                    ng-disabled="selected.item.perm.PCriar==false"
                                    type="button" class="btn btn-default btn-xs">
                                <span class="glyphicon glyphicon-plus"></span>
                            </button>
                            <button popover-placement="top"
                                    popover-trigger="mouseenter"
                                    data-popover="Editar Sala"
                                    ng-click="salaEditRow(selectedSala)"
                                    ng-disabled="selected.item.perm.PEditar==false"
                                    type="button" class="btn btn-default btn-xs">
                                <span class="glyphicon glyphicon-pencil"></span>
                            </button>
                        </th>
                    </tr>
                    <tr ng-click="selSala(selected.item,sala)"
                        ng-repeat="sala in selectedPiso.LstSala"
                        ng-selected=""
                        class="apontar"
                        ng-class="{info:sala.PK_Sala==selected.item.FK_Sala}">
                        <td>{{sala.Descricao}}</td>
                        <td></td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
    <div class="modal-footer">
        <button class="btn btn-primary"
                ng-click="ok()"
                ng-disabled="selected.item.perm.PCriar==false || selected.item.perm.PEditar==false"
                ng-show="edificios.length>0">
            Aplicar Local
        </button>
        <button class="btn btn-warning" ng-click="cancel()">Sair</button>
    </div>

</div>

