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

55 lines
1.6 KiB
JavaScript
Raw Normal View History

import ngModule from '../module';
2020-03-17 13:43:46 +00:00
import Section from 'salix/components/section';
class Controller extends Section {
showGenus(event) {
if (event.defaultPrevented) return;
event.preventDefault();
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`);
console.log(this.data);
this.$http.post(`genera`, this.data).then(res => {
this.vnApp.showMessage(this.$t('The genus has been created. You can save the data now'));
this.emit('response', {$response: res.data});
});
} catch (e) {
this.vnApp.showError(this.$t(e.message));
return false;
}
return true;
}
onSpeciesAccept() {
try {
if (!this.data.name)
throw new Error(`The name of the specie can't be empty`);
console.log(this.data);
this.$http.post(`species`, this.data).then(res => {
this.vnApp.showMessage(this.$t('The specie has been created.'));
this.emit('response', {$response: res.data});
});
} catch (e) {
this.vnApp.showError(this.$t(e.message));
return false;
}
return true;
}
}
ngModule.vnComponent('vnItemBotanical', {
template: require('./index.html'),
controller: Controller
});