import ngModule from '../module'; import './style.scss'; class Controller { constructor($http, $state, $scope) { this.$http = $http; this.$state = $state; this.$ = $scope; this.itemSelected = null; this.imagesPath = '//verdnatura.es/vn-image-data/catalog'; this.showFields = { id: false, actions: false }; } stopEvent(event) { event.preventDefault(); event.stopImmediatePropagation(); } onSearch(params) { if (params) this.$.model.applyFilter(null, params); else this.$.model.clear(); } showItemDescriptor(event, itemFk) { if (event.defaultPrevented) return; event.preventDefault(); event.stopPropagation(); this.quicklinks = { btnThree: { icon: 'icon-transaction', state: `item.card.diary({ id: ${itemFk}, })`, tooltip: 'Item diary' } }; this.$.itemDescriptor.itemFk = itemFk; this.$.itemDescriptor.parent = event.target; this.$.itemDescriptor.show(); } showWorkerDescriptor(event, userId) { if (event.defaultPrevented) return; event.preventDefault(); event.stopPropagation(); this.selectedWorker = userId; this.$.workerDescriptor.parent = event.target; this.$.workerDescriptor.show(); } cloneItem(event, item) { this.stopEvent(event); this.itemSelected = item; this.$.clone.show(); } onCloneAccept(response) { if (!(response == 'ACCEPT' && this.itemSelected)) return; this.$http.post(`/item/api/Items/${this.itemSelected.id}/clone`).then(res => { if (res && res.data && res.data.id) this.$state.go('item.card.tags', {id: res.data.id}); }); this.itemSelected = null; } preview(event, item) { this.stopEvent(event); this.itemSelected = item; this.$.preview.show(); } } Controller.$inject = ['$http', '$state', '$scope']; ngModule.component('vnItemIndex', { template: require('./index.html'), controller: Controller });