<vn-crud-model
    vn-id="model"
    url="/api/Routes/{{$ctrl.$stateParams.id}}/getTickets"
    order="priority ASC"
    data="$ctrl.tickets"
    auto-load="true">
</vn-crud-model>
<form name="form">
    <vn-card pad-large>
        <vn-tool-bar margin-small-bottom >
            <vn-button 
                icon="icon-wand"
                ng-click="$ctrl.guessPriority()"
                vn-tooltip="Sort routes">
            </vn-button>
            <vn-button 
                disabled="!$ctrl.isChecked"
                ng-click="$ctrl.goToBuscaman()"
                vn-tooltip="Open buscaman" 
                tooltip-position="up"
                icon="icon-buscaman">
            </vn-button>
        </vn-tool-bar>
        <vn-icon-button
            vn-tooltip="Load more"
            ng-click="$ctrl.goToBuscaman()">
        </vn-icon-button>
        <vn-table model="model" auto-load="false">
            <vn-thead>
                <vn-tr>
                    <vn-th shrink>
                        <vn-multi-check 
                            model="model">
                        </vn-multi-check>
                    </vn-th>
                    <vn-th>Order</vn-th>
                    <vn-th number>Ticket id</vn-th>
                    <vn-th>Alias</vn-th>
                    <vn-th number shrink>Packages</vn-th>
                    <vn-th shrink>m³</vn-th>
                    <vn-th shrink>Warehouse</vn-th>
                    <vn-th shrink>PC</vn-th>
                    <vn-th>Street</vn-th>
                    <vn-th shrink></vn-th>
                    <vn-th shrink></vn-th>
                </vn-tr>
            </vn-thead>
            <vn-tbody>
                <vn-tr ng-repeat="ticket in $ctrl.tickets">
                    <vn-td shrink>
                        <vn-check 
                            field="ticket.checked">
                        </vn-check>
                    </vn-td>
                    <vn-td>
                        <vn-textfield
                            vn-tab-index="-1"
                            type="number"
                            on-change="$ctrl.setPriority(ticket.id, ticket.priority)"
                            model="ticket.priority"
                            rule="ticket.priority">
                        </vn-textfield>
                    </vn-td>
                    <vn-td number>
                        <span 
                            ng-click="$ctrl.showTicketDescriptor($event, ticket.id)"
                            class="link">
                            {{ticket.id | zeroFill:6}}
                        </span>
                    </vn-td>
                    <vn-td>
                        <span 
                            ng-click="$ctrl.showClientDescriptor($event, ticket.clientFk)"
                            class="link">
                            {{ticket.nickname}}
                        </span>
                    </vn-td>
                    <vn-td number shrink>{{ticket.packages}}</vn-td>
                    <vn-td shrink>{{ticket.volume}}</vn-td>
                    <vn-td shrink>{{ticket.warehouse.name}}</vn-td>
                    <vn-td shrink>{{ticket.client.postcode}}</vn-td>
                    <vn-td expand title="{{ticket.client.street}}">{{ticket.client.street}}</vn-td>
                    <vn-td shrink> 
                        <vn-icon
                            ng-if="ticket.notes.length"
                            vn-tooltip="{{ticket.notes[0].description}}"
                            icon="insert_drive_file">
                        </vn-icon>
                    </vn-td>
                    <vn-td>
                        <vn-icon-button
                            vn-tooltip="Remove ticket"
                            icon="delete"
                            ng-click="$ctrl.showDeleteConfirm(ticket.id)"
                            tabindex="-1">
                        </vn-icon-button>
                    </vn-td>
                </vn-tr>
            </vn-tbody>
        </vn-table>
    </vn-card>
</form>

<vn-ticket-descriptor-popover 
    vn-id="ticketDescriptor">
</vn-ticket-descriptor-popover>
<vn-client-descriptor-popover
    vn-id="clientDescriptor">
</vn-client-descriptor-popover>
<vn-confirm 
    vn-id="confirm"
    question="Delete ticket from route?"
    on-response="$ctrl.deleteFromRoute(response)">
</vn-confirm>