2018-01-18 07:38:04 +00:00
|
|
|
import ngModule from '../module';
|
2020-03-17 13:43:46 +00:00
|
|
|
import Section from 'salix/components/section';
|
2021-03-04 06:56:31 +00:00
|
|
|
class Controller extends Section {
|
2021-03-04 19:11:10 +00:00
|
|
|
get item() {
|
|
|
|
return this._item;
|
|
|
|
}
|
|
|
|
|
|
|
|
set item(value) {
|
|
|
|
this._item = value;
|
|
|
|
if (value)
|
|
|
|
this.getBotanicalData();
|
|
|
|
}
|
|
|
|
|
2021-03-04 06:56:31 +00:00
|
|
|
showGenus(event) {
|
|
|
|
if (event.defaultPrevented) return;
|
|
|
|
event.preventDefault();
|
2018-01-18 07:38:04 +00:00
|
|
|
|
2021-03-04 06:56:31 +00:00
|
|
|
this.$.genus.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
showSpecies(event) {
|
|
|
|
if (event.defaultPrevented) return;
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
this.$.species.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
onGenusAccept() {
|
|
|
|
try {
|
|
|
|
if (!this.data.name)
|
|
|
|
throw new Error(`The name of the genus can't be empty`);
|
2021-03-04 19:11:10 +00:00
|
|
|
|
2021-03-04 06:56:31 +00:00
|
|
|
this.$http.post(`genera`, this.data).then(res => {
|
2021-03-04 19:11:10 +00:00
|
|
|
this.vnApp.showMessage(this.$t('The genus has been created'));
|
2021-03-04 06:56:31 +00:00
|
|
|
this.emit('response', {$response: res.data});
|
2021-03-08 11:38:54 +00:00
|
|
|
this.onGenusResponse(res.data);
|
2021-03-04 06:56:31 +00:00
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
this.vnApp.showError(this.$t(e.message));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
onSpeciesAccept() {
|
|
|
|
try {
|
|
|
|
if (!this.data.name)
|
2021-03-08 11:38:54 +00:00
|
|
|
throw new Error(`The name of the species can't be empty`);
|
2021-03-04 19:11:10 +00:00
|
|
|
|
2021-03-04 06:56:31 +00:00
|
|
|
this.$http.post(`species`, this.data).then(res => {
|
2021-03-08 11:38:54 +00:00
|
|
|
this.vnApp.showMessage(this.$t('The species has been created'));
|
2021-03-04 06:56:31 +00:00
|
|
|
this.emit('response', {$response: res.data});
|
2021-03-08 11:38:54 +00:00
|
|
|
this.onSpeciesResponse(res.data);
|
2021-03-04 06:56:31 +00:00
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
this.vnApp.showError(this.$t(e.message));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2021-03-04 19:11:10 +00:00
|
|
|
|
|
|
|
getBotanicalData() {
|
|
|
|
const filter = {
|
|
|
|
where: {itemFk: this.item.id}
|
|
|
|
};
|
|
|
|
const filterParams = encodeURIComponent(JSON.stringify(filter));
|
|
|
|
this.$http.get(`ItemBotanicals?filter=${filterParams}`).then(res => {
|
|
|
|
if (res.data[0])
|
|
|
|
this.botanical = res.data[0];
|
|
|
|
|
|
|
|
else
|
|
|
|
this.botanical = {itemFk: this.item.id};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onSubmit() {
|
|
|
|
this.$.watcher.check();
|
|
|
|
this.$http.patch(`ItemBotanicals`, this.botanical).then(() => {
|
|
|
|
this.$.watcher.notifySaved();
|
|
|
|
this.$.watcher.updateOriginalData();
|
|
|
|
});
|
|
|
|
}
|
2021-03-08 11:38:54 +00:00
|
|
|
|
|
|
|
onGenusResponse(response) {
|
|
|
|
this.botanical.genusFk = response.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
onSpeciesResponse(response) {
|
|
|
|
this.botanical.specieFk = response.id;
|
|
|
|
}
|
2021-03-04 06:56:31 +00:00
|
|
|
}
|
2018-05-25 08:03:45 +00:00
|
|
|
|
2020-07-24 12:22:30 +00:00
|
|
|
ngModule.vnComponent('vnItemBotanical', {
|
2018-05-25 08:03:45 +00:00
|
|
|
template: require('./index.html'),
|
2021-03-04 19:11:10 +00:00
|
|
|
bindings: {
|
|
|
|
item: '<'
|
|
|
|
},
|
2018-05-25 08:03:45 +00:00
|
|
|
controller: Controller
|
2018-01-18 07:38:04 +00:00
|
|
|
});
|