<div ng-controller="localController" ng-init="listarEdificios(selected.item)">

    <div class="modal-header">
        <h3>Localização</h3>

        <h5>
            <span class="glyphicon glyphicon-folder-open" style="margin-right:5px"></span>
            <label>{{caminhoLocalizacao}}</label>
        </h5>
    </div>

    <div class="modal-body">
        <div class="table-responsive sep1" style="height:auto">
            <div style="background-color:#DDD">
                
                
                <input type="text" placeholder="" class="form-control" style="cursor:default"
                       popover-placement="top"
                       popover-trigger="mouseenter"
                       data-popover="Nome da Entidade"
                       ng-click=""
                       readonly="readonly" ng-model="selectedEdificio.NomeEntidade" />
            </div>
            
            <table class="table">
                <tr>
                    <td></td>
                    <td>
                        <h4>Edifício</h4>

                        <select class="form-control" id="selEdificio"
                                ng-model="selectedEdificio"
                                ng-change="selEdificio(selectedEdificio,selected.item); atribuirLoc(selected.item)"
                                ng-options="e.EdificioEntidade for e in edificios">
                            <option value="">Qualquer Edifício...</option>
                        </select>
                    </td>
                    <td style="text-align:right; width:150px">
                        <button popover-placement="top"
                                popover-trigger="mouseenter"
                                data-popover="Remover Edifício"
                                ng-click="confirmarApagarEdificio(selectedEdificio,selected.item)"
                                type="button"
                                ng-disabled="mnuTabelas.PApagar==false || edificios.length==0 || selectedEdificio==null"
                                class="btn btn-warning btn-sm">
                            <span class="glyphicon glyphicon-remove"></span>
                        </button>

                        <button popover-placement="top"
                                popover-trigger="mouseenter"
                                data-popover="Novo Edifício"
                                ng-click="edificioEditRow(null,selected.item)"
                                type="button"
                                class="btn btn-primary btn-sm">
                            <span class="glyphicon glyphicon-plus"></span>
                        </button>
                        <button popover-placement="top"
                                popover-trigger="mouseenter"
                                data-popover="Editar Edifício"
                                type="button"
                                class="btn btn-default btn-sm"
                                ng-click="edificioEditRow(selectedEdificio,selected.item)"
                                ng-disabled="mnuTabelas.PEditar==false || edificios.length==0 || selectedEdificio==null">

                            <span class="glyphicon glyphicon-pencil"></span>
                        </button>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <h4>Piso</h4>
                        <select class="form-control"
                                ng-model="selectedPiso"
                                ng-change="selPiso(selectedPiso,selected.item); atribuirLoc(selected.item)"
                                ng-options="p.Descricao for p in selectedEdificio.LstPiso">
                            <option value="">Qualquer Piso...</option>
                        </select>
                    </td>
                    <td style="text-align:right; width:150px" >
                        <button popover-placement="top"
                                popover-trigger="mouseenter"
                                data-popover="Remover Piso"
                                ng-click="confirmarApagarPiso(selectedPiso,selected.item)"
                                type="button"
                                ng-disabled="mnuTabelas.PApagar==false ||selectedEdificio.LstPiso.length==0 || selectedPiso==null"
                                class="btn btn-warning btn-sm">
                            <span class="glyphicon glyphicon-remove"></span>
                        </button>
                        <button popover-placement="top"
                                popover-trigger="mouseenter"
                                data-popover="Novo Piso"
                                ng-click="pisoEditRow(null,selected.item)"
                                type="button"
                                class="btn btn-primary btn-sm">
                            <span class="glyphicon glyphicon-plus"></span>
                        </button>
                        <button popover-placement="top"
                                popover-trigger="mouseenter"
                                data-popover="Editar Piso"
                                type="button"
                                class="btn btn-default btn-sm"
                                ng-click="pisoEditRow(selectedPiso,selected.item)"
                                ng-disabled="mnuTabelas.PEditar==false || selectedEdificio.LstPiso.length==0 || selectedPiso==null">
                            <span class="glyphicon glyphicon-pencil"></span>
                        </button>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <h4>Sala</h4>
                        <select class="form-control"
                                ng-model="selectedSala"
                                ng-change="selSala(selectedSala,selected.item); atribuirLoc(selected.item)"
                                ng-options="s.Descricao for s in selectedPiso.LstSala">
                            <option value="">Qualquer Sala...</option>
                        </select>
                    </td>
                    <td style="text-align:right; width:150px">
                        <button popover-placement="top"
                                popover-trigger="mouseenter"
                                data-popover="Remover Sala"
                                ng-click="confirmarApagarSala(selectedSala,selected.item)"
                                type="button"
                                ng-disabled="mnuTabelas.PApagar==false ||selectedPiso.LstSala.length==0 || selectedSala==null"
                                class="btn btn-warning btn-sm">
                            <span class="glyphicon glyphicon-remove"></span>
                        </button>
                        <button popover-placement="top"
                                popover-trigger="mouseenter"
                                data-popover="Nova Sala"
                                ng-click="salaEditRow(null,selected.item)"
                                type="button"
                                class="btn btn-primary btn-sm">
                            <span class="glyphicon glyphicon-plus"></span>
                        </button>
                        <button popover-placement="top"
                                popover-trigger="mouseenter"
                                data-popover="Editar Sala"
                                type="button"
                                class="btn btn-default btn-sm"
                                ng-click="salaEditRow(selectedSala,selected.item)"
                                ng-disabled="mnuTabelas.PEditar==false || selectedPiso.LstSala.length==0 || selectedSala==null">
                            <span class="glyphicon glyphicon-pencil"></span>
                        </button>
                    </td>
                </tr>
            </table>
        </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>

