2019-03-29 06:29:09 +00:00
|
|
|
import ngModule from '../module';
|
2020-03-17 10:17:50 +00:00
|
|
|
import Section from 'salix/components/section';
|
2019-03-29 06:29:09 +00:00
|
|
|
import './style.scss';
|
|
|
|
|
2020-03-17 10:17:50 +00:00
|
|
|
class Controller extends Section {
|
2019-03-29 06:29:09 +00:00
|
|
|
open() {
|
2020-03-17 10:17:50 +00:00
|
|
|
this.$.SMSDialog.show();
|
2019-03-29 06:29:09 +00:00
|
|
|
}
|
|
|
|
|
2020-01-14 08:10:54 +00:00
|
|
|
charactersRemaining() {
|
2020-03-17 10:17:50 +00:00
|
|
|
const element = this.$.message;
|
2020-02-14 11:01:17 +00:00
|
|
|
const value = element.input.value;
|
2020-01-14 08:10:54 +00:00
|
|
|
|
2020-02-14 11:01:17 +00:00
|
|
|
const maxLength = 160;
|
|
|
|
const textAreaLength = new Blob([value]).size;
|
|
|
|
return maxLength - textAreaLength;
|
2020-01-14 08:10:54 +00:00
|
|
|
}
|
|
|
|
|
2020-07-29 08:47:48 +00:00
|
|
|
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`);
|
|
|
|
|
|
|
|
this.$http.post(`Clients/${this.$params.id}/sendSms`, this.sms).then(res => {
|
|
|
|
this.vnApp.showMessage(this.$t('SMS sent!'));
|
|
|
|
|
|
|
|
if (res.data) this.emit('send', {response: res.data});
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
this.vnApp.showError(this.$t(e.message));
|
|
|
|
return false;
|
2019-03-29 06:29:09 +00:00
|
|
|
}
|
2020-02-10 12:22:43 +00:00
|
|
|
return true;
|
2019-03-29 06:29:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Controller.$inject = ['$element', '$scope', '$http', '$translate', 'vnApp'];
|
|
|
|
|
2020-07-24 12:22:30 +00:00
|
|
|
ngModule.vnComponent('vnClientSms', {
|
2019-03-29 06:29:09 +00:00
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
sms: '<',
|
|
|
|
}
|
|
|
|
});
|