get address return province data

This commit is contained in:
Dani Herrero 2017-09-28 11:29:01 +02:00
parent 1d47bf58f1
commit 70e4b22e8a
3 changed files with 26 additions and 8 deletions

View File

@ -1,6 +1,6 @@
<mg-ajax path="/client/api/Addresses/{{edit.params.addressId}}" actions="$ctrl.address=edit.model" options="mgEdit"></mg-ajax>
<vn-watcher
vn-id="watcher"
get="true"
url="/client/api/Addresses"
id-field="id"
data="$ctrl.address"
@ -23,6 +23,7 @@
<vn-textfield vn-one label="Postcode" field="$ctrl.address.postcode"></vn-textfield>
<vn-textfield vn-one label="City" field="$ctrl.address.city"></vn-textfield>
<vn-autocomplete vn-one
initial-data="$ctrl.address.province"
field="$ctrl.address.provinceFk"
url="/client/api/Provinces"
show-field="name"

View File

@ -25,8 +25,10 @@ export default class Watcher extends Component {
this.copyData();
}
$onInit() {
if (this.get) {
if (this.get && this.url) {
this.fetchData();
} else if (this.get && !this.url) {
throw new Error('Error: Parameter url ommitted');
}
}
$onChanges(changes) {
@ -39,12 +41,15 @@ export default class Watcher extends Component {
}
fetchData() {
let id = this.data[this.idField];
return new Promise((resolve, reject) => {
this.$http.get(`${this.url}/${id}`).then(
json => this.writeData(json, resolve),
json => reject(json)
);
});
// return new Promise((resolve, reject) => {
this.$http.get(`${this.url}/${id}`).then(
json => {
this.data = this.copyObject(json.data);
this.copyData();
}
// json => reject(json)
);
// });
}
/**
* Submits the data and goes back in the history.

View File

@ -22,6 +22,18 @@ module.exports = function(Address) {
getAddress(ctx, data, next);
});
Address.beforeRemote('findById', function(ctx, modelInstance, next) {
ctx.args.filter = {
"include": {
"relation": "province",
"scope": {
"fields": ["id", "name"]
}
}
};
next();
});
function getAddress(ctx, data, next){
var address = Address.findOne( {where: { id: data.id}}, function (err, address){
if(address)