removed on response if just accept
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Carlos Jimenez Ruiz 2020-07-29 10:47:48 +02:00
parent e126350079
commit e2481366a2
25 changed files with 121 additions and 140 deletions

View File

@ -60,7 +60,7 @@
</vn-float-button>
<vn-confirm
vn-id="close-contract"
on-response="$ctrl.returnDialog($response)"
on-accept="$ctrl.returnDialog()"
question="Close contract"
message="Are you sure you want to close this contract?">
</vn-confirm>

View File

@ -51,13 +51,11 @@ class Controller extends Section {
this.$.closeContract.show();
}
returnDialog(response) {
if (response === 'accept') {
let params = {finished: Date.now()};
this.$http.patch(`CreditClassifications/${this.classificationId}`, params).then(() => {
this._getClassifications(this.client.id);
});
}
returnDialog() {
let params = {finished: Date.now()};
this.$http.patch(`CreditClassifications/${this.classificationId}`, params).then(() => {
this._getClassifications(this.client.id);
});
}
}

View File

@ -78,7 +78,7 @@ describe('Client', () => {
jest.spyOn(controller, '_getClassifications').mockReturnThis();
controller.classificationId = 1;
$httpBackend.expect('PATCH', `CreditClassifications/1`).respond(200);
controller.returnDialog('accept');
controller.returnDialog();
$httpBackend.flush();
expect(controller._getClassifications).toHaveBeenCalledWith(101);

View File

@ -1,6 +1,6 @@
<vn-dialog
vn-id="SMSDialog"
on-response="$ctrl.onResponse($response)">
on-accept="$ctrl.onResponse()">
<tpl-body>
<section class="SMSDialog">
<h5 class="vn-py-sm" translate>Send SMS</h5>

View File

@ -16,25 +16,23 @@ class Controller extends Section {
return maxLength - textAreaLength;
}
onResponse(response) {
if (response === 'accept') {
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`);
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!'));
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;
}
if (res.data) this.emit('send', {response: res.data});
});
} catch (e) {
this.vnApp.showError(this.$t(e.message));
return false;
}
return true;
}

View File

@ -30,7 +30,7 @@ describe('Client', () => {
jest.spyOn(controller.vnApp, 'showMessage');
$httpBackend.expect('POST', `Clients/101/sendSms`, params).respond(200, params);
controller.onResponse('accept');
controller.onResponse();
$httpBackend.flush();
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('SMS sent!');

View File

@ -34,7 +34,7 @@
<vn-dialog
vn-id="change-pass"
on-open="$ctrl.onPassOpen()"
on-response="$ctrl.onPassChange($response)">
on-accept="$ctrl.onPassChange()">
<tpl-body>
<vn-textfield
type="password"

View File

@ -38,25 +38,23 @@ export default class Controller extends Section {
this.$.$apply();
}
onPassChange(response) {
if (response == 'accept') {
try {
if (!this.newPassword)
throw new Error(`You must enter a new password`);
if (this.newPassword != this.repeatPassword)
throw new Error(`Passwords don't match`);
let account = {
password: this.newPassword
};
onPassChange() {
try {
if (!this.newPassword)
throw new Error(`You must enter a new password`);
if (this.newPassword != this.repeatPassword)
throw new Error(`Passwords don't match`);
let account = {
password: this.newPassword
};
this.$http.patch(`Accounts/${this.client.id}`, account).then(res => {
this.vnApp.showSuccess(this.$t('Data saved!'));
});
} catch (e) {
this.vnApp.showError(this.$t(e.message));
this.$http.patch(`Accounts/${this.client.id}`, account).then(res => {
this.vnApp.showSuccess(this.$t('Data saved!'));
});
} catch (e) {
this.vnApp.showError(this.$t(e.message));
return false;
}
return false;
}
return true;

View File

@ -83,7 +83,7 @@ describe('Component VnClientWebAccess', () => {
controller.repeatPassword = 'm24x8';
controller.canChangePassword = true;
$httpBackend.expectPATCH('Accounts/1234', {password: 'm24x8'}).respond('done');
controller.onPassChange('accept');
controller.onPassChange();
$httpBackend.flush();
});
@ -92,7 +92,7 @@ describe('Component VnClientWebAccess', () => {
controller.client = {id: '1234'};
controller.newPassword = '';
controller.canChangePassword = true;
controller.onPassChange('accept');
controller.onPassChange();
expect(vnApp.showError).toHaveBeenCalledWith(`You must enter a new password`);
});
@ -104,7 +104,7 @@ describe('Component VnClientWebAccess', () => {
controller.newPassword = 'm24x8';
controller.canChangePassword = true;
controller.repeatPassword = 'notMatchingPassword';
controller.onPassChange('accept');
controller.onPassChange();
expect(vnApp.showError).toHaveBeenCalledWith(`Passwords don't match`);
});

View File

@ -108,7 +108,7 @@
<vn-confirm
vn-id="confirm"
question="Delete ticket from route?"
on-response="$ctrl.removeTicketFromRoute($response)">
on-accept="$ctrl.removeTicketFromRoute()">
</vn-confirm>
<vn-crud-model
vn-id="possibleTicketsModel"
@ -118,7 +118,7 @@
</vn-crud-model>
<vn-dialog
vn-id="possibleTicketsDialog"
on-response="$ctrl.setTicketsRoute($response)"
on-accept="$ctrl.setTicketsRoute()"
message="Tickets to add">
<tpl-body>
<vn-data-viewer class="vn-pa-md" model="possibleTicketsModel">

View File

@ -101,15 +101,13 @@ class Controller extends Section {
this.$.confirm.show();
}
removeTicketFromRoute(response) {
if (response === 'accept') {
let params = {routeFk: null};
let query = `Tickets/${this.selectedTicket}/`;
this.$http.patch(query, params).then(() => {
this.vnApp.showSuccess(this.$t('Ticket removed from route'));
this.updateVolume();
});
}
removeTicketFromRoute() {
let params = {routeFk: null};
let query = `Tickets/${this.selectedTicket}/`;
this.$http.patch(query, params).then(() => {
this.vnApp.showSuccess(this.$t('Ticket removed from route'));
this.updateVolume();
});
}
updateVolume() {
@ -133,20 +131,17 @@ class Controller extends Section {
this.$.possibleTicketsDialog.show();
}
setTicketsRoute(response) {
if (response === 'accept') {
let tickets = this.getSelectedItems(this.possibleTickets);
for (let i = 0; i < tickets.length; i++) {
delete tickets[i].checked;
tickets[i].routeFk = this.route.id;
}
return this.$.possibleTicketsModel.save().then(() => {
this.$.model.data = this.$.model.data.concat(tickets);
});
setTicketsRoute() {
let tickets = this.getSelectedItems(this.possibleTickets);
if (tickets.length === 0) return;
for (let i = 0; i < tickets.length; i++) {
delete tickets[i].checked;
tickets[i].routeFk = this.route.id;
}
return Promise.resolve();
return this.$.possibleTicketsModel.save().then(() => {
this.$.model.data = this.$.model.data.concat(tickets);
});
}
onDrop($event) {

View File

@ -170,7 +170,7 @@ describe('Route', () => {
controller.selectedTicket = ticketId;
$httpBackend.expectPATCH(`Tickets/${ticketId}/`).respond('ok');
controller.removeTicketFromRoute('accept');
controller.removeTicketFromRoute();
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Ticket removed from route');
@ -250,15 +250,11 @@ describe('Route', () => {
{id: 5, routeFk: 111}
];
controller.setTicketsRoute('accept').then(() => {
controller.setTicketsRoute().then(() => {
expect(controller.$.model.data).toEqual(expectedResult);
done();
}).catch(done.fail);
});
it('should just return a promise', () => {
expect(controller.setTicketsRoute('cancel')).toEqual(jasmine.any(Promise));
});
});
describe('onDrop()', () => {

View File

@ -384,14 +384,14 @@
vn-id="delete-lines"
question="You are going to delete lines of the ticket"
message="Continue anyway?"
on-response="$ctrl.removeSales()">
on-accept="$ctrl.removeSales()">
</vn-confirm>
<vn-confirm
vn-id="delete-ticket"
question="Do you want to delete it?"
message="This ticket is now empty"
on-response="$ctrl.transferSales($ctrl.transfer.ticketId, $response)">
on-accept="$ctrl.transferSales($ctrl.transfer.ticketId)">
</vn-confirm>
<vn-menu vn-id="moreOptions">

View File

@ -1,6 +1,6 @@
<vn-dialog
vn-id="SMSDialog"
on-response="$ctrl.onResponse($response)"
on-accept="$ctrl.onResponse()"
message="Send SMS">
<tpl-body>
<section class="SMSDialog">

View File

@ -16,25 +16,23 @@ class Controller extends Component {
return maxLength - textAreaLength;
}
onResponse(response) {
if (response === 'accept') {
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`);
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.$params.id}/sendSms`, this.sms).then(res => {
this.vnApp.showMessage(this.$t('SMS sent!'));
this.$http.post(`Tickets/${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;
}
if (res.data) this.emit('send', {response: res.data});
});
} catch (e) {
this.vnApp.showError(this.$t(e.message));
return false;
}
return true;
}

View File

@ -28,7 +28,7 @@ describe('Ticket', () => {
jest.spyOn(controller.vnApp, 'showMessage');
$httpBackend.expect('POST', `Tickets/11/sendSms`, params).respond(200, params);
controller.onResponse('accept');
controller.onResponse();
$httpBackend.flush();
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('SMS sent!');
@ -39,7 +39,7 @@ describe('Ticket', () => {
jest.spyOn(controller.vnApp, 'showError');
controller.onResponse('accept');
controller.onResponse();
expect(controller.vnApp.showError).toHaveBeenCalledWith(`The destination can't be empty`);
});
@ -49,7 +49,7 @@ describe('Ticket', () => {
jest.spyOn(controller.vnApp, 'showError');
controller.onResponse('accept');
controller.onResponse();
expect(controller.vnApp.showError).toHaveBeenCalledWith(`The message can't be empty`);
});

View File

@ -19,7 +19,7 @@
</form>
<vn-confirm
vn-id="deleteNode"
on-response="$ctrl.onRemoveResponse($response)"
on-accept="$ctrl.onRemoveResponse()"
question="Delete department"
message="Are you sure you want to delete it?">
</vn-confirm>
@ -27,7 +27,7 @@
<vn-dialog
vn-id="createNode"
on-open="$ctrl.onCreateDialogOpen()"
on-response="$ctrl.onCreateResponse($response)"
on-accept="$ctrl.onCreateResponse()"
message="New department">
<tpl-body>
<vn-textfield

View File

@ -38,29 +38,27 @@ class Controller extends Section {
this.newChild.name = '';
}
onCreateResponse(response) {
if (response == 'accept') {
try {
if (!this.newChild.name)
throw new Error(`Name can't be empty`);
onCreateResponse() {
try {
if (!this.newChild.name)
throw new Error(`Name can't be empty`);
const params = {name: this.newChild.name};
const parent = this.newChild.parent;
const params = {name: this.newChild.name};
const parent = this.newChild.parent;
if (parent && parent.id)
params.parentId = parent.id;
if (parent && parent.id)
params.parentId = parent.id;
const query = `departments/createChild`;
this.$http.post(query, params).then(res => {
const item = res.data;
item.parent = parent;
const query = `departments/createChild`;
this.$http.post(query, params).then(res => {
const item = res.data;
item.parent = parent;
this.$.treeview.create(item);
});
} catch (e) {
this.vnApp.showError(this.$t(e.message));
return false;
}
this.$.treeview.create(item);
});
} catch (e) {
this.vnApp.showError(this.$t(e.message));
return false;
}
return true;
}
@ -70,14 +68,12 @@ class Controller extends Section {
this.$.deleteNode.show();
}
onRemoveResponse(response) {
if (response === 'accept') {
const childId = this.removedChild.id;
const path = `departments/${childId}/removeChild`;
this.$http.post(path).then(() => {
this.$.treeview.remove(this.removedChild);
});
}
onRemoveResponse() {
const childId = this.removedChild.id;
const path = `departments/${childId}/removeChild`;
this.$http.post(path).then(() => {
this.$.treeview.remove(this.removedChild);
});
}
}

View File

@ -1,3 +1,4 @@
New department: Nuevo departamento
Delete department: Eliminar departamento
Are you sure you want to delete it?: ¿Seguro que quieres eliminarlo?
Name can't be empty: El nombre esta vacio

View File

@ -92,7 +92,7 @@
</vn-side-menu>
<vn-dialog
vn-id="addTimeDialog"
on-response="$ctrl.addTime($response)"
on-accept="$ctrl.addTime()"
message="Add time">
<tpl-body>
<vn-input-time

View File

@ -233,8 +233,7 @@ class Controller extends Section {
this.$.addTimeDialog.show();
}
addTime(response) {
if (response !== 'accept') return;
addTime() {
let data = {
workerFk: this.$params.id,
timed: this.newTime

View File

@ -10,6 +10,10 @@
"id": {
"id": true,
"type": "Number"
},
"warehouseFk": {
"type": "Number",
"required": true
}
},
"relations": {

View File

@ -28,7 +28,7 @@
</vn-float-button>
<vn-dialog
vn-id="dialog"
on-response="$ctrl.onSave($response)">
on-accept="$ctrl.onSave()">
<tpl-body>
<vn-autocomplete
ng-model="$ctrl.selected.warehouseFk"

View File

@ -21,9 +21,7 @@ class Controller extends Section {
this.$.dialog.show();
}
onSave(response) {
if (response != 'accept') return;
onSave() {
this.$http.post(this.path, this.selected)
.then(() => {
this.selected = null;

View File

@ -36,7 +36,7 @@ describe('Zone warehouses', () => {
jest.spyOn(controller, 'refresh').mockReturnThis();
$httpBackend.expect('POST', `Zones/1/warehouses`).respond(200);
controller.onSave('accept');
controller.onSave();
$httpBackend.flush();
expect(controller.selected).toBeNull();