<mg-ajax path="Routes/{{patch.params.id}}" options="vnPatch"></mg-ajax>
<vn-watcher
    vn-id="watcher"
    data="$ctrl.route"
    form="form"
    save="patch">
</vn-watcher>
<form name="form" ng-submit="$ctrl.onSubmit()" class="vn-w-md">
    <vn-card class="vn-pa-lg">
        <vn-horizontal>
            <vn-worker-autocomplete
                ng-model="$ctrl.route.workerFk"
                show-field="nickname"
                vn-name="worker">
            </vn-worker-autocomplete>
            <vn-autocomplete
                label="Vehicle"
                ng-model="$ctrl.route.vehicleFk"
                data="$ctrl.vehicles"
                show-field="numberPlate"
                value-field="id"
                order="false"
                vn-name="vehicle">
                <tpl-item>{{::numberPlate}} - {{::name}}</tpl-item>
            </vn-autocomplete>
        </vn-horizontal>
        <vn-horizontal>
            <vn-date-picker
                label="Created"
                ng-model="$ctrl.route.created"
                vn-name="created"> 
            </vn-date-picker>
            <vn-autocomplete
                ng-model="$ctrl.route.agencyModeFk"
                url="AgencyModes"
                show-field="name"
                value-field="id"
                label="Agency"
                vn-name="agencyMode">
            </vn-autocomplete>
        </vn-horizontal>
        <vn-horizontal>
            <vn-input-number
                label="Km start"
                ng-model="$ctrl.route.kmStart"
                vn-name="kmStart"
                rule>
            </vn-input-number>
            <vn-input-number
                label="Km end"
                ng-model="$ctrl.route.kmEnd"
                vn-name="kmEnd"
                rule>
            </vn-input-number>
        </vn-horizontal>
        <vn-horizontal>
            <vn-input-time
                label="Hour started"
                ng-model="$ctrl.route.started"
                vn-name="started">
            </vn-input-time>
            <vn-input-time
                label="Hour finished"
                ng-model="$ctrl.route.finished"
                vn-name="finished">
            </vn-input-time>
            <vn-check
                class="vn-mr-md"
                label="Is served"
                ng-model="$ctrl.route.isOk"
                vn-name="isOk">
            </vn-check>
        </vn-horizontal>
        <vn-horizontal>
            <vn-textArea
                label="Description"
                ng-model="$ctrl.route.description"
                vn-name="description"
                rule
                vn-focus>
            </vn-textArea>
        </vn-horizontal>
    </vn-card>
    <vn-button-bar>
        <vn-submit
            disabled="!watcher.dataChanged()"
            label="Save">
        </vn-submit>
        <vn-button
            class="cancel"
            label="Undo changes"
            disabled="!watcher.dataChanged()"
            ng-click="watcher.loadOriginalData()">
        </vn-button>
    </vn-button-bar>
</form>