38 lines
1.0 KiB
JavaScript
38 lines
1.0 KiB
JavaScript
|
import ngModule from '../../module';
|
||
|
import Component from 'core/lib/component';
|
||
|
|
||
|
class Controller extends Component { // Comprobar funcionamiento añadir ciudad
|
||
|
open($event) {
|
||
|
if ($event.defaultPrevented) return;
|
||
|
|
||
|
this.$.cityDialog.show();
|
||
|
$event.preventDefault();
|
||
|
}
|
||
|
|
||
|
onAccept() {
|
||
|
try {
|
||
|
if (!this.city.name)
|
||
|
throw new Error(`The city name can't be empty`);
|
||
|
if (!this.city.provinceFk)
|
||
|
throw new Error(`The province can't be empty`);
|
||
|
|
||
|
this.$http.patch(`towns`, this.city).then(res => {
|
||
|
this.vnApp.showMessage(this.$t('The city has been created'));
|
||
|
this.emit('response', {$response: res.data});
|
||
|
});
|
||
|
} catch (e) {
|
||
|
this.vnApp.showError(this.$t(e.message));
|
||
|
return false;
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
ngModule.vnComponent('vnGeoCity', {
|
||
|
template: require('./index.html'),
|
||
|
controller: Controller,
|
||
|
bindings: {
|
||
|
data: '<',
|
||
|
}
|
||
|
});
|