Create client geo auto fill
gitea/salix/2034-postcode_autocomplete There was a failure building this commit Details

This commit is contained in:
Joan Sanchez 2020-02-21 12:39:41 +01:00
parent 2dbde24a99
commit 7b57d79f50
6 changed files with 213 additions and 131 deletions

View File

@ -1,46 +1,53 @@
{ {
"name": "Province", "name": "Province",
"description": "Provinces of every country", "description": "Provinces of every country",
"base": "VnModel", "base": "VnModel",
"options": { "options": {
"mysql": { "mysql": {
"table": "province" "table": "province"
} }
},
"properties": {
"id": {
"type": "Number",
"id": true,
"description": "Identifier"
}, },
"name": { "properties": {
"type": "string", "id": {
"required": true "type": "Number",
} "id": true,
}, "description": "Identifier"
"relations": { },
"country": { "name": {
"type": "belongsTo", "type": "string",
"model": "Country", "required": true
"foreignKey": "countryFk" }
}, },
"warehouse": { "relations": {
"type": "belongsTo", "country": {
"model": "Warehouse", "type": "belongsTo",
"foreignKey": "warehouseFk" "model": "Country",
"foreignKey": "countryFk"
},
"warehouse": {
"type": "belongsTo",
"model": "Warehouse",
"foreignKey": "warehouseFk"
},
"zone": {
"type": "belongsTo",
"model": "Zone",
"foreignKey": "zoneFk"
}
}, },
"zone": { "scopes": {
"type": "belongsTo", "location": {
"model": "Zone", "include": {
"foreignKey": "zoneFk" "relation": "country"
} }
}, }
"acls": [ },
{ "acls": [
"accessType": "READ", {
"principalType": "ROLE", "accessType": "READ",
"principalId": "$everyone", "principalType": "ROLE",
"permission": "ALLOW" "principalId": "$everyone",
} "permission": "ALLOW"
] }
]
} }

View File

@ -52,7 +52,14 @@ export default class Datalist extends Textfield {
validSelection(selection) { validSelection(selection) {
return this.modelData && this.modelData.find(item => { 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;
}); });
} }

View File

@ -49,76 +49,57 @@
</vn-textfield> </vn-textfield>
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <vn-horizontal>
<vn-autocomplete <vn-autocomplete vn-id="country" vn-one
vn-id="country"
vn-one
ng-model="$ctrl.client.countryFk" ng-model="$ctrl.client.countryFk"
url="Countries" url="Countries"
show-field="country" show-field="country"
value-field="id" value-field="id"
label="Country"> label="Country">
</vn-autocomplete> </vn-autocomplete>
<vn-autocomplete <vn-autocomplete vn-id="province" vn-one
vn-id="province" label="Province"
vn-one
url="Provinces"
ng-model="$ctrl.client.provinceFk" ng-model="$ctrl.client.provinceFk"
selection="$ctrl.province"
url="Provinces/location"
fields="['id', 'name', 'countryFk']"
where="{countryFk: country.selection.id}" where="{countryFk: country.selection.id}"
show-field="name" show-field="name"
value-field="id" value-field="id"
label="Province"> rule>
<tpl-item>{{name}} ({{country.country}})</tpl-item>
</vn-autocomplete> </vn-autocomplete>
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <vn-horizontal>
<vn-textfield <vn-datalist vn-id="town" vn-one
vn-one
label="City" label="City"
ng-model="$ctrl.client.city" ng-model="$ctrl.client.city"
rule> selection="$ctrl.town"
</vn-textfield> url="Towns/location"
<!-- fields="['id', 'name', 'provinceFk']"
<vn-autocomplete vn-id="town" vn-one
label="City"
url="Towns"
fields="['id', 'name']"
where="{provinceFk: province.selection.id}" where="{provinceFk: province.selection.id}"
show-field="name" show-field="name"
value-field="name" value-field="name">
ng-model="$ctrl.client.city"> <tpl-item>
</vn-autocomplete> {{name}}, {{province.name}}
<vn-icon-button ({{province.country.country}})
vn-auto </tpl-item>
class="vn-my-md" </vn-datalist>
icon="add_circle" <vn-datalist vn-one
vn-tooltip="New postcode"
ng-click="postcode.open()">
</vn-icon-button>
-->
<vn-textfield
vn-one
label="Postcode" label="Postcode"
ng-model="$ctrl.client.postcode" ng-model="$ctrl.client.postcode"
rule> selection="$ctrl.postcode"
</vn-textfield>
<!--
<vn-autocomplete
vn-one
url="Postcodes/location" url="Postcodes/location"
fields="['code', 'townFk']" fields="['code','townFk']"
ng-model="$ctrl.client.postcode"
selection="$ctrl.postcodeSelection"
search-function="{code: $search}"
where="{townFk: town.selection.id}" where="{townFk: town.selection.id}"
order="code, townFk" order="code, townFk"
show-field="code"
value-field="code" value-field="code"
label="Postcode"> show-field="code"
rule>
<tpl-item> <tpl-item>
{{code}}, {{town.name}} - {{town.province.name}} {{code}}, {{town.name}} - {{town.province.name}}
({{town.province.country.country}}) ({{town.province.country.country}})
</tpl-item> </tpl-item>
</vn-autocomplete> </vn-datalist>
-->
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <vn-horizontal>
<vn-textfield <vn-textfield

View File

@ -12,12 +12,59 @@ export default class Controller {
}; };
} }
get postcodeSelection() { onResponse(response) {
return this._postcodeSelection; this.client.postcode = response.code;
} }
set postcodeSelection(selection) { onSubmit() {
this._postcodeSelection = selection; return this.$.watcher.submit().then(
json => 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; if (!selection) return;
@ -29,17 +76,8 @@ export default class Controller {
this.client.provinceFk = province.id; this.client.provinceFk = province.id;
this.client.countryFk = country.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']; Controller.$inject = ['$scope', '$state', '$http', '$translate', 'vnApp'];
ngModule.component('vnClientCreate', { ngModule.component('vnClientCreate', {

View File

@ -33,9 +33,7 @@
</vn-textfield> </vn-textfield>
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <vn-horizontal>
<vn-autocomplete <vn-autocomplete vn-id="country" vn-one
vn-one
vn-id="country"
ng-model="$ctrl.client.countryFk" ng-model="$ctrl.client.countryFk"
url="Countries" url="Countries"
show-field="country" show-field="country"
@ -43,51 +41,44 @@
label="Country" label="Country"
rule> rule>
</vn-autocomplete> </vn-autocomplete>
<vn-autocomplete <vn-autocomplete vn-id="province" vn-one
vn-one label="Province"
vn-id="province"
ng-model="$ctrl.client.provinceFk" ng-model="$ctrl.client.provinceFk"
url="Provinces" selection="$ctrl.province"
url="Provinces/location"
fields="['id', 'name', 'countryFk']"
where="{countryFk: country.selection.id}" where="{countryFk: country.selection.id}"
show-field="name" show-field="name"
value-field="id" value-field="id"
label="Province"
rule> rule>
<tpl-item>{{name}} ({{country.country}})</tpl-item>
</vn-autocomplete> </vn-autocomplete>
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <vn-horizontal>
<vn-textfield <vn-datalist vn-id="town" vn-one
vn-one
label="City" label="City"
ng-model="$ctrl.client.city" ng-model="$ctrl.client.city"
rule> selection="$ctrl.town"
</vn-textfield> url="Towns/location"
<vn-textfield fields="['id', 'name', 'provinceFk']"
vn-one
label="Postcode"
ng-model="$ctrl.client.postcode"
rule>
</vn-textfield>
<!-- <vn-autocomplete vn-id="town" vn-one
label="City"
url="Towns"
fields="['id', 'name']"
where="{provinceFk: province.selection.id}" where="{provinceFk: province.selection.id}"
show-field="name" show-field="name"
value-field="name" value-field="name">
ng-model="$ctrl.client.city"> <tpl-item>{{name}} ({{province.name}}, {{province.country.country}})</tpl-item>
</vn-autocomplete> </vn-datalist>
<vn-autocomplete vn-id="postcode" vn-one <vn-datalist vn-one
url="Postcodes/location" label="Postcode"
fields="['code', 'townFk']"
ng-model="$ctrl.client.postcode" ng-model="$ctrl.client.postcode"
search-function="{code: $search}" selection="$ctrl.postcode"
url="Postcodes/location"
fields="['code','townFk']"
where="{townFk: town.selection.id}" where="{townFk: town.selection.id}"
order="code, townFk" order="code, townFk"
show-field="code"
value-field="code" value-field="code"
label="Postcode"> show-field="code"
</vn-autocomplete> --> rule>
<tpl-item>{{code}} - {{town.name}} ({{town.province.name}}, {{town.province.country.country}})</tpl-item>
</vn-datalist>
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <vn-horizontal>
<vn-check <vn-check

View File

@ -76,6 +76,64 @@ export default class Controller extends Component {
this.$.$apply(); this.$.$apply();
} }
get province() {
return this._province;
}
// Province auto complete
set province(selection) {
const oldValue = this._province;
this._province = selection;
if (!selection || !oldValue) return;
const country = selection.country;
this.client.countryFk = country.id;
}
get town() {
return this._town;
}
// Town auto complete
set town(selection) {
const oldValue = this._town;
this._town = selection;
if (!selection || !oldValue) 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) {
const oldValue = this._postcode;
this._postcode = selection;
console.log(selection);
if (!selection || !oldValue) return;
const town = selection.town;
const province = town.province;
const country = province.country;
console.log(province.id);
this.client.city = town.name;
this.client.provinceFk = province.id;
this.client.countryFk = country.id;
}
} }
ngModule.component('vnClientFiscalData', { ngModule.component('vnClientFiscalData', {