<mg-ajax path="Workers/{{patch.params.id}}" options="vnPatch"></mg-ajax>
<vn-watcher
    vn-id="watcher"
    data="$ctrl.worker"
    form="form"
    save="patch">
</vn-watcher>
<form name="form" ng-submit="$ctrl.onSubmit()" class="vn-w-md">
    <vn-card class="vn-pa-lg">
        <vn-vertical>
            <vn-horizontal>
                <vn-textfield
                    vn-one
                    label="Name" 
                    ng-model="$ctrl.worker.firstName"
                    rule>
                </vn-textfield>
                <vn-textfield
                    vn-one
                    label="Last name"
                    ng-model="$ctrl.worker.lastName"
                    rule>
                </vn-textfield>
            </vn-horizontal>
            <vn-horizontal>
                <vn-textfield
                    vn-one 
                    label="Phone" 
                    ng-model="$ctrl.worker.phone"
                    rule>
                </vn-textfield>
                <vn-autocomplete
                    ng-model="$ctrl.worker.bossFk"
                    url="Workers/activeWithInheritedRole"
                    show-field="nickname"
                    search-function="{firstName: $search}"
                    where="{role: 'employee'}"
                    label="Boss">
                </vn-autocomplete>
            </vn-horizontal>
            <vn-horizontal>
                <vn-autocomplete
                    label="Marital status"
                    data="$ctrl.maritalStatus"
                    show-field="name"
                    value-field="code"
                    ng-model="$ctrl.worker.maritalStatus">
                </vn-autocomplete>
                <vn-autocomplete
                    ng-model="$ctrl.worker.originCountryFk"
                    url="Countries"
                    fields="['id', 'country', 'code']"
                    show-field="country"
                    value-field="id"
                    label="Origin country">
                </vn-autocomplete>
            </vn-horizontal>
            <vn-horizontal>
                <vn-autocomplete
                    ng-model="$ctrl.worker.educationLevelFk"
                    url="EducationLevels"
                    fields="['id', 'name']"
                    show-field="name"
                    value-field="id"
                    label="Education level">
                </vn-autocomplete>
                <vn-textfield
                    vn-one 
                    label="SSN" 
                    ng-model="$ctrl.worker.SSN"
                    rule>
                </vn-textfield>
            </vn-horizontal>
        </vn-vertical>
    </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>