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}}) +