Changed implementation and parameter of __barcodeChooseBackward to accept a format-like string; renamed retroCompatibility to backward

This commit is contained in:
alexandercerutti
2018-08-22 13:18:29 +02:00
parent dacfa8d799
commit f0c682abec

View File

@@ -400,7 +400,7 @@ class Pass {
return Object.assign({ return Object.assign({
length: 4, length: 4,
autocomplete: () => {}, autocomplete: () => {},
retroCompatibility: this.__barcodeChooseBackward.bind(this) backward: this.__barcodeChooseBackward.bind(this)
}, this); }, this);
} }
@@ -465,21 +465,19 @@ class Pass {
* property "barcode". * property "barcode".
* *
* @method __barcodeChooseRetroCompatibility * @method __barcodeChooseRetroCompatibility
* @params {Number} index - the position in this.props * @params {String} format - the format, or part of it, to be used
* @return {this} * @return {this}
*/ */
__barcodeChooseBackward(index) { __barcodeChooseBackward(format) {
if (typeof index !== "number") { if (typeof format !== "string") {
return this; return this;
} }
if (index > this.props["barcodes"].length) { let index = this.props["barcodes"].findIndex(b => b.format.toLowerCase().includes(format.toLowerCase()));
// resetting from left
index = index - this.props["barcodes"].length - 1; if (index === -1) {
} else if (index < 0) { return this;
// resetting from rigth
index = Math.abs(this.props["barcodes"].length - Math.abs(index));
} }
this.props["barcode"] = this.props["barcodes"][index]; this.props["barcode"] = this.props["barcodes"][index];