refs #4791 @2h
This commit is contained in:
parent
65fd5e2c8f
commit
4e97d931f7
|
@ -53,3 +53,4 @@ import './datalist';
|
|||
import './contextmenu';
|
||||
import './rating';
|
||||
import './smart-table';
|
||||
import './sendSms';
|
||||
|
|
|
@ -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: '<',
|
||||
}
|
||||
});
|
|
@ -113,10 +113,10 @@
|
|||
</div>
|
||||
</slot-body>
|
||||
</vn-descriptor-content>
|
||||
<vn-client-sms
|
||||
vn-id="sms"
|
||||
sms="$ctrl.newSMS">
|
||||
</vn-client-sms>
|
||||
<vn-sms-dialog
|
||||
vn-id="sms"
|
||||
sms="$ctrl.newSMS">
|
||||
</vn-sms-dialog>
|
||||
<vn-worker-descriptor-popover
|
||||
vn-id="workerDescriptor">
|
||||
</vn-worker-descriptor-popover>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,10 @@
|
|||
</vn-dialog>
|
||||
|
||||
<!-- Send SMS popup -->
|
||||
<vn-ticket-sms
|
||||
<vn-sms-dialog
|
||||
vn-id="sms"
|
||||
sms="$ctrl.newSMS">
|
||||
</vn-ticket-sms>
|
||||
</vn-sms-dialog>
|
||||
|
||||
<!-- Make invoice confirmation dialog -->
|
||||
<vn-confirm
|
||||
|
|
|
@ -225,6 +225,7 @@ class Controller extends Section {
|
|||
}
|
||||
|
||||
showSMSDialog(params) {
|
||||
const route = `Tickets/${this.id}/sendSms`;
|
||||
const address = this.ticket.address;
|
||||
const client = this.ticket.client;
|
||||
const phone = this.$params.phone
|
||||
|
@ -238,7 +239,7 @@ class Controller extends Section {
|
|||
destinationFk: this.ticket.clientFk,
|
||||
destination: phone
|
||||
}, params);
|
||||
this.$.sms.open();
|
||||
this.$.sms.open(route);
|
||||
}
|
||||
|
||||
makeInvoice() {
|
||||
|
|
|
@ -32,5 +32,4 @@ import './weekly';
|
|||
import './dms/index';
|
||||
import './dms/create';
|
||||
import './dms/edit';
|
||||
import './sms';
|
||||
import './boxing';
|
||||
|
|
|
@ -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,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: '<',
|
||||
}
|
||||
});
|
|
@ -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