401 redirecciona a login, vnAutocomplete: campos seleccionados

This commit is contained in:
Juan Ferrer Toribio 2017-05-23 14:05:26 +02:00
parent 434002b308
commit 5b9fcf868a
4 changed files with 62 additions and 37 deletions

View File

@ -1,21 +1,24 @@
<mg-ajax path="/client/api/Clients/{{put.params.id}}" options="vnPut"></mg-ajax>
<vn-watcher
vn-id="watcher"
data="bill.client"
form="form"
save="put"
>
vn-id="watcher"
data="bill.client"
form="form"
save="put">
</vn-watcher>
<form name="form" ng-submit="watcher.submit()" pad-medium>
<vn-card margin-small-bottom>
<vn-vertical pad-large>
<vn-title>Información de facturación</vn-title>
<vn-horizontal>
<vn-autocomplete vn-two initial-value="bill.client.payMethod" field="bill.client.payMethodFk" url="/client/api/PayMethods"
show-field="name" value-field="id" label="Forma de pago">
</vn-autocomplete>
<vn-textfield vn-two label="IBAN" field="bill.client.iban"></vn-textfield>
<vn-textfield vn-one label="Vencimiento" field="bill.client.dueDay"></vn-textfield>
<vn-autocomplete vn-two
field="bill.client.payMethodFk"
url="/client/api/PayMethods"
select-fields="ibanRequired"
initial-data="bill.client.payMethod"
label="Forma de pago">
</vn-autocomplete>
<vn-textfield vn-two label="IBAN" field="bill.client.iban"></vn-textfield>
<vn-textfield vn-one label="Vencimiento" field="bill.client.dueDay"></vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-textfield vn-one label="Crédito" field="bill.client.credit"></vn-textfield>
@ -34,7 +37,6 @@
</vn-horizontal>
</vn-vertical>
</vn-card>
<vn-button-bar>
<vn-submit label="Guardar"></vn-submit>
</vn-button-bar>

View File

@ -12,20 +12,25 @@ export default class Autocomplete extends Component {
this.item = null;
this.data = null;
this.popover = null;
this.popoverData = null;
this.displayData = null;
this.timeoutId = null;
this.lastSearch = null;
this.lastRequest = null;
this.currentRequest = null;
this.moreData = false;
this.activeOption = -1;
this.maxRows = 10;
this.requestDelay = 350;
this.locked = false;
this.$http = $http;
this.$scope = $scope;
this.vnPopover = vnPopover;
Object.assign(this, {
maxRows: 10,
requestDelay: 350,
showField: 'name',
valueField: 'id'
});
componentHandler.upgradeElement($element[0].firstChild);
}
set field(value) {
@ -36,13 +41,23 @@ export default class Autocomplete extends Component {
get field() {
return this.value;
}
set initialValue(value) {
set initialData(value) {
if (value) {
if (!this.data)
this.data = [];
this.data.push(value);
}
}
set selectFields(value) {
this._selectFields = [];
if (!value)
return;
let res = value.split(',');
for (let i of res)
this._selectFields.push(i.trim());
}
mdlUpdate() {
let mdlField = this.element.firstChild.MaterialTextfield;
if (mdlField)
@ -52,7 +67,7 @@ export default class Autocomplete extends Component {
textFilter = textFilter ? textFilter : '';
if (this.lastSearch === textFilter) {
this.popoverDataReady();
this.showPopoverIfFocus();
return;
}
@ -72,6 +87,11 @@ export default class Autocomplete extends Component {
let fields = {};
fields[this.valueField] = true;
fields[this.showField] = true;
if (this._selectFields)
for (let field of this._selectFields)
fields[field] = true;
return fields;
}
requestData(textFilter, append) {
@ -112,28 +132,30 @@ export default class Autocomplete extends Component {
else
this.data = this.data.concat(data);
this.setPopoverData(this.data);
this.setDisplayData(this.data);
}
localFilter(textFilter) {
let regex = new RegExp(textFilter, 'i');
let data = this.data.filter(item => {
return regex.test(item[this.showField]);
});
this.setPopoverData(data);
this.setDisplayData(data);
}
setPopoverData(data) {
this.popoverData = data;
this.popoverDataReady();
setDisplayData(data) {
this.displayData = data;
this.showPopoverIfFocus();
}
popoverDataReady() {
showPopoverIfFocus() {
if (this.hasFocus)
this.showPopover();
}
showPopover() {
if (!this.data) return;
let data = this.displayData;
if (!data)
return;
let fragment = this.document.createDocumentFragment();
let data = this.popoverData;
for (let i = 0; i < data.length; i++) {
let li = this.document.createElement('li');
@ -171,8 +193,8 @@ export default class Autocomplete extends Component {
}
selectPopoverOption(index) {
if (!this.popover || index === -1) return;
if (index < this.popoverData.length) {
this.selectOptionByDataIndex(this.popoverData, index);
if (index < this.displayData.length) {
this.selectOptionByDataIndex(this.displayData, index);
this.hidePopover();
} else
this.requestData(this.lastRequest, true);
@ -276,7 +298,7 @@ export default class Autocomplete extends Component {
let popover = this.popover;
let childs = popover.childNodes;
let len = this.popoverData.length;
let len = this.displayData.length;
if (this.activeOption >= 0)
childs[this.activeOption].className = '';
@ -332,11 +354,8 @@ export default class Autocomplete extends Component {
this.showItem(item);
let value = item ? item[this.valueField] : undefined;
if (!this.locked) {
if (!this.locked)
this.value = value;
setTimeout(
() => this.$scope.$apply());
}
}
showItem(item) {
this.input.value = item ? item[this.showField] : '';
@ -350,9 +369,10 @@ module.component('vnAutocomplete', {
template: require('./index.html'),
bindings: {
url: '@',
showField: '@',
valueField: '@',
initialValue: '<',
showField: '@?',
valueField: '@?',
selectFields: '@?',
initialData: '<?',
field: '=',
label: '@'
},

View File

@ -23,8 +23,8 @@ ngModule.provider('vnAppLogger', function() {
this.$get = vnAppLogger;
});
vnAppInterceptor.$inject = ['$q', '$rootScope', 'vnAppLogger', '$translate', '$cookies'];
function vnAppInterceptor($q, $rootScope, logger, $translate, $cookies) {
vnAppInterceptor.$inject = ['$q', '$rootScope', '$window', 'vnAppLogger', '$translate', '$cookies'];
function vnAppInterceptor($q, $rootScope, $window, logger, $translate, $cookies) {
$rootScope.loading = false;
return {
request: function(config) {
@ -60,6 +60,9 @@ function vnAppInterceptor($q, $rootScope, logger, $translate, $cookies) {
else
error = `${rejection.status}: ${rejection.statusText}`;
if (rejection.status === 401)
$window.location = '/auth';
logger.showError(error);
return $q.reject(rejection);
}

View File

@ -14,7 +14,7 @@
},
"fi": {
"type": "string",
"description": "Fiscal indetifier"
"description": "Fiscal indentifier"
},
"socialName": {
"type": "string"