salix/modules/route/front/sms/index.js

48 lines
1.3 KiB
JavaScript
Raw Normal View History

2022-10-20 13:04:25 +00:00
import ngModule from '../module';
import Component from 'core/lib/component';
import './style.scss';
class Controller extends Component {
open() {
this.$.SMSDialog.show();
}
charactersRemaining() {
const element = this.$.message;
const value = element.input.value;
const maxLength = 160;
const textAreaLength = new Blob([value]).size;
return maxLength - textAreaLength;
}
onResponse() {
try {
if (!this.sms.destination)
throw new Error(`The destination can't be empty`);
if (!this.sms.message)
throw new Error(`The message can't be empty`);
if (this.charactersRemaining() < 0)
throw new Error(`The message it's too long`);
2022-10-20 13:04:59 +00:00
this.$http.post(`Routes/sendSms`, this.sms).then(res => {
2023-01-12 10:48:44 +00:00
this.vnApp.showMessage(this.$t('SMS sent'));
2022-10-20 13:04:25 +00:00
if (res.data) this.emit('send', {response: res.data});
});
} catch (e) {
this.vnApp.showError(this.$t(e.message));
return false;
}
return true;
}
}
ngModule.vnComponent('vnRouteSms', {
template: require('./index.html'),
controller: Controller,
bindings: {
sms: '<',
}
});