<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-autocomplete
                vn-one
                ng-model="$ctrl.route.workerFk"
                url="Workers/activeWithInheritedRole"
                show-field="nickname"
                search-function="{firstName: $search}"
                value-field="id"
                where="{role: 'employee'}"
                label="Worker">
                <tpl-item>
                    <div>{{name}} - {{nickname}}</div>
                </tpl-item>
            </vn-autocomplete>
            <vn-autocomplete
                vn-one
                ng-model="$ctrl.route.vehicleFk"
                url="Vehicles"
                show-field="numberPlate"
                value-field="id"
                label="Vehicle">
            </vn-autocomplete>
        </vn-horizontal>
        <vn-horizontal>
            <vn-date-picker
                vn-one
                label="Created"
                ng-model="$ctrl.route.created">
            </vn-date-picker>
            <vn-autocomplete
                vn-one
                ng-model="$ctrl.route.agencyModeFk"
                url="AgencyModes"
                show-field="name"
                value-field="id"
                label="Agency">
            </vn-autocomplete>
        </vn-horizontal>
        <vn-horizontal>
            <vn-input-number
                vn-one
                label="Km start"
                ng-model="$ctrl.route.kmStart"
                rule>
            </vn-input-number>
            <vn-input-number
                vn-one
                label="Km end"
                ng-model="$ctrl.route.kmEnd"
                rule>
            </vn-input-number>
        </vn-horizontal>
        <vn-horizontal>
            <vn-input-time
                label="Hour started"
                ng-model="$ctrl.route.started">
            </vn-input-time>
            <vn-input-time
                label="Hour finished"
                ng-model="$ctrl.route.finished">
        </vn-input-time>
        </vn-horizontal>
        <vn-horizontal>
            <vn-textArea
                vn-one
                label="Description"
                ng-model="$ctrl.route.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>