bitcitawebfrontlib-ibsalut
Version:
Angular CLI project used by other Angular projects in the bitcita web project.<br />
164 lines • 11 kB
JavaScript
"use strict";
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 (b.hasOwnProperty(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 __());
};
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var forms_1 = require("@angular/forms");
var rxjs_1 = require("rxjs");
var core_2 = require("@ngx-translate/core");
var campanya_service_1 = require("../../common/service/campanya.service");
var reservar_cita_paso_1 = require("./reservar-cita-paso");
var message_service_1 = require("../../shared/service/message.service");
var error_1 = require("../../shared/data/error");
var custom_validators_service_1 = require("../../shared/service/custom-validators.service");
var idioma_1 = require("../../shared/data/idioma");
var CAMPO_FECHA_NACIMIENTO = "fecha";
var CAMPO_DESCRIPCION = "descripcion";
var CAMPO_EMAIL = "email";
var DatosPersonalesComponent = /** @class */ (function (_super) {
__extends(DatosPersonalesComponent, _super);
function DatosPersonalesComponent(campanyaService, formBuilder, translate, message) {
var _this = _super.call(this, "DatosPersonalesComponent", campanyaService) || this;
_this.campanyaService = campanyaService;
_this.formBuilder = formBuilder;
_this.translate = translate;
_this.message = message;
return _this;
}
/// Comportamiento general del paso (sobrescribe lo definido en ReservaCitaPaso) ///
/** Cuando el usuario vuelve a esta pestaña y el servicio ha cambiado, hay que recargar la lista de campos. */
DatosPersonalesComponent.prototype.refreshDatosVisible = function () {
if (this.peticion.servicioId && this.servicioId !== this.peticion.servicioId) {
this.servicioId = this.peticion.servicioId;
this.loadCampos();
}
};
DatosPersonalesComponent.prototype.validarPaso = function () {
var _this = this;
if (this.myForm.valid) {
return true;
}
else {
this.translate.get("error.datosPersonales").subscribe(function (result) {
var err = new error_1.Error(null, idioma_1.Idioma.esCatalanSeleccionado() ? result : null, idioma_1.Idioma.esEspanyolSeleccionado() ? result : null, null, true);
_this.message.sendError(err);
});
}
};
DatosPersonalesComponent.prototype.updateReservaCita = function () {
if (this.listCampo) {
this.getFormValues();
this.peticion.setValores(this.listCampo);
this.resumen.setValores(this.listCampo);
}
};
DatosPersonalesComponent.prototype.getFormValues = function () {
for (var i = 0; this.listCampo != null && i < this.listCampo.length; i++) {
var campo = this.listCampo[i];
var value = this.myForm.controls["cmp" + campo.campoId].value;
campo.valor = value;
}
};
DatosPersonalesComponent.prototype.resetActions = function () {
this.servicioId = null;
this.listCampo = null;
};
/// Comportamiento propio de este paso ///
DatosPersonalesComponent.prototype.loadCampos = function () {
var _this = this;
this.campanyaService
.findCamposDeServicio(this.peticion.referencia, this.peticion.servicioId)
.subscribe(function (result) {
_this.listCampo = result;
_this.fillLabels();
_this.buildFormGroup();
});
};
DatosPersonalesComponent.prototype.fillLabels = function () {
this.listCampo.forEach(function (campo) {
if (!campo.label)
campo.label = campo.nombre;
else {
campo.label = campo.label.replace("<p>", "").replace("</p>", "");
console.log("" + campo.label);
}
});
};
/// Gestión de los formularios ///
DatosPersonalesComponent.prototype.buildFormGroup = function () {
var group = {};
for (var i = 0; this.listCampo != null && i < this.listCampo.length; i++) {
var campo = this.listCampo[i];
var checks = campo.obligatorio ? [forms_1.Validators.required] : [];
checks.push(custom_validators_service_1.CustomValidators.CustomValidatorsMap[campo.checkForm]);
group["cmp" + campo.campoId] = [this.listCampo[i].valor, checks];
}
this.myForm = this.formBuilder.group(group);
};
DatosPersonalesComponent.prototype.campoEsDescription = function (campo) {
return campo && campo.checkForm === CAMPO_DESCRIPCION;
};
DatosPersonalesComponent.prototype.campoEsText = function (campo) {
return !this.campoEsDescription(campo) && !campo.listaValores && !this.campoEsFecha(campo);
};
DatosPersonalesComponent.prototype.campoEsFecha = function (campo) {
return campo && campo.checkForm === CAMPO_FECHA_NACIMIENTO;
};
DatosPersonalesComponent.prototype.campoEsEmail = function (campo) {
return campo && campo.checkForm === CAMPO_EMAIL;
};
DatosPersonalesComponent.prototype.campoType = function (campo) {
return campo && this.campoEsEmail(campo) ? "email" : "text";
};
DatosPersonalesComponent.prototype.campoShowError = function (campoId) {
var control = this.myForm.controls["cmp" + campoId];
return control.invalid && control.touched;
};
DatosPersonalesComponent.prototype.campoError = function (campoId) {
var control = this.myForm.controls["cmp" + campoId];
if (control && control.errors && control.touched) {
var error = null;
for (var e in control.errors) {
error = e;
break;
}
return this.translate.get("error." + error);
}
else {
return rxjs_1.of(null);
}
};
DatosPersonalesComponent = __decorate([
core_1.Component({
selector: "bci-datos-personales",
template: "\n <div class=\"paso\" [style.display]=\"visible?'block':'none'\">\n <h4><span class=\"fa fa-user-circle-o\"></span> <span translate=\"titulo.introducirDatos\">Dades personals</span></h4>\n\n <!-- ng-template #DatosPersonalesCustom><ng-content select=\"[DatosPersonalesCustom]\"></ng-content></ng-template>\n <ng-container *ngTemplateOutlet=\"DatosPersonalesCustom\"></ng-container -->\n <ng-container *ngIf=\"textoDatosPersonales\">\n <div class=\"contenedor-texto-dinamico ql-editor\">\n <div class=\"row\">\n <div [innerHTML]=\"textoDatosPersonales | sanitizeInnerHtml\" class=\"col-sm-12\"></div>\n </div>\n </div>\n </ng-container>\n\n <div class=\"row\">\n <div class=\"col-sm-9 col-md-6\">\n <form *ngIf=\"myForm\" role=\"form\" [formGroup]=\"myForm\">\n <div class=\"form-group\" *ngFor=\"let campo of listCampo\">\n <span [innerHTML]=\"campo.label\">{{campo.label}}</span>\n\n <textarea *ngIf=\"campoEsDescription(campo)\" class=\"form-control\" cols=\"4\" pInputText\n id=\"cmp{{campo.campoId}}\" formControlName=\"cmp{{campo.campoId}}\" ></textarea>\n\n <input *ngIf=\"campoEsText(campo)\" class=\"form-control\" type=\"text\"\n id=\"cmp{{campo.campoId}}\" formControlName=\"cmp{{campo.campoId}}\" />\n\n <select *ngIf=\"campo.listaValores\" class=\"form-control\"\n id=\"cmp{{campo.campoId}}\" formControlName=\"cmp{{campo.campoId}}\">\n <option value=\"\"></option>\n <option *ngFor=\"let valor of campo.listaValoresValue; let i = index\" value=\"{{valor}}\">{{campo.listaValoresLabel[i]}}</option>\n </select>\n\n <span *ngIf=\"campoShowError(campo.campoId)\" class=\"texto-rojo\">Error: {{campoError(campo.campoId) | async}}</span>\n </div>\n </form>\n </div>\n </div>\n <div *ngIf=\"resumen?.servicio?.smsNotificarReserva\" class=\"row\">\n <div class=\"col-xs-12\">\n <div class=\"alert alert-warning\" translate=\"info.siQuiereSms\">\n (*) Si vol rebre la confirmació de la seva cita mitjantçant SMS, indiqui'ns el seu número de mòbil i estigui atent.\n </div>\n </div>\n </div>\n <div class=\"row\">\n <div class=\"col-xs-12\">\n <div class=\"btn-navegar\">\n <button class=\"btn btn-success pull-left\" (click)=\"goToPasoAnterior ();\"><span class=\"fa fa-chevron-left\"></span> <span translate=\"btn.atras\">Enrere</span></button>\n <button class=\"btn btn-success pull-right\" (click)=\"goToPasoSiguiente();\"><span translate=\"btn.continuar\">Continua</span> <span class=\"fa fa-chevron-right\"></span></button>\n </div>\n </div>\n </div>\n </div>\n "
}),
__metadata("design:paramtypes", [campanya_service_1.CampanyaService,
forms_1.FormBuilder,
core_2.TranslateService,
message_service_1.MessageService])
], DatosPersonalesComponent);
return DatosPersonalesComponent;
}(reservar_cita_paso_1.ReservarCitaPaso));
exports.DatosPersonalesComponent = DatosPersonalesComponent;
//# sourceMappingURL=2-datos-personales.component.js.map