diff --git a/front/salix/components/index.js b/front/salix/components/index.js
index dbe9fe81a..3bd24d32f 100644
--- a/front/salix/components/index.js
+++ b/front/salix/components/index.js
@@ -19,3 +19,4 @@ import './user-popover';
import './upload-photo';
import './bank-entity';
import './log';
+import './sendSms';
diff --git a/modules/client/front/sms/index.html b/front/salix/components/sendSms/index.html
similarity index 100%
rename from modules/client/front/sms/index.html
rename to front/salix/components/sendSms/index.html
diff --git a/modules/ticket/front/sms/index.js b/front/salix/components/sendSms/index.js
similarity index 52%
rename from modules/ticket/front/sms/index.js
rename to front/salix/components/sendSms/index.js
index 6bc252dc1..0947550b0 100644
--- a/modules/ticket/front/sms/index.js
+++ b/front/salix/components/sendSms/index.js
@@ -1,19 +1,26 @@
-import ngModule from '../module';
-import Component from 'core/lib/component';
+import ngModule from '../../module';
import './style.scss';
+import Dialog from '../../../core/components/dialog';
+
+export default class sendSmsDialog extends Dialog {
+ constructor($element, $scope, $http, $translate, vnApp) {
+ super($element, $scope, $http, $translate, vnApp);
+
+ new CustomEvent('openSmsDialog', {
+ detail: {
+ this: this
+ }
+ });
+ }
-class Controller extends Component {
open() {
this.$.SMSDialog.show();
}
charactersRemaining() {
- const element = this.$.message;
- const value = element.input.value;
-
+ const element = this.sms.message;
const maxLength = 160;
- const textAreaLength = new Blob([value]).size;
- return maxLength - textAreaLength;
+ return maxLength - element.length;
}
onResponse() {
@@ -25,23 +32,19 @@ class Controller extends Component {
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});
- });
+ return this.onSend({$sms: this.sms});
} catch (e) {
this.vnApp.showError(this.$t(e.message));
return false;
}
- return true;
}
}
-ngModule.vnComponent('vnTicketSms', {
+ngModule.vnComponent('vnSmsDialog', {
template: require('./index.html'),
- controller: Controller,
+ controller: sendSmsDialog,
bindings: {
sms: '<',
+ onSend: '&',
}
});
diff --git a/modules/client/front/sms/locale/es.yml b/front/salix/components/sendSms/locale/es.yml
similarity index 100%
rename from modules/client/front/sms/locale/es.yml
rename to front/salix/components/sendSms/locale/es.yml
diff --git a/modules/client/front/sms/style.scss b/front/salix/components/sendSms/style.scss
similarity index 100%
rename from modules/client/front/sms/style.scss
rename to front/salix/components/sendSms/style.scss
diff --git a/modules/client/front/descriptor/index.html b/modules/client/front/descriptor/index.html
index cad226416..ef5c2997f 100644
--- a/modules/client/front/descriptor/index.html
+++ b/modules/client/front/descriptor/index.html
@@ -113,10 +113,11 @@
-
-
+
diff --git a/modules/client/front/descriptor/index.js b/modules/client/front/descriptor/index.js
index 4a0d1cd2a..4d8d70edf 100644
--- a/modules/client/front/descriptor/index.js
+++ b/modules/client/front/descriptor/index.js
@@ -39,6 +39,11 @@ class Controller extends Descriptor {
};
this.$.sms.open();
}
+
+ onSmsSend(sms) {
+ return this.$http.post(`Clients/${this.id}/sendSms`, sms)
+ .then(() => this.vnApp.showSuccess(this.$t('SMS sent')));
+ }
}
ngModule.vnComponent('vnClientDescriptor', {
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..1f0ae8362 100644
--- a/modules/ticket/front/descriptor-menu/index.html
+++ b/modules/ticket/front/descriptor-menu/index.html
@@ -280,10 +280,11 @@
-
-
+
this.vnApp.showSuccess(this.$t('SMS sent')));
+ }
}
Controller.$inject = ['$element', '$scope', 'vnReport', 'vnEmail'];
diff --git a/modules/ticket/front/descriptor-menu/index.spec.js b/modules/ticket/front/descriptor-menu/index.spec.js
index 1716e36f6..f3d8ea3b3 100644
--- a/modules/ticket/front/descriptor-menu/index.spec.js
+++ b/modules/ticket/front/descriptor-menu/index.spec.js
@@ -261,11 +261,8 @@ describe('Ticket Component vnTicketDescriptorMenu', () => {
describe('showSMSDialog()', () => {
it('should set the destionationFk and destination properties and then call the sms open() method', () => {
controller.$.sms = {open: () => {}};
- jest.spyOn(controller.$.sms, 'open');
-
controller.showSMSDialog();
- expect(controller.$.sms.open).toHaveBeenCalledWith();
expect(controller.newSMS).toEqual({
destinationFk: ticket.clientFk,
destination: ticket.address.mobile,
diff --git a/modules/ticket/front/index.js b/modules/ticket/front/index.js
index 6106a22eb..b49c6d49b 100644
--- a/modules/ticket/front/index.js
+++ b/modules/ticket/front/index.js
@@ -32,7 +32,6 @@ import './weekly';
import './dms/index';
import './dms/create';
import './dms/edit';
-import './sms';
import './boxing';
import './future';
import './future-search-panel';
diff --git a/modules/ticket/front/sms/index.html b/modules/ticket/front/sms/index.html
deleted file mode 100644
index 97bdfef14..000000000
--- a/modules/ticket/front/sms/index.html
+++ /dev/null
@@ -1,45 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
- {{'Characters remaining' | translate}}:
-
- {{$ctrl.charactersRemaining()}}
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
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