salix/modules/item/front/index/index.js

76 lines
1.9 KiB
JavaScript

import ngModule from '../module';
import './style.scss';
class Controller {
constructor($http, $state, $scope, aclService) {
this.aclService = aclService;
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();
}
showItemDescriptor(event, itemFk) {
if (event.defaultPrevented) return;
event.preventDefault();
event.stopPropagation();
this.$.itemDescriptor.itemFk = itemFk;
this.$.itemDescriptor.parent = event.target;
this.$.itemDescriptor.show();
}
showWorkerDescriptor(event, workerFk) {
if (event.defaultPrevented) return;
event.preventDefault();
event.stopPropagation();
this.selectedWorker = workerFk;
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(`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', 'aclService'];
ngModule.component('vnItemIndex', {
template: require('./index.html'),
controller: Controller
});