<vn-crud-model
    vn-id="model"
    url="/item/api/ItemNiches"
    fields="['id', 'itemFk', 'warehouseFk', 'code']"
    link="{itemFk: $ctrl.$stateParams.id}"
    data="niches"
    auto-load="true">
</vn-crud-model>
<vn-watcher
    vn-id="watcher"
    data="niches"
    form="form">
</vn-watcher>
<form name="form" ng-submit="$ctrl.onSubmit()" compact>
    <vn-card pad-large>
        <vn-horizontal ng-repeat="niche in niches track by $index">
            <vn-autocomplete
                url="/item/api/Warehouses"
                show-field="name"
                value-field="id"
                field="niche.warehouseFk"
                label="Warehouse"
                vn-acl="buyer,replenisher" vn-one vn-focus>
            </vn-autocomplete>
            <vn-textfield 
                vn-three
                label="Code"
                model="niche.code"
                rule="itemNiche.code"
                vn-acl="buyer,replenisher">
            </vn-textfield>
            <vn-none>
                <vn-icon-button
                    vn-acl="buyer,replenisher"
                    pointer
                    vn-tooltip="Remove niche"
                    icon="delete"
                    ng-click="model.remove($index)">
                </vn-icon-button>
            </vn-none>
        </vn-horizontal>
        <vn-one>
            <vn-icon-button
                vn-acl="buyer, replenisher"
                vn-tooltip="Add niche"
                vn-bind="+"
                icon="add_circle"
                ng-click="model.insert()">
            </vn-icon-button>
        </vn-one>
    </vn-card>
    <vn-button-bar>
        <vn-submit label="Save"></vn-submit>
    </vn-button-bar>
</form>