From 4e97d931f7f9a057b72956fe753d8d6a5a4980cd Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Mon, 21 Nov 2022 08:45:45 +0100 Subject: [PATCH] refs #4791 @2h --- front/core/components/index.js | 1 + .../core/components/sendSms}/index.html | 0 front/core/components/sendSms/index.js | 52 +++++++++++++ .../core/components/sendSms}/locale/es.yml | 0 .../core/components/sendSms}/style.scss | 0 modules/client/front/descriptor/index.html | 8 +- modules/client/front/descriptor/index.js | 5 +- modules/client/front/index.js | 1 - modules/client/front/sms/index.js | 49 ------------ modules/client/front/sms/index.spec.js | 74 ------------------- .../ticket/front/descriptor-menu/index.html | 4 +- modules/ticket/front/descriptor-menu/index.js | 3 +- modules/ticket/front/index.js | 1 - modules/ticket/front/sms/index.html | 45 ----------- modules/ticket/front/sms/index.js | 47 ------------ modules/ticket/front/sms/index.spec.js | 71 ------------------ modules/ticket/front/sms/locale/es.yml | 9 --- modules/ticket/front/sms/style.scss | 5 -- 18 files changed, 65 insertions(+), 310 deletions(-) rename {modules/client/front/sms => front/core/components/sendSms}/index.html (100%) create mode 100644 front/core/components/sendSms/index.js rename {modules/client/front/sms => front/core/components/sendSms}/locale/es.yml (100%) rename {modules/client/front/sms => front/core/components/sendSms}/style.scss (100%) delete mode 100644 modules/client/front/sms/index.js delete mode 100644 modules/client/front/sms/index.spec.js delete mode 100644 modules/ticket/front/sms/index.html delete mode 100644 modules/ticket/front/sms/index.js delete mode 100644 modules/ticket/front/sms/index.spec.js delete mode 100644 modules/ticket/front/sms/locale/es.yml delete mode 100644 modules/ticket/front/sms/style.scss diff --git a/front/core/components/index.js b/front/core/components/index.js index 86ab89212..723b39baf 100644 --- a/front/core/components/index.js +++ b/front/core/components/index.js @@ -53,3 +53,4 @@ import './datalist'; import './contextmenu'; import './rating'; import './smart-table'; +import './sendSms'; diff --git a/modules/client/front/sms/index.html b/front/core/components/sendSms/index.html similarity index 100% rename from modules/client/front/sms/index.html rename to front/core/components/sendSms/index.html diff --git a/front/core/components/sendSms/index.js b/front/core/components/sendSms/index.js new file mode 100644 index 000000000..3d67627dd --- /dev/null +++ b/front/core/components/sendSms/index.js @@ -0,0 +1,52 @@ +import ngModule from '../../module'; +import './style.scss'; + +export default class sendSmsDialog { + constructor($element, $scope, $http, $translate, vnApp) { + this.$element = $element; + this.$scope = $scope; + this.$http = $http; + this.$t = $translate; + this.vnApp = vnApp; + } + + open(route) { + this.route = route; + this.$scope.SMSDialog.show(); + } + + charactersRemaining() { + const element = this.sms.message; + const maxLength = 160; + return maxLength - element.length; + } + + 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(this.route, this.sms).then(res => { + this.vnApp.showMessage(this.$t.instant('SMS sent!')); + }); + } catch (e) { + this.vnApp.showError(this.$t.instant(e.message)); + return false; + } + return true; + } +} + +sendSmsDialog.$inject = ['$element', '$scope', '$http', '$translate', 'vnApp']; + +ngModule.vnComponent('vnSmsDialog', { + template: require('./index.html'), + controller: sendSmsDialog, + bindings: { + sms: '<', + } +}); diff --git a/modules/client/front/sms/locale/es.yml b/front/core/components/sendSms/locale/es.yml similarity index 100% rename from modules/client/front/sms/locale/es.yml rename to front/core/components/sendSms/locale/es.yml diff --git a/modules/client/front/sms/style.scss b/front/core/components/sendSms/style.scss similarity index 100% rename from modules/client/front/sms/style.scss rename to front/core/components/sendSms/style.scss diff --git a/modules/client/front/descriptor/index.html b/modules/client/front/descriptor/index.html index cad226416..9973a6471 100644 --- a/modules/client/front/descriptor/index.html +++ b/modules/client/front/descriptor/index.html @@ -113,10 +113,10 @@ - - + + diff --git a/modules/client/front/descriptor/index.js b/modules/client/front/descriptor/index.js index 4a0d1cd2a..0051afe94 100644 --- a/modules/client/front/descriptor/index.js +++ b/modules/client/front/descriptor/index.js @@ -37,7 +37,10 @@ class Controller extends Descriptor { destination: this.$params.phone || client.mobile || client.phone, message: this.$params.message || '' }; - this.$.sms.open(); + + const route = `Clients/${this.id}/sendSms`; + + this.$.sms.open(route); } } diff --git a/modules/client/front/index.js b/modules/client/front/index.js index a5782c789..ff767bc9e 100644 --- a/modules/client/front/index.js +++ b/modules/client/front/index.js @@ -35,7 +35,6 @@ import './sample/index'; import './sample/create'; import './web-payment'; import './log'; -import './sms'; import './postcode'; import './postcode/province'; import './postcode/city'; diff --git a/modules/client/front/sms/index.js b/modules/client/front/sms/index.js deleted file mode 100644 index 701ee39af..000000000 --- a/modules/client/front/sms/index.js +++ /dev/null @@ -1,49 +0,0 @@ -import ngModule from '../module'; -import Section from 'salix/components/section'; -import './style.scss'; - -class Controller extends Section { - 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`); - - 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; - } - return true; - } -} - -Controller.$inject = ['$element', '$scope', '$http', '$translate', 'vnApp']; - -ngModule.vnComponent('vnClientSms', { - template: require('./index.html'), - controller: Controller, - bindings: { - sms: '<', - } -}); diff --git a/modules/client/front/sms/index.spec.js b/modules/client/front/sms/index.spec.js deleted file mode 100644 index 793c80d6e..000000000 --- a/modules/client/front/sms/index.spec.js +++ /dev/null @@ -1,74 +0,0 @@ -import './index'; - -describe('Client', () => { - describe('Component vnClientSms', () => { - let controller; - let $httpBackend; - let $element; - - beforeEach(ngModule('client')); - - beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => { - $httpBackend = _$httpBackend_; - let $scope = $rootScope.$new(); - $element = angular.element(''); - controller = $componentController('vnClientSms', {$element, $scope}); - controller.client = {id: 1101}; - controller.$params = {id: 1101}; - controller.$.message = { - input: { - value: 'My SMS' - } - }; - })); - - describe('onResponse()', () => { - it('should perform a POST query and show a success snackbar', () => { - let params = {destinationFk: 1101, destination: 111111111, message: 'My SMS'}; - controller.sms = {destinationFk: 1101, destination: 111111111, message: 'My SMS'}; - - jest.spyOn(controller.vnApp, 'showMessage'); - $httpBackend.expect('POST', `Clients/1101/sendSms`, params).respond(200, params); - - controller.onResponse(); - $httpBackend.flush(); - - expect(controller.vnApp.showMessage).toHaveBeenCalledWith('SMS sent!'); - }); - - it('should call onResponse without the destination and show an error snackbar', () => { - controller.sms = {destinationFk: 1101, message: 'My SMS'}; - - jest.spyOn(controller.vnApp, 'showError'); - - controller.onResponse('accept'); - - expect(controller.vnApp.showError).toHaveBeenCalledWith(`The destination can't be empty`); - }); - - it('should call onResponse without the message and show an error snackbar', () => { - controller.sms = {destinationFk: 1101, destination: 222222222}; - - jest.spyOn(controller.vnApp, 'showError'); - - controller.onResponse('accept'); - - expect(controller.vnApp.showError).toHaveBeenCalledWith(`The message can't be empty`); - }); - }); - - describe('charactersRemaining()', () => { - it('should return the characters remaining in a element', () => { - controller.$.message = { - input: { - value: 'My message 0€' - } - }; - - let result = controller.charactersRemaining(); - - expect(result).toEqual(145); - }); - }); - }); -}); diff --git a/modules/ticket/front/descriptor-menu/index.html b/modules/ticket/front/descriptor-menu/index.html index 0c04b42fb..eb15901d6 100644 --- a/modules/ticket/front/descriptor-menu/index.html +++ b/modules/ticket/front/descriptor-menu/index.html @@ -280,10 +280,10 @@ - - + - -
- - - - - - - - - - - {{'Characters remaining' | translate}}: - - {{$ctrl.charactersRemaining()}} - - - -
-
- - - - - \ No newline at end of file diff --git a/modules/ticket/front/sms/index.js b/modules/ticket/front/sms/index.js deleted file mode 100644 index 6bc252dc1..000000000 --- a/modules/ticket/front/sms/index.js +++ /dev/null @@ -1,47 +0,0 @@ -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`); - - this.$http.post(`Tickets/${this.sms.ticketId}/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; - } - return true; - } -} - -ngModule.vnComponent('vnTicketSms', { - template: require('./index.html'), - controller: Controller, - bindings: { - sms: '<', - } -}); diff --git a/modules/ticket/front/sms/index.spec.js b/modules/ticket/front/sms/index.spec.js deleted file mode 100644 index b133db04d..000000000 --- a/modules/ticket/front/sms/index.spec.js +++ /dev/null @@ -1,71 +0,0 @@ -import './index'; - -describe('Ticket', () => { - describe('Component vnTicketSms', () => { - let controller; - let $httpBackend; - - beforeEach(ngModule('ticket')); - - beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => { - $httpBackend = _$httpBackend_; - let $scope = $rootScope.$new(); - const $element = angular.element(''); - controller = $componentController('vnTicketSms', {$element, $scope}); - controller.$.message = { - input: { - value: 'My SMS' - } - }; - })); - - describe('onResponse()', () => { - it('should perform a POST query and show a success snackbar', () => { - let params = {ticketId: 11, destinationFk: 1101, destination: 111111111, message: 'My SMS'}; - controller.sms = {ticketId: 11, destinationFk: 1101, destination: 111111111, message: 'My SMS'}; - - jest.spyOn(controller.vnApp, 'showMessage'); - $httpBackend.expect('POST', `Tickets/11/sendSms`, params).respond(200, params); - - controller.onResponse(); - $httpBackend.flush(); - - expect(controller.vnApp.showMessage).toHaveBeenCalledWith('SMS sent!'); - }); - - it('should call onResponse without the destination and show an error snackbar', () => { - controller.sms = {destinationFk: 1101, message: 'My SMS'}; - - jest.spyOn(controller.vnApp, 'showError'); - - controller.onResponse(); - - expect(controller.vnApp.showError).toHaveBeenCalledWith(`The destination can't be empty`); - }); - - it('should call onResponse without the message and show an error snackbar', () => { - controller.sms = {destinationFk: 1101, destination: 222222222}; - - jest.spyOn(controller.vnApp, 'showError'); - - controller.onResponse(); - - expect(controller.vnApp.showError).toHaveBeenCalledWith(`The message can't be empty`); - }); - }); - - describe('charactersRemaining()', () => { - it('should return the characters remaining in a element', () => { - controller.$.message = { - input: { - value: 'My message 0€' - } - }; - - let result = controller.charactersRemaining(); - - expect(result).toEqual(145); - }); - }); - }); -}); diff --git a/modules/ticket/front/sms/locale/es.yml b/modules/ticket/front/sms/locale/es.yml deleted file mode 100644 index 64c3fcca6..000000000 --- a/modules/ticket/front/sms/locale/es.yml +++ /dev/null @@ -1,9 +0,0 @@ -Send SMS: Enviar SMS -Destination: Destinatario -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 -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/style.scss b/modules/ticket/front/sms/style.scss deleted file mode 100644 index 84571a5f4..000000000 --- a/modules/ticket/front/sms/style.scss +++ /dev/null @@ -1,5 +0,0 @@ -@import "variables"; - -.SMSDialog { - min-width: 400px -} \ No newline at end of file