bug fixed on LoadMore action in autocomplete

This commit is contained in:
Dani Herrero 2017-10-03 09:16:02 +02:00
parent ff6801c8e8
commit 4e309b67f0
4 changed files with 26 additions and 10 deletions

View File

@ -16,7 +16,14 @@
<input type="checkbox" ng-checked="item.checked" ng-if="$ctrl.multiple"> <input type="checkbox" ng-checked="item.checked" ng-if="$ctrl.multiple">
<div ng-transclude="vnItem">{{item.name}}</div> <div ng-transclude="vnItem">{{item.name}}</div>
</li> </li>
<li ng-if="$ctrl.showLoadMore" class="dropdown__loadMore" tabIndex="-1" ng-class="{'active': $ctrl.itemsFiltered.length === $ctrl.activeOption}" ng-click="$ctrl.loadMore();$ctrl.show = true;" translate="Load More"></li> <li
ng-if="$ctrl.loadMore"
class="dropdown__loadMore"
tabIndex="-1"
ng-class="{'active': $ctrl.itemsFiltered.length === $ctrl.activeOption}"
ng-click="$ctrl.loadItems()"
translate="{{$ctrl.showLoadMore ? 'Show More' : 'No more results'}}"
></li>
</ul> </ul>
</vn-one> </vn-one>
</vn-vertical> </vn-vertical>

View File

@ -135,6 +135,13 @@ export default class DropDown {
} }
} }
loadItems() {
if (this.showLoadMore && this.loadMore) {
this.loadMore();
}
this.show = true;
}
$onInit() { $onInit() {
if (this.parent) if (this.parent)
this.parent.addEventListener('keydown', e => this.onKeydown(e)); this.parent.addEventListener('keydown', e => this.onKeydown(e));

View File

@ -6,5 +6,6 @@
"Save": "Guardar", "Save": "Guardar",
"Add": "Añadir", "Add": "Añadir",
"Search": "Buscar", "Search": "Buscar",
"Load More": "Cargar más" "Show More": "Ver más",
"No more results" : "No hay más resultados"
} }

View File

@ -1,7 +1,7 @@
module.exports = function(Address) { module.exports = function(Address) {
Address.validate('default',isEnabled,{message: 'No se puede poner predeterminado un consignatario desactivado'}); Address.validate('default',isEnabled,{message: 'No se puede poner predeterminado un consignatario desactivado'});
function isEnabled(err) { function isEnabled(err) {
if (!this.isEnabled && this.default) err(); if (!this.isEnabled && this.isDefaultAddress) err();
} }
Address.beforeRemote('create',function(ctx, modelInstance, next){ Address.beforeRemote('create',function(ctx, modelInstance, next){
@ -10,10 +10,11 @@ module.exports = function(Address) {
}); });
function create(data, next){ function create(data, next){
if(data.default){ if(data.isDefaultAddress){
removeAllDefault(data.client); removeAllDefault(data.client, next);
} } else {
next(); next();
}
} }
Address.beforeRemote('prototype.patchAttributes',function(ctx, modelInstance, next){ Address.beforeRemote('prototype.patchAttributes',function(ctx, modelInstance, next){
@ -42,10 +43,10 @@ module.exports = function(Address) {
} }
function callbackGetAddress(ctx, newData, oldData, next){ function callbackGetAddress(ctx, newData, oldData, next){
if (newData.default){ if (newData.isDefaultAddress){
removeAllDefault(oldData.client, next); removeAllDefault(oldData.client, next);
} }
else if (oldData.default && newData.hasOwnProperty('default') && !newData.default) else if (oldData.isDefaultAddress && newData.hasOwnProperty('isDefaultAddress') && !newData.isDefaultAddress)
next(generateErrorDefaultAddress()); next(generateErrorDefaultAddress());
else else
next(); next();
@ -59,7 +60,7 @@ module.exports = function(Address) {
} }
function removeAllDefault(client, next){ function removeAllDefault(client, next){
Address.updateAll({clientFk: client.id, default: true}, {default: false}, next); Address.updateAll({clientFk: client.id, isDefaultAddress: true}, {isDefaultAddress: false}, next);
} }
function generateErrorDefaultAddress(){ function generateErrorDefaultAddress(){