import ngModule from '../module'; import Section from 'salix/components/section'; class Controller extends Section { showIntrastat(event) { if (event.defaultPrevented) return; event.preventDefault(); this.newIntrastat = { taxClassFk: this.item.taxClassFk }; this.$.intrastat.show(); } onIntrastatAccept() { const query = `Items/${this.$params.id}/createIntrastat`; return this.$http.patch(query, this.newIntrastat) .then(res => this.item.intrastatFk = res.data.id); } itemSearchFunc($search) { return /^\d+$/.test($search) ? {id: $search} : {name: {like: '%' + $search + '%'}}; } showFilterDialog(item) { this.activeItem = item; this.itemFilterParams = {}; this.itemFilter = { include: [ { relation: 'producer', scope: { fields: ['name'] } }, { relation: 'ink', scope: { fields: ['name'] } } ] }; this.$.filterDialog.show(); } selectItem(id) { this.activeItem['id'] = id; this.$.filterDialog.hide(); } filter() { const filter = this.itemFilter; const params = this.itemFilterParams; const where = {}; for (let key in params) { const value = params[key]; if (!value) continue; switch (key) { case 'name': where[key] = {like: `%${value}%`}; break; case 'producerFk': case 'typeFk': case 'size': case 'inkFk': where[key] = value; } } filter.where = where; this.$.itemsModel.applyFilter(filter); } } ngModule.vnComponent('vnItemBasicData', { template: require('./index.html'), bindings: { item: '<' }, controller: Controller });