<vn-crud-model auto-load="false"
    vn-id="model"
    url="/ticket/api/TicketWeeklies"
    filter="::$ctrl.filter"
    limit="20"
    data="weeklies"
    primary-key="ticketFk"
    auto-save="true"
    on-save="$ctrl.onSave()">
</vn-crud-model>
<form name="form">
    <div margin-medium>
        <vn-card margin-medium-v pad-medium>
            <vn-table model="model">
                <vn-thead>
                    <vn-tr>
                        <vn-th number field="ticketFk">Ticket ID</vn-th>
                        <vn-th field="weekDay">Client</vn-th>
                        <vn-th>Turn</vn-th>
                        <vn-th>Warehouse</vn-th>
                        <vn-th>Salesperson</vn-th>
                    </vn-tr>
                </vn-thead>
                <vn-tbody>
                    <vn-tr ng-repeat="weekly in weeklies" class="clickable" ui-sref="ticket.card.summary({id: {{::weekly.ticketFk}}})">
                        <vn-td number>
                            <span class="link"
                                ng-click="$ctrl.showTicketDescriptor($event, weekly.ticketFk)">
                                {{weekly.ticketFk}}
                            </span>
                        </vn-td>
                        <vn-td>
                            <span class="link" ng-click="$ctrl.showClientDescriptor($event, weekly.ticket.client.id)">
                                {{::weekly.ticket.client.name}}
                            </span>
                        </vn-td>
                        <vn-td ng-click="$ctrl.preventNavigation($event)">
                            <vn-autocomplete
                                vn-one
                                field="weekly.weekDay"
                                data="$ctrl.weekdays"
                                show-field="name"
                                translate-fields="['name']"
                                value-field="id"
                                order="id">
                            </vn-autocomplete>
                        </vn-td>
                        <vn-td>{{::weekly.ticket.warehouse.name}}</vn-td>
                        <vn-td>{{::weekly.ticket.client.salesPerson.firstName}} {{::weekly.ticket.client.salesPerson.name}}</vn-td>
                        <vn-td>
                            <vn-icon-button
                                icon="delete"
                                ng-click="model.remove($index)"
                                vn-tooltip="Delete">
                            </vn-icon-button>
                        </vn-td>
                    </vn-tr>
                </vn-tbody>
                <vn-empty-rows ng-if="model.data.length === 0" translate>
                    No results
                </vn-empty-rows>
            </vn-table>
        </vn-card>
        <vn-pagination model="model"></vn-pagination>
    </div>
</form>
<vn-client-descriptor-popover vn-id="clientDescriptor"></vn-client-descriptor-popover>
<vn-ticket-descriptor-popover 
    vn-id="ticketDescriptor">
</vn-ticket-descriptor-popover>
<vn-confirm
    vn-id="deleteWeekly"
    on-response="$ctrl.returnDialog(response)"
    question="Delete weekly"
    message="Are you sure you want to delete this weekly?">
</vn-confirm>