2509 - Added forms to create new locations
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
e48effca08
commit
6fa8aae161
|
@ -0,0 +1,3 @@
|
|||
UPDATE `salix`.`ACL` SET `principalId` = 'deliveryBoss' WHERE (`id` = '194');
|
||||
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('Town', '*', 'WRITE', 'ALLOW', 'ROLE', 'deliveryBoss');
|
||||
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('Province', '*', 'WRITE', 'ALLOW', 'ROLE', 'deliveryBoss');
|
|
@ -153,9 +153,9 @@
|
|||
</form>
|
||||
|
||||
<!-- New postcode dialog -->
|
||||
<vn-client-postcode vn-id="postcode"
|
||||
<vn-geo-postcode vn-id="postcode"
|
||||
on-response="$ctrl.onResponse($response)">
|
||||
</vn-client-postcode>
|
||||
</vn-geo-postcode>
|
||||
|
||||
<!-- Create custom agent dialog -->
|
||||
<vn-dialog class="edit"
|
||||
|
|
|
@ -191,9 +191,9 @@
|
|||
</form>
|
||||
|
||||
<!-- New postcode dialog -->
|
||||
<vn-client-postcode vn-id="postcode"
|
||||
<vn-geo-postcode vn-id="postcode"
|
||||
on-response="$ctrl.onResponse($response)">
|
||||
</vn-client-postcode>
|
||||
</vn-geo-postcode>
|
||||
|
||||
<!-- Create custom agent dialog -->
|
||||
<vn-dialog class="edit"
|
||||
|
|
|
@ -136,7 +136,7 @@
|
|||
</vn-button-bar>
|
||||
</form>
|
||||
<!-- New postcode dialog -->
|
||||
<vn-client-postcode
|
||||
<vn-geo-postcode
|
||||
vn-id="postcode"
|
||||
on-response="$ctrl.onResponse($response)">
|
||||
</vn-client-postcode>
|
||||
</vn-geo-postcode>
|
|
@ -173,7 +173,7 @@
|
|||
on-accept="$ctrl.onAcceptDuplication()">
|
||||
</vn-confirm>
|
||||
<!-- New postcode dialog -->
|
||||
<vn-client-postcode
|
||||
<vn-geo-postcode
|
||||
vn-id="postcode"
|
||||
on-response="$ctrl.onResponse($response)">
|
||||
</vn-client-postcode>
|
||||
</vn-geo-postcode>
|
|
@ -159,6 +159,9 @@ export default class Controller extends Section {
|
|||
|
||||
onResponse(response) {
|
||||
this.client.postcode = response.code;
|
||||
this.client.city = response.city;
|
||||
this.client.provinceFk = response.provinceFk;
|
||||
this.client.countryFk = response.countryFk;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,8 @@ import './web-payment';
|
|||
import './log';
|
||||
import './sms';
|
||||
import './postcode';
|
||||
import './postcode/province';
|
||||
import './postcode/city';
|
||||
import './dms/index';
|
||||
import './dms/create';
|
||||
import './dms/edit';
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
<vn-dialog class="edit"
|
||||
vn-id="cityDialog"
|
||||
on-open="$ctrl.onOpen()"
|
||||
on-accept="$ctrl.onAccept()"
|
||||
message="New city">
|
||||
<tpl-body>
|
||||
<p translate>Please, ensure you put the correct data!</p>
|
||||
<vn-horizontal>
|
||||
<vn-textfield vn-one
|
||||
vn-focus
|
||||
ng-model="$ctrl.city.name"
|
||||
label="Name">
|
||||
</vn-textfield>
|
||||
<vn-autocomplete vn-one
|
||||
ng-model="$ctrl.city.provinceFk"
|
||||
url="Provinces"
|
||||
show-field="name"
|
||||
value-field="id"
|
||||
label="Province">
|
||||
</vn-autocomplete>
|
||||
</vn-horizontal>
|
||||
</tpl-body>
|
||||
<tpl-buttons>
|
||||
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
|
||||
<button response="accept" translate>Save</button>
|
||||
</tpl-buttons>
|
||||
</vn-dialog>
|
|
@ -0,0 +1,37 @@
|
|||
import ngModule from '../../module';
|
||||
import Component from 'core/lib/component';
|
||||
|
||||
class Controller extends Component { // Comprobar funcionamiento añadir ciudad
|
||||
open($event) {
|
||||
if ($event.defaultPrevented) return;
|
||||
|
||||
this.$.cityDialog.show();
|
||||
$event.preventDefault();
|
||||
}
|
||||
|
||||
onAccept() {
|
||||
try {
|
||||
if (!this.city.name)
|
||||
throw new Error(`The city name can't be empty`);
|
||||
if (!this.city.provinceFk)
|
||||
throw new Error(`The province can't be empty`);
|
||||
|
||||
this.$http.patch(`towns`, this.city).then(res => {
|
||||
this.vnApp.showMessage(this.$t('The city has been created'));
|
||||
this.emit('response', {$response: res.data});
|
||||
});
|
||||
} catch (e) {
|
||||
this.vnApp.showError(this.$t(e.message));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
ngModule.vnComponent('vnGeoCity', {
|
||||
template: require('./index.html'),
|
||||
controller: Controller,
|
||||
bindings: {
|
||||
data: '<',
|
||||
}
|
||||
});
|
|
@ -0,0 +1,34 @@
|
|||
import './index';
|
||||
|
||||
describe('Client', () => {
|
||||
describe('Component vnGeoCity', () => {
|
||||
let controller;
|
||||
let $httpBackend;
|
||||
let $scope;
|
||||
|
||||
beforeEach(ngModule('client'));
|
||||
|
||||
beforeEach(inject(($componentController, _$httpBackend_, $rootScope) => {
|
||||
$httpBackend = _$httpBackend_;
|
||||
$scope = $rootScope.$new();
|
||||
const $element = angular.element('<vn-dialog></vn-dialog>');
|
||||
controller = $componentController('vnGeoCity', {$element, $scope});
|
||||
controller.client = {id: 101};
|
||||
}));
|
||||
|
||||
describe('onAccept()', () => {
|
||||
it('should perform a POST query and show a success snackbar', () => {
|
||||
let params = {name: 'Gotham City', provinceFk: 1};
|
||||
controller.city = {name: 'Gotham City', provinceFk: 1};
|
||||
|
||||
jest.spyOn(controller.vnApp, 'showMessage');
|
||||
$httpBackend.expect('PATCH', `towns`, params).respond(200, params);
|
||||
|
||||
controller.onAccept();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The city has been created');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -11,7 +11,7 @@
|
|||
vn-focus
|
||||
vn-id="postcode"
|
||||
label="Postcode"
|
||||
ng-model="$ctrl.data.code"
|
||||
ng-model="$ctrl.location.code"
|
||||
required="true">
|
||||
</vn-textfield>
|
||||
<vn-autocomplete vn-one
|
||||
|
@ -19,23 +19,39 @@
|
|||
url="Towns/location"
|
||||
show-field="name"
|
||||
value-field="id"
|
||||
ng-model="$ctrl.data.townFk"
|
||||
ng-model="$ctrl.location.townFk"
|
||||
selection="$ctrl.townSelection"
|
||||
required="true">
|
||||
<append>
|
||||
<vn-icon-button
|
||||
icon="add_circle"
|
||||
vn-tooltip="New city"
|
||||
ng-click="city.open($event)"
|
||||
vn-acl="deliveryBoss"
|
||||
vn-acl-action="remove">
|
||||
</vn-icon-button>
|
||||
</append>
|
||||
</vn-autocomplete>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal>
|
||||
<vn-autocomplete vn-one
|
||||
disabled="true"
|
||||
ng-model="$ctrl.data.provinceFk"
|
||||
ng-model="$ctrl.location.provinceFk"
|
||||
url="Provinces"
|
||||
show-field="name"
|
||||
value-field="id"
|
||||
label="Province">
|
||||
<append>
|
||||
<vn-icon-button
|
||||
icon="add_circle"
|
||||
vn-tooltip="New province"
|
||||
ng-click="province.open($event)"
|
||||
vn-acl="deliveryBoss"
|
||||
vn-acl-action="remove">
|
||||
</vn-icon-button>
|
||||
</append>
|
||||
</vn-autocomplete>
|
||||
<vn-autocomplete vn-one
|
||||
disabled="true"
|
||||
ng-model="$ctrl.data.countryFk"
|
||||
ng-model="$ctrl.location.countryFk"
|
||||
url="Countries"
|
||||
show-field="country"
|
||||
value-field="id"
|
||||
|
@ -47,4 +63,14 @@
|
|||
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
|
||||
<button response="accept" translate>Save</button>
|
||||
</tpl-buttons>
|
||||
</vn-dialog>
|
||||
</vn-dialog>
|
||||
<!-- New province dialog -->
|
||||
<vn-geo-province
|
||||
vn-id="province"
|
||||
on-response="$ctrl.onProvinceResponse($response)">
|
||||
</vn-geo-province>
|
||||
<!-- New city dialog -->
|
||||
<vn-geo-city
|
||||
vn-id="city"
|
||||
on-response="$ctrl.onCityResponse($response)">
|
||||
</vn-geo-city>
|
|
@ -15,8 +15,9 @@ class Controller extends Component {
|
|||
const province = selection.province;
|
||||
const country = province.country;
|
||||
|
||||
this.data.provinceFk = province.id;
|
||||
this.data.countryFk = country.id;
|
||||
this.location.city = selection.name;
|
||||
this.location.provinceFk = province.id;
|
||||
this.location.countryFk = country.id;
|
||||
}
|
||||
|
||||
open() {
|
||||
|
@ -24,19 +25,35 @@ class Controller extends Component {
|
|||
}
|
||||
|
||||
onOpen() {
|
||||
this.location = {};
|
||||
this.$.postcode.focus();
|
||||
}
|
||||
|
||||
onProvinceResponse(response) {
|
||||
this.location.provinceFk = response.id;
|
||||
this.location.countryFk = response.countryFk;
|
||||
}
|
||||
|
||||
onCityResponse(response) {
|
||||
this.location.townFk = response.id;
|
||||
this.location.provinceFk = response.provinceFk;
|
||||
this.location.countryFk = response.countryFk;
|
||||
}
|
||||
|
||||
onAccept() {
|
||||
try {
|
||||
if (!this.data.code)
|
||||
if (!this.location.code)
|
||||
throw new Error(`The postcode can't be empty`);
|
||||
if (!this.data.townFk)
|
||||
if (!this.location.townFk)
|
||||
throw new Error(`The town can't be empty`);
|
||||
if (!this.location.provinceFk)
|
||||
throw new Error(`The province can't be empty`);
|
||||
if (!this.location.provinceFk)
|
||||
throw new Error(`The country can't be empty`);
|
||||
|
||||
this.$http.patch(`postcodes`, this.data).then(res => {
|
||||
this.vnApp.showMessage(this.$t('The postcode has been saved'));
|
||||
this.emit('response', {$response: res.data});
|
||||
this.$http.patch(`postcodes`, this.location).then(() => {
|
||||
this.vnApp.showMessage(this.$t('The postcode has been created. You can save the data now'));
|
||||
this.emit('response', {$response: this.location});
|
||||
});
|
||||
} catch (e) {
|
||||
this.vnApp.showError(this.$t(e.message));
|
||||
|
@ -46,7 +63,7 @@ class Controller extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
ngModule.vnComponent('vnClientPostcode', {
|
||||
ngModule.vnComponent('vnGeoPostcode', {
|
||||
template: require('./index.html'),
|
||||
controller: Controller,
|
||||
bindings: {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import './index';
|
||||
|
||||
describe('Client', () => {
|
||||
describe('Component vnClientPostcode', () => {
|
||||
describe('Component vnGeoPostcode', () => {
|
||||
let controller;
|
||||
let $httpBackend;
|
||||
let $scope;
|
||||
|
@ -12,14 +12,14 @@ describe('Client', () => {
|
|||
$httpBackend = _$httpBackend_;
|
||||
$scope = $rootScope.$new();
|
||||
const $element = angular.element('<vn-dialog></vn-dialog>');
|
||||
controller = $componentController('vnClientPostcode', {$element, $scope});
|
||||
controller = $componentController('vnGeoPostcode', {$element, $scope});
|
||||
controller.client = {id: 101};
|
||||
}));
|
||||
|
||||
describe('onAccept()', () => {
|
||||
it('should perform a POST query and show a success snackbar', () => {
|
||||
let params = {townFk: 1, provinceFk: 1, countryFk: 1, code: '46460'};
|
||||
controller.data = {townFk: 1, provinceFk: 1, countryFk: 1, code: '46460'};
|
||||
controller.location = {townFk: 1, provinceFk: 1, countryFk: 1, code: '46460'};
|
||||
|
||||
jest.spyOn(controller.vnApp, 'showMessage');
|
||||
$httpBackend.expect('PATCH', `postcodes`, params).respond(200, params);
|
||||
|
@ -27,7 +27,7 @@ describe('Client', () => {
|
|||
controller.onAccept();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The postcode has been saved');
|
||||
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The postcode has been created. You can save the data now');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
New postcode: Nuevo código postal
|
||||
New city: Nueva ciudad
|
||||
New province: Nueva provincia
|
||||
Please, ensure you put the correct data!: ¡Por favor, asegúrate de poner los datos correctos!
|
||||
The postcode can't be empty: El código postal no puede quedar vacío
|
||||
The town can't be empty: La población no puede quedar vacía
|
||||
The postcode has been saved: El código postal ha sido guardado
|
||||
The province can't be empty: La provincia no puede quedar vacía
|
||||
The country can't be empty: El país no puede quedar vacío
|
||||
The postcode has been created. You can save the data now: Se ha creado el código postal. Ahora puedes guardar los datos
|
||||
The city has been created: Se ha creado la ciudad
|
||||
The province has been created: Se ha creado la provincia
|
|
@ -0,0 +1,27 @@
|
|||
<vn-dialog class="edit"
|
||||
vn-id="provinceDialog"
|
||||
on-open="$ctrl.onOpen()"
|
||||
on-accept="$ctrl.onAccept()"
|
||||
message="New province">
|
||||
<tpl-body>
|
||||
<p translate>Please, ensure you put the correct data!</p>
|
||||
<vn-horizontal>
|
||||
<vn-textfield vn-one
|
||||
vn-focus
|
||||
ng-model="$ctrl.province.name"
|
||||
label="Name">
|
||||
</vn-textfield>
|
||||
<vn-autocomplete vn-one
|
||||
ng-model="$ctrl.province.countryFk"
|
||||
url="Countries"
|
||||
show-field="country"
|
||||
value-field="id"
|
||||
label="Country">
|
||||
</vn-autocomplete>
|
||||
</vn-horizontal>
|
||||
</tpl-body>
|
||||
<tpl-buttons>
|
||||
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
|
||||
<button response="accept" translate>Save</button>
|
||||
</tpl-buttons>
|
||||
</vn-dialog>
|
|
@ -0,0 +1,37 @@
|
|||
import ngModule from '../../module';
|
||||
import Component from 'core/lib/component';
|
||||
|
||||
class Controller extends Component {
|
||||
open($event) {
|
||||
if ($event.defaultPrevented) return;
|
||||
|
||||
this.$.provinceDialog.show();
|
||||
$event.preventDefault();
|
||||
}
|
||||
|
||||
onAccept() {
|
||||
try {
|
||||
if (!this.province.name)
|
||||
throw new Error(`The province name can't be empty`);
|
||||
if (!this.province.countryFk)
|
||||
throw new Error(`The country can't be empty`);
|
||||
|
||||
this.$http.patch(`provinces`, this.province).then(res => {
|
||||
this.vnApp.showMessage(this.$t('The province has been created'));
|
||||
this.emit('response', {$response: res.data});
|
||||
});
|
||||
} catch (e) {
|
||||
this.vnApp.showError(this.$t(e.message));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
ngModule.vnComponent('vnGeoProvince', {
|
||||
template: require('./index.html'),
|
||||
controller: Controller,
|
||||
bindings: {
|
||||
data: '<',
|
||||
}
|
||||
});
|
|
@ -0,0 +1,34 @@
|
|||
import './index';
|
||||
|
||||
describe('Client', () => {
|
||||
describe('Component vnGeoProvince', () => {
|
||||
let controller;
|
||||
let $httpBackend;
|
||||
let $scope;
|
||||
|
||||
beforeEach(ngModule('client'));
|
||||
|
||||
beforeEach(inject(($componentController, _$httpBackend_, $rootScope) => {
|
||||
$httpBackend = _$httpBackend_;
|
||||
$scope = $rootScope.$new();
|
||||
const $element = angular.element('<vn-dialog></vn-dialog>');
|
||||
controller = $componentController('vnGeoProvince', {$element, $scope});
|
||||
controller.client = {id: 101};
|
||||
}));
|
||||
|
||||
describe('onAccept()', () => {
|
||||
it('should perform a POST query and show a success snackbar', () => {
|
||||
let params = {name: 'New Jersey', countryFk: 1};
|
||||
controller.province = {name: 'New Jersey', countryFk: 1};
|
||||
|
||||
jest.spyOn(controller.vnApp, 'showMessage');
|
||||
$httpBackend.expect('PATCH', `provinces`, params).respond(200, params);
|
||||
|
||||
controller.onAccept();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The province has been created');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,6 +1,6 @@
|
|||
@import "variables";
|
||||
|
||||
vn-client-postcode {
|
||||
vn-geo-postcode {
|
||||
vn-dialog {
|
||||
p {
|
||||
color: $color-alert
|
||||
|
|
Loading…
Reference in New Issue