bitfront-library
Version:
Angular CLI project with components and classes used by other Angular projects of the BIT foundation.
115 lines • 5.78 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.BitCustomComponent = void 0;
var core_1 = require("@angular/core");
var ayuda_service_1 = require("../../service/ayuda.service");
var bit_general_component_1 = require("./bit-general.component");
var i0 = require("@angular/core");
var i1 = require("../../service/ayuda.service");
var noop = function () { };
/** Clase customizada para componentes personalizados que requieren implementar la interface ControlValueAccessor.
* Tipicamente para aquellos componentes personalizados que trabajan sobre otros componentes no estándars HTML como
* pueden ser los componentes de prime como switch, autocomplete, calendar, select, etc.
*/
var BitCustomComponent = /** @class */ (function (_super) {
__extends(BitCustomComponent, _super);
function BitCustomComponent(ayudaService, changeDetectorRef) {
var _this = _super.call(this, ayudaService) || this;
_this.ayudaService = ayudaService;
_this.changeDetectorRef = changeDetectorRef;
_this.onTouchedCallback = noop;
_this.onChangeCallback = noop;
return _this;
}
Object.defineProperty(BitCustomComponent.prototype, "value", {
//sobreescribimos el getter para coger el valor del FormControl
get: function () {
return this.control.value;
},
//sobreescribimos el setter del value para poder transformarlo
set: function (v) {
v = this.transformData(v);
if (v !== this.control.value) {
//v != undefined &&
this.control.setValue(v);
this.onTouchedCallback();
this.onChangeCallback(v);
}
},
enumerable: false,
configurable: true
});
Object.defineProperty(BitCustomComponent.prototype, "value_lectura", {
/** Solo se activa este método si el input readOnly es true */
get: function () {
if (this.value == null) {
return "";
}
else {
return this.value;
}
},
enumerable: false,
configurable: true
});
/** El comportamiento normal es no transformar nada. Si el componente hijo necesita transformarlo
* que sobreecriba el método y modifique el comportamiento. Esto se dará típicamente en los campos fecha porque
* no queremos la versión ISO que nos da Prime si no una versión españolizada*/
BitCustomComponent.prototype.transformData = function (v) {
return v;
};
/** Controlamos si debemos modificar el valor interno del componente mediante una transformacion al tener un pipe asociado*/
BitCustomComponent.prototype.onBlur = function () {
if (this.instanciaPipe != null) {
this.control.setValue(this.instanciaPipe.transform(this.control.value));
this.onChangeCallback(this.control.value);
}
this.onTouchedCallback();
};
/** Controlamos si debemos modificar el valor interno del componente mediante una transformacion al tener un pipe asociado*/
BitCustomComponent.prototype.onFocus = function () {
if (this.instanciaPipe != null) {
this.control.setValue(this.instanciaPipe.parse(this.control.value));
this.control.updateValueAndValidity();
this.onChangeCallback(this.control.value);
}
this.onTouchedCallback();
};
/** Se activa cuando debemos Angular nos informa de que debemos actualizar la vista. Cada componente hijo deberá ver
* si requiere o no implementar este método */
BitCustomComponent.prototype.writeValue = function (value) {
if (value !== this.control.value) {
// hack para que el ControlValueAccesor funcione correctamente cuando está referenciado en componentes con ChangeDetectionStrategy.OnPush
// (no es nada bonito, pero Angular lleva 2 años con este bug y no lo han solucionado)
// si no lo incluimos, en algunos casos se corre el riesgo de ir varios valores por detrás en el bit-input
this.changeDetectorRef.markForCheck();
}
};
BitCustomComponent.prototype.registerOnChange = function (fn) {
this.onChangeCallback = fn;
};
BitCustomComponent.prototype.registerOnTouched = function (fn) {
this.onTouchedCallback = fn;
};
BitCustomComponent.ɵfac = function BitCustomComponent_Factory(t) { return new (t || BitCustomComponent)(i0.ɵɵdirectiveInject(i1.AyudaService), i0.ɵɵdirectiveInject(i0.ChangeDetectorRef)); };
BitCustomComponent.ɵdir = i0.ɵɵdefineDirective({ type: BitCustomComponent, features: [i0.ɵɵInheritDefinitionFeature] });
return BitCustomComponent;
}(bit_general_component_1.BitGeneralComponent));
exports.BitCustomComponent = BitCustomComponent;
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(BitCustomComponent, [{
type: core_1.Directive
}], function () { return [{ type: i1.AyudaService }, { type: i0.ChangeDetectorRef }]; }, null); })();
//# sourceMappingURL=bit-custom.component.js.map