4791-refactor-sendsms #1160
|
@ -19,3 +19,4 @@ import './user-popover';
|
|||
import './upload-photo';
|
||||
import './bank-entity';
|
||||
import './log';
|
||||
import './sendSms';
|
||||
|
|
|
@ -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: '&',
|
||||
}
|
||||
});
|
|
@ -113,10 +113,11 @@
|
|||
</div>
|
||||
</slot-body>
|
||||
</vn-descriptor-content>
|
||||
<vn-client-sms
|
||||
<vn-sms-dialog
|
||||
vn-id="sms"
|
||||
pau marked this conversation as resolved
Outdated
|
||||
on-send="$ctrl.onSmsSend($sms)"
|
||||
sms="$ctrl.newSMS">
|
||||
</vn-client-sms>
|
||||
</vn-sms-dialog>
|
||||
<vn-worker-descriptor-popover
|
||||
vn-id="workerDescriptor">
|
||||
</vn-worker-descriptor-popover>
|
||||
|
|
|
@ -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', {
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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: '<',
|
||||
}
|
||||
});
|
|
@ -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('<vn-dialog></vn-dialog>');
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -280,10 +280,11 @@
|
|||
</vn-dialog>
|
||||
|
||||
<!-- Send SMS popup -->
|
||||
<vn-ticket-sms
|
||||
<vn-sms-dialog
|
||||
vn-id="sms"
|
||||
on-send="$ctrl.onSmsSend($sms)"
|
||||
sms="$ctrl.newSMS">
|
||||
</vn-ticket-sms>
|
||||
</vn-sms-dialog>
|
||||
|
||||
<!-- Make invoice confirmation dialog -->
|
||||
<vn-confirm
|
||||
|
|
|
@ -239,6 +239,7 @@ class Controller extends Section {
|
|||
destinationFk: this.ticket.clientFk,
|
||||
destination: phone
|
||||
}, params);
|
||||
|
||||
this.$.sms.open();
|
||||
}
|
||||
|
||||
|
@ -294,6 +295,11 @@ class Controller extends Section {
|
|||
this.$state.go('ticket.card.sale', {id: refundTicket.id});
|
||||
});
|
||||
}
|
||||
|
||||
onSmsSend(sms) {
|
||||
return this.$http.post(`Tickets/${this.id}/sendSms`, sms)
|
||||
.then(() => this.vnApp.showSuccess(this.$t('SMS sent')));
|
||||
}
|
||||
}
|
||||
|
||||
Controller.$inject = ['$element', '$scope', 'vnReport', 'vnEmail'];
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
<vn-dialog
|
||||
vn-id="SMSDialog"
|
||||
on-accept="$ctrl.onResponse()"
|
||||
message="Send SMS">
|
||||
<tpl-body>
|
||||
<section class="SMSDialog">
|
||||
<vn-horizontal>
|
||||
<vn-textfield
|
||||
vn-one
|
||||
label="Destination"
|
||||
ng-model="$ctrl.sms.destination"
|
||||
required="true"
|
||||
rule>
|
||||
</vn-textfield>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal >
|
||||
<vn-textarea vn-one
|
||||
vn-id="message"
|
||||
label="Message"
|
||||
ng-model="$ctrl.sms.message"
|
||||
info="Special characters like accents counts as a multiple"
|
||||
rows="5"
|
||||
required="true"
|
||||
rule>
|
||||
</vn-textarea>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal>
|
||||
<span>
|
||||
{{'Characters remaining' | translate}}:
|
||||
<vn-chip translate-attr="{title: 'Packing'}" ng-class="{
|
||||
'colored': $ctrl.charactersRemaining() > 25,
|
||||
'warning': $ctrl.charactersRemaining() <= 25,
|
||||
'alert': $ctrl.charactersRemaining() < 0,
|
||||
}">
|
||||
{{$ctrl.charactersRemaining()}}
|
||||
</vn-chip>
|
||||
</span>
|
||||
</vn-horizontal>
|
||||
</section>
|
||||
</tpl-body>
|
||||
<tpl-buttons>
|
||||
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
|
||||
<button response="accept" translate>Send</button>
|
||||
</tpl-buttons>
|
||||
</vn-dialog>
|
|
@ -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('<vn-dialog></vn-dialog>');
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -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
|
|
@ -1,5 +0,0 @@
|
|||
@import "variables";
|
||||
|
||||
.SMSDialog {
|
||||
min-width: 400px
|
||||
}
|
Loading…
Reference in New Issue
Falta tabulación.