VnAutocomplete ya no carga los datos cuando los datos se pueden bandera.

Creado el método card en client para listar el cliente con sus datos para el combo.
This commit is contained in:
nelo 2017-05-17 08:19:03 +02:00
parent bdb7cf9ed3
commit ae3f9db948
8 changed files with 110 additions and 17 deletions

View File

@ -22,6 +22,7 @@
<vn-horizontal>
<vn-textfield vn-one label="Email" field="$ctrl.client.email"></vn-textfield>
<vn-autocomplete vn-one
initial-value="$ctrl.client.salesPerson"
field="$ctrl.client.salesPersonFk"
url="/client/api/Employees"
show-field="name"
@ -29,6 +30,7 @@
label="Comercial">
</vn-autocomplete>
<vn-autocomplete vn-one
initial-value="$ctrl.client.contactChannel"
field="$ctrl.client.contactChannelFk"
url="/client/api/ContactChannels"
show-field="name"

View File

@ -7,7 +7,7 @@ export const COMPONENT = {
controllerAs: 'card',
controller: function($http, $stateParams) {
this.client = null;
$http.get(`/client/api/Clients/${$stateParams.id}?filter[include][account]`).then(
$http.get(`/client/api/Clients/${$stateParams.id}/card`).then(
json => this.client = json.data
);

View File

@ -20,6 +20,7 @@
<vn-horizontal>
<vn-textfield vn-one label="Código postal" field="fiscal.client.postcode"></vn-textfield>
<vn-autocomplete vn-one
initial-value="fiscal.client.province"
field="fiscal.client.provinceFk"
url="/client/api/Provinces"
show-field="name"
@ -27,6 +28,7 @@
label="Provincia">
</vn-autocomplete>
<vn-autocomplete vn-one
initial-value="fiscal.client.country"
field="fiscal.client.countryFk"
url="/client/api/Countries"
show-field="name"
@ -42,6 +44,7 @@
<vn-horizontal>
<vn-textfield vn-two label="IBAN" field="fiscal.client.iban"></vn-textfield>
<vn-autocomplete vn-two
initial-value="fiscal.client.payMethod"
field="fiscal.client.payMethodFk"
url="/client/api/PayMethods"
show-field="name"

View File

@ -27,7 +27,6 @@ export default class Autocomplete extends Component {
this.vnPopover = vnPopover;
componentHandler.upgradeElement($element[0].firstChild);
this.requestItem();
}
set field(value) {
this.locked = true;
@ -37,6 +36,14 @@ export default class Autocomplete extends Component {
get field() {
return this.value;
}
set initialValue(value) {
if (value) {
if (!this.data)
this.data = [];
this.data.push(value);
}
}
mdlUpdate() {
let mdlField = this.element.firstChild.MaterialTextfield;
if (mdlField)
@ -191,9 +198,6 @@ export default class Autocomplete extends Component {
this.hasFocus = true;
this.input.select();
if (this.data)
this.showPopover();
else
this.loadData();
}
onBlur() {
@ -340,6 +344,13 @@ export default class Autocomplete extends Component {
this.item = item;
this.mdlUpdate();
}
$onChanges(changes) {
if (!changes.initialValue)
this.requestItem();
else
this.showItem(changes.initialValue);
}
}
Autocomplete.$inject = ['$element', '$scope', '$http', 'vnPopover'];
@ -349,6 +360,7 @@ module.component('vnAutocomplete', {
url: '@',
showField: '@',
valueField: '@',
initialValue: '<',
field: '=',
label: '@'
},

View File

@ -1,7 +1,8 @@
module.exports = function(Client) {
// Validations
require("../scopes/card.js")(Client);
// Validations
Client.validatesUniquenessOf('name', {message: 'El nombre debe ser único'});
Client.validatesUniquenessOf('fi', {message: 'El NIF/CIF debe ser único'});
Client.validatesPresenceOf('socialName', {message: 'Debe especificarse la razón social'});

View File

@ -149,12 +149,5 @@
"permission": "ALLOW"
}
],
"methods": {},
"scopes": {
"test": {
"where": {
"name": "Verdnatura"
}
}
}
"methods": {}
}

View File

@ -0,0 +1,39 @@
module.exports = function(Client) {
// Validations
var card = require('./card.json');
Client.remoteMethod('card', {
description: 'Get client for card call',
accepts: {
arg: 'id',
type: 'number',
required: true,
description: 'Model id',
http: {source: 'path'}
},
returns: {
arg: 'data',
type: 'Client',
root: true
},
http: {
verb: 'get',
path: '/:id/card'
}
});
Client.card = function(id, cb) {
let filter = {
where: {
id: id
},
include: card
};
Client.find(filter, function(err, instances) {
if(!err) {
cb(null, instances[0]);
}
})
};
};

View File

@ -0,0 +1,43 @@
[
{
"relation": "salesPerson",
"scope":{
"fields": {
"id": true, "name": true
}
}
},
{
"relation": "contactChannel",
"scope":{
"fields": {
"id": true, "name": true
}
}
},
{
"relation": "province",
"scope":{
"fields": {
"id": true, "name": true
}
}
},
{
"relation": "country",
"scope":{
"fields": {
"id": true, "name": true
}
}
},
{
"relation": "payMethod",
"scope":{
"fields": {
"id": true, "name": true
}
}
}
]