From 7b57d79f50157c02f95db8adb067311cc4dacf15 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 21 Feb 2020 12:39:41 +0100 Subject: [PATCH] Create client geo auto fill --- back/models/province.json | 89 +++++++++++---------- front/core/components/datalist/index.js | 9 ++- modules/client/front/create/index.html | 67 ++++++---------- modules/client/front/create/index.js | 66 +++++++++++---- modules/client/front/fiscal-data/index.html | 55 ++++++------- modules/client/front/fiscal-data/index.js | 58 ++++++++++++++ 6 files changed, 213 insertions(+), 131 deletions(-) diff --git a/back/models/province.json b/back/models/province.json index 49a971b65..2e2ace5ed 100644 --- a/back/models/province.json +++ b/back/models/province.json @@ -1,46 +1,53 @@ { - "name": "Province", - "description": "Provinces of every country", - "base": "VnModel", - "options": { - "mysql": { - "table": "province" - } - }, - "properties": { - "id": { - "type": "Number", - "id": true, - "description": "Identifier" + "name": "Province", + "description": "Provinces of every country", + "base": "VnModel", + "options": { + "mysql": { + "table": "province" + } }, - "name": { - "type": "string", - "required": true - } - }, - "relations": { - "country": { - "type": "belongsTo", - "model": "Country", - "foreignKey": "countryFk" + "properties": { + "id": { + "type": "Number", + "id": true, + "description": "Identifier" + }, + "name": { + "type": "string", + "required": true + } }, - "warehouse": { - "type": "belongsTo", - "model": "Warehouse", - "foreignKey": "warehouseFk" + "relations": { + "country": { + "type": "belongsTo", + "model": "Country", + "foreignKey": "countryFk" + }, + "warehouse": { + "type": "belongsTo", + "model": "Warehouse", + "foreignKey": "warehouseFk" + }, + "zone": { + "type": "belongsTo", + "model": "Zone", + "foreignKey": "zoneFk" + } }, - "zone": { - "type": "belongsTo", - "model": "Zone", - "foreignKey": "zoneFk" - } - }, - "acls": [ - { - "accessType": "READ", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "ALLOW" - } - ] + "scopes": { + "location": { + "include": { + "relation": "country" + } + } + }, + "acls": [ + { + "accessType": "READ", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + } + ] } \ No newline at end of file diff --git a/front/core/components/datalist/index.js b/front/core/components/datalist/index.js index bf3cab9a1..adf33b50a 100644 --- a/front/core/components/datalist/index.js +++ b/front/core/components/datalist/index.js @@ -52,7 +52,14 @@ export default class Datalist extends Textfield { validSelection(selection) { return this.modelData && this.modelData.find(item => { - return item[this.valueField] == selection; + let dataValue = item[this.valueField]; + if (typeof(dataValue) === 'string') + dataValue = dataValue.toLowerCase(); + + if (typeof(selection) === 'string') + selection = selection.toLowerCase(); + + return dataValue == selection; }); } diff --git a/modules/client/front/create/index.html b/modules/client/front/create/index.html index ce4b7d4ed..23676a36f 100644 --- a/modules/client/front/create/index.html +++ b/modules/client/front/create/index.html @@ -49,76 +49,57 @@ - - + rule> + {{name}} ({{country.country}}) - - - - + + {{name}}, {{province.name}} + ({{province.country.country}}) + + + - - + this.$state.go('client.card.basicData', {id: json.data.id}) + ); + } + + get province() { + return this._province; + } + + // Province auto complete + set province(selection) { + this._province = selection; + + if (!selection) return; + + const country = selection.country; + + this.client.countryFk = country.id; + } + + get town() { + return this._town; + } + + // Town auto complete + set town(selection) { + this._town = selection; + + if (!selection) return; + + const province = selection.province; + const country = province.country; + const postcodes = selection.postcodes; + + this.client.provinceFk = province.id; + this.client.countryFk = country.id; + + if (postcodes.length === 1) + this.client.postcode = postcodes[0].code; + } + + get postcode() { + return this._postcode; + } + + // Postcode auto complete + set postcode(selection) { + this._postcode = selection; if (!selection) return; @@ -29,17 +76,8 @@ export default class Controller { this.client.provinceFk = province.id; this.client.countryFk = country.id; } - - onResponse(response) { - this.client.postcode = response.code; - } - - onSubmit() { - return this.$.watcher.submit().then( - json => this.$state.go('client.card.basicData', {id: json.data.id}) - ); - } } + Controller.$inject = ['$scope', '$state', '$http', '$translate', 'vnApp']; ngModule.component('vnClientCreate', { diff --git a/modules/client/front/fiscal-data/index.html b/modules/client/front/fiscal-data/index.html index 3bbc48630..98d0e9318 100644 --- a/modules/client/front/fiscal-data/index.html +++ b/modules/client/front/fiscal-data/index.html @@ -33,9 +33,7 @@ - - + {{name}} ({{country.country}}) - - - - - + show-field="code" + rule> + {{code}} - {{town.name}} ({{town.province.name}}, {{town.province.country.country}}) +