2020-01-15 12:27:14 +00:00
|
|
|
import ngModule from '../module';
|
|
|
|
import Component from 'core/lib/component';
|
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
class Controller extends Component {
|
|
|
|
constructor($element, $scope, $http, $translate, vnApp) {
|
|
|
|
super($element, $scope);
|
|
|
|
|
|
|
|
this.$scope = $scope;
|
|
|
|
this.$http = $http;
|
|
|
|
this.$translate = $translate;
|
|
|
|
this.vnApp = vnApp;
|
|
|
|
}
|
|
|
|
|
|
|
|
open() {
|
|
|
|
this.$scope.SMSDialog.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
charactersRemaining() {
|
|
|
|
const element = this.$scope.message;
|
2020-02-14 11:01:17 +00:00
|
|
|
const value = element.input.value;
|
2020-01-15 12:27:14 +00:00
|
|
|
|
2020-02-14 11:01:17 +00:00
|
|
|
const maxLength = 160;
|
|
|
|
const textAreaLength = new Blob([value]).size;
|
|
|
|
return maxLength - textAreaLength;
|
2020-01-15 12:27:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onResponse(response) {
|
|
|
|
if (response === 'accept') {
|
2020-02-10 12:22:43 +00:00
|
|
|
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`);
|
2020-02-14 11:01:17 +00:00
|
|
|
if (this.charactersRemaining() < 0)
|
|
|
|
throw new Error(`The message it's too long`);
|
2020-02-10 12:22:43 +00:00
|
|
|
|
|
|
|
this.$http.post(`Tickets/${this.$params.id}/sendSms`, this.sms).then(res => {
|
|
|
|
this.vnApp.showMessage(this.$translate.instant('SMS sent!'));
|
|
|
|
|
|
|
|
if (res.data) this.emit('send', {response: res.data});
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
this.vnApp.showError(this.$translate.instant(e.message));
|
|
|
|
return false;
|
|
|
|
}
|
2020-01-15 12:27:14 +00:00
|
|
|
}
|
2020-02-10 12:22:43 +00:00
|
|
|
return true;
|
2020-01-15 12:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Controller.$inject = ['$element', '$scope', '$http', '$translate', 'vnApp'];
|
|
|
|
|
|
|
|
ngModule.component('vnTicketSms', {
|
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
sms: '<',
|
|
|
|
}
|
|
|
|
});
|