UNPKG

bitfront-library

Version:

Angular CLI project with components and classes used by other Angular projects of the BIT foundation.

107 lines 4.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BitGeneralComponent = void 0; var core_1 = require("@angular/core"); var forms_1 = require("@angular/forms"); var ayuda_service_1 = require("../../service/ayuda.service"); var i0 = require("@angular/core"); var i1 = require("../../service/ayuda.service"); /** * Clase general que todos los componentes personalizados deben extender. Contiene toda la lógica común para trabajar con * componentes personalizados */ var BitGeneralComponent = /** @class */ (function () { function BitGeneralComponent(ayudaService) { this.ayudaService = ayudaService; this.placeholder = ""; this.readOnly = false; this.hideLabel = false; // forzar que no se reserve espacio para el nombre del campo this.forceObligatorio = false; this.onChange = new core_1.EventEmitter(); } /** Debemos suscribirnos a los cambios del FormControl para emitir mediante onChange el evento con el nuevo valor que tiene el componente. */ BitGeneralComponent.prototype.ngOnInit = function () { var _this = this; if (this.control) { this.transformValue(); this.control.valueChanges.subscribe(function (value) { _this.transformValue(); _this.onChange.emit(value); }); } else { console.log("control no definido para " + this.nombre); } }; /** Controlamos si debemos modificar el valor interno del componente mediante una transformacion al tener un pipe asociado. */ BitGeneralComponent.prototype.onBlur = function () { if (this.instanciaPipe != null) { this.control.setValue(this.instanciaPipe.transform(this.control.value)); } }; BitGeneralComponent.prototype.onFocus = function () { if (this.instanciaPipe != null) { this.control.setValue(this.instanciaPipe.parse(this.control.value)); this.control.updateValueAndValidity(); } }; /** * Si es necesario, transformamos el valor de entrada para que se muestre correctamente en el campo (ver bit-dropdown-general). */ BitGeneralComponent.prototype.transformValue = function () { }; Object.defineProperty(BitGeneralComponent.prototype, "obligatorio", { // decidimos marcar el campo como obligatorio si se ha indicado a la fuerza (por parámetro) // o si el control de formulario asociado está saltando por ser obligatorio y no haberse rellenado get: function () { return this.forceObligatorio || (this.control && this.control.errors && this.control.errors["required"]); }, enumerable: false, configurable: true }); BitGeneralComponent.prototype.showAyuda = function () { this.ayudaService.mostrarAyuda(this.ayuda); }; Object.defineProperty(BitGeneralComponent.prototype, "value_lectura", { get: function () { return this.control.value; }, enumerable: false, configurable: true }); BitGeneralComponent.ɵfac = function BitGeneralComponent_Factory(t) { return new (t || BitGeneralComponent)(i0.ɵɵdirectiveInject(i1.AyudaService)); }; BitGeneralComponent.ɵdir = i0.ɵɵdefineDirective({ type: BitGeneralComponent, inputs: { control: "control", nombre: "nombre", nombreDirectiva: "nombreDirectiva", label: "label", estilo: "estilo", tooltipTexto: "tooltipTexto", tooltipPosicion: "tooltipPosicion", ayuda: "ayuda", placeholder: "placeholder", readOnly: "readOnly", hideLabel: "hideLabel", instanciaPipe: "instanciaPipe", forceObligatorio: "forceObligatorio" }, outputs: { onChange: "onChange" } }); return BitGeneralComponent; }()); exports.BitGeneralComponent = BitGeneralComponent; (function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(BitGeneralComponent, [{ type: core_1.Directive }], function () { return [{ type: i1.AyudaService }]; }, { control: [{ type: core_1.Input }], nombre: [{ type: core_1.Input }], nombreDirectiva: [{ type: core_1.Input }], label: [{ type: core_1.Input }], estilo: [{ type: core_1.Input }], tooltipTexto: [{ type: core_1.Input }], tooltipPosicion: [{ type: core_1.Input }], ayuda: [{ type: core_1.Input }], placeholder: [{ type: core_1.Input }], readOnly: [{ type: core_1.Input }], hideLabel: [{ type: core_1.Input }], instanciaPipe: [{ type: core_1.Input }], forceObligatorio: [{ type: core_1.Input }], onChange: [{ type: core_1.Output }] }); })(); //# sourceMappingURL=bit-general.component.js.map