From 84bf95db1325b811dd489b59568ccd397a05bc9b Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 14 Feb 2020 12:01:17 +0100 Subject: [PATCH] 2106 - Sms max length fix --- modules/client/front/sms/index.html | 13 ++++++++++--- modules/client/front/sms/index.js | 11 ++++++----- modules/client/front/sms/index.spec.js | 12 ++++++++---- modules/client/front/sms/locale/es.yml | 4 +++- modules/ticket/front/sms/index.html | 11 +++++++++-- modules/ticket/front/sms/index.js | 11 ++++++----- modules/ticket/front/sms/index.spec.js | 12 ++++++++---- modules/ticket/front/sms/locale/es.yml | 4 +++- 8 files changed, 53 insertions(+), 25 deletions(-) diff --git a/modules/client/front/sms/index.html b/modules/client/front/sms/index.html index facbb7694..fb2f1dfff 100644 --- a/modules/client/front/sms/index.html +++ b/modules/client/front/sms/index.html @@ -13,20 +13,27 @@ rule> - + - {{'Characters remaining' | translate}}: {{$ctrl.charactersRemaining()}} + {{'Characters remaining' | translate}}: + + {{$ctrl.charactersRemaining()}} + diff --git a/modules/client/front/sms/index.js b/modules/client/front/sms/index.js index 851ce1a66..c7d89e717 100644 --- a/modules/client/front/sms/index.js +++ b/modules/client/front/sms/index.js @@ -17,13 +17,12 @@ class Controller extends Component { } charactersRemaining() { - let elementMaxLength; - let textAreaLength; const element = this.$scope.message; + const value = element.input.value; - textAreaLength = element.input.textLength; - elementMaxLength = element.maxlength; - return elementMaxLength - textAreaLength; + const maxLength = 160; + const textAreaLength = new Blob([value]).size; + return maxLength - textAreaLength; } onResponse(response) { @@ -33,6 +32,8 @@ class Controller extends Component { 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.$translate.instant('SMS sent!')); diff --git a/modules/client/front/sms/index.spec.js b/modules/client/front/sms/index.spec.js index 26a597c17..03d9cbf1d 100644 --- a/modules/client/front/sms/index.spec.js +++ b/modules/client/front/sms/index.spec.js @@ -15,6 +15,11 @@ describe('Client', () => { controller = $componentController('vnClientSms', {$element, $scope}); controller.client = {id: 101}; controller.$params = {id: 101}; + controller.$scope.message = { + input: { + value: 'My SMS' + } + }; })); describe('onResponse()', () => { @@ -56,14 +61,13 @@ describe('Client', () => { it('should return the characters remaining in a element', () => { controller.$scope.message = { input: { - textLength: 50 - }, - maxlength: 150 + value: 'My message 0€' + } }; let result = controller.charactersRemaining(); - expect(result).toEqual(100); + expect(result).toEqual(145); }); }); }); diff --git a/modules/client/front/sms/locale/es.yml b/modules/client/front/sms/locale/es.yml index 4438e4fce..64c3fcca6 100644 --- a/modules/client/front/sms/locale/es.yml +++ b/modules/client/front/sms/locale/es.yml @@ -4,4 +4,6 @@ Message: Mensaje SMS sent!: ¡SMS enviado! Characters remaining: Carácteres restantes The destination can't be empty: El destinatario no puede estar vacio -The message can't be empty: El mensaje no puede estar vacio \ No newline at end of file +The message can't be empty: El mensaje no puede estar vacio +The message it's too long: El mensaje es demasiado largo +Special characters like accents counts as a multiple: Carácteres especiales como los acentos cuentan como varios \ No newline at end of file diff --git a/modules/ticket/front/sms/index.html b/modules/ticket/front/sms/index.html index f74bc29e5..2003aa4fd 100644 --- a/modules/ticket/front/sms/index.html +++ b/modules/ticket/front/sms/index.html @@ -18,15 +18,22 @@ vn-id="message" label="Message" ng-model="$ctrl.sms.message" + info="Special characters like accents counts as a multiple" rows="5" - maxlength="160" required="true" rule> - {{'Characters remaining' | translate}}: {{$ctrl.charactersRemaining()}} + {{'Characters remaining' | translate}}: + + {{$ctrl.charactersRemaining()}} + diff --git a/modules/ticket/front/sms/index.js b/modules/ticket/front/sms/index.js index 0d639d46e..ac1131513 100644 --- a/modules/ticket/front/sms/index.js +++ b/modules/ticket/front/sms/index.js @@ -17,13 +17,12 @@ class Controller extends Component { } charactersRemaining() { - let elementMaxLength; - let textAreaLength; const element = this.$scope.message; + const value = element.input.value; - textAreaLength = element.input.textLength; - elementMaxLength = element.maxlength; - return elementMaxLength - textAreaLength; + const maxLength = 160; + const textAreaLength = new Blob([value]).size; + return maxLength - textAreaLength; } onResponse(response) { @@ -33,6 +32,8 @@ class Controller extends Component { 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(`Tickets/${this.$params.id}/sendSms`, this.sms).then(res => { this.vnApp.showMessage(this.$translate.instant('SMS sent!')); diff --git a/modules/ticket/front/sms/index.spec.js b/modules/ticket/front/sms/index.spec.js index d02b3f3eb..96c10edd1 100644 --- a/modules/ticket/front/sms/index.spec.js +++ b/modules/ticket/front/sms/index.spec.js @@ -14,6 +14,11 @@ describe('Ticket', () => { $element = angular.element(''); controller = $componentController('vnTicketSms', {$element, $scope}); controller.$params = {id: 11}; + controller.$scope.message = { + input: { + value: 'My SMS' + } + }; })); describe('onResponse()', () => { @@ -55,14 +60,13 @@ describe('Ticket', () => { it('should return the characters remaining in a element', () => { controller.$scope.message = { input: { - textLength: 50 - }, - maxlength: 150 + value: 'My message 0€' + } }; let result = controller.charactersRemaining(); - expect(result).toEqual(100); + expect(result).toEqual(145); }); }); }); diff --git a/modules/ticket/front/sms/locale/es.yml b/modules/ticket/front/sms/locale/es.yml index 4438e4fce..64c3fcca6 100644 --- a/modules/ticket/front/sms/locale/es.yml +++ b/modules/ticket/front/sms/locale/es.yml @@ -4,4 +4,6 @@ Message: Mensaje SMS sent!: ¡SMS enviado! Characters remaining: Carácteres restantes The destination can't be empty: El destinatario no puede estar vacio -The message can't be empty: El mensaje no puede estar vacio \ No newline at end of file +The message can't be empty: El mensaje no puede estar vacio +The message it's too long: El mensaje es demasiado largo +Special characters like accents counts as a multiple: Carácteres especiales como los acentos cuentan como varios \ No newline at end of file