angular-formio
Version:
Form.io Angular JSON Form Renderer ========================== This library serves as a Dynamic JSON Powered Form rendering library for [Angular](https://angular.io). This works by providing a JSON schema to a ```<formio>``` Angular component, where that f
1,407 lines (1,392 loc) • 141 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('lodash'), require('formiojs'), require('@angular/common'), require('@angular/router'), require('rxjs'), require('formiojs/utils/Evaluator')) :
typeof define === 'function' && define.amd ? define(['exports', '@angular/core', 'lodash', 'formiojs', '@angular/common', '@angular/router', 'rxjs', 'formiojs/utils/Evaluator'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['formio-auth'] = {}, global.core, global.lodash, global.formiojs, global.common, global.router, global.rxjs, global.Evaluator));
}(this, (function (exports, core, lodash, formiojs, common, router, rxjs, Evaluator) { 'use strict';
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var Evaluator__default = /*#__PURE__*/_interopDefaultLegacy(Evaluator);
/**
* @fileoverview added by tsickle
* Generated from: auth/auth.config.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var FormioAuthConfig = /** @class */ (function () {
function FormioAuthConfig() {
}
FormioAuthConfig.decorators = [
{ type: core.Injectable },
];
return FormioAuthConfig;
}());
/**
* @fileoverview added by tsickle
* Generated from: formio.config.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var FormioAppConfig = /** @class */ (function () {
function FormioAppConfig() {
this.appUrl = '';
this.apiUrl = '';
}
FormioAppConfig.decorators = [
{ type: core.Injectable },
];
return FormioAppConfig;
}());
/**
* @fileoverview added by tsickle
* Generated from: auth/auth.service.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var FormioAuthService = /** @class */ (function () {
function FormioAuthService(appConfig, config) {
var _this = this;
this.appConfig = appConfig;
this.config = config;
this.authenticated = false;
this.formAccess = {};
this.submissionAccess = {};
this.is = {};
this.user = null;
if (this.appConfig && this.appConfig.appUrl) {
formiojs.Formio.setBaseUrl(this.appConfig.apiUrl);
formiojs.Formio.setProjectUrl(this.appConfig.appUrl);
formiojs.Formio.formOnly = !!this.appConfig.formOnly;
}
else {
console.error('You must provide an AppConfig within your application!');
}
this.loginForm =
this.appConfig.appUrl +
'/' +
lodash.get(this.config, 'login.form', 'user/login');
this.registerForm =
this.appConfig.appUrl +
'/' +
lodash.get(this.config, 'register.form', 'user/register');
this.onLogin = new core.EventEmitter();
this.onLogout = new core.EventEmitter();
this.onRegister = new core.EventEmitter();
this.onUser = new core.EventEmitter();
this.onError = new core.EventEmitter();
this.ready = new Promise((/**
* @param {?} resolve
* @param {?} reject
* @return {?}
*/
function (resolve, reject) {
_this.readyResolve = resolve;
_this.readyReject = reject;
}));
// Register for the core events.
formiojs.Formio.events.on('formio.badToken', (/**
* @return {?}
*/
function () { return _this.logoutError(); }));
formiojs.Formio.events.on('formio.sessionExpired', (/**
* @return {?}
*/
function () { return _this.logoutError(); }));
if (!this.config.delayAuth) {
this.init();
}
}
/**
* @param {?} submission
* @return {?}
*/
FormioAuthService.prototype.onLoginSubmit = /**
* @param {?} submission
* @return {?}
*/
function (submission) {
this.setUser(submission);
this.onLogin.emit(submission);
};
/**
* @param {?} submission
* @return {?}
*/
FormioAuthService.prototype.onRegisterSubmit = /**
* @param {?} submission
* @return {?}
*/
function (submission) {
this.setUser(submission);
this.onRegister.emit(submission);
};
/**
* @return {?}
*/
FormioAuthService.prototype.init = /**
* @return {?}
*/
function () {
var _this = this;
this.projectReady = formiojs.Formio.makeStaticRequest(this.appConfig.appUrl).then((/**
* @param {?} project
* @return {?}
*/
function (project) {
lodash.each(project.access, (/**
* @param {?} access
* @return {?}
*/
function (access) {
_this.formAccess[access.type] = access.roles;
}));
}), (/**
* @return {?}
*/
function () {
_this.formAccess = {};
return null;
}));
// Get the access for this project.
this.accessReady = formiojs.Formio.makeStaticRequest(this.appConfig.appUrl + '/access').then((/**
* @param {?} access
* @return {?}
*/
function (access) {
lodash.each(access.forms, (/**
* @param {?} form
* @return {?}
*/
function (form) {
_this.submissionAccess[form.name] = {};
form.submissionAccess.forEach((/**
* @param {?} subAccess
* @return {?}
*/
function (subAccess) {
_this.submissionAccess[form.name][subAccess.type] = subAccess.roles;
}));
}));
_this.roles = access.roles;
return access;
}), (/**
* @return {?}
*/
function () {
_this.roles = {};
return null;
}));
/** @type {?} */
var currentUserPromise;
if (this.config.oauth) {
// Make a fix to the hash to remove starting "/" that angular might put there.
if (window.location.hash && window.location.hash.match(/^#\/access_token/)) {
history.pushState(null, null, window.location.hash.replace(/^#\/access_token/, '#access_token'));
}
// Initiate the SSO if they provide oauth settings.
currentUserPromise = formiojs.Formio.ssoInit(this.config.oauth.type, this.config.oauth.options);
}
else {
currentUserPromise = formiojs.Formio.currentUser();
}
this.userReady = currentUserPromise.then((/**
* @param {?} user
* @return {?}
*/
function (user) {
_this.setUser(user);
return user;
}));
// Trigger we are redy when all promises have resolved.
if (this.accessReady) {
this.accessReady
.then((/**
* @return {?}
*/
function () { return _this.projectReady; }))
.then((/**
* @return {?}
*/
function () { return _this.userReady; }))
.then((/**
* @return {?}
*/
function () { return _this.readyResolve(true); }))
.catch((/**
* @param {?} err
* @return {?}
*/
function (err) { return _this.readyReject(err); }));
}
};
/**
* @param {?} user
* @return {?}
*/
FormioAuthService.prototype.setUser = /**
* @param {?} user
* @return {?}
*/
function (user) {
/** @type {?} */
var namespace = formiojs.Formio.namespace || 'formio';
if (user) {
this.user = user;
localStorage.setItem(namespace + "AppUser", JSON.stringify(user));
this.setUserRoles();
}
else {
this.user = null;
this.is = {};
localStorage.removeItem(namespace + "AppUser");
formiojs.Formio.clearCache();
formiojs.Formio.setUser(null);
}
this.authenticated = !!formiojs.Formio.getToken();
this.onUser.emit(this.user);
};
/**
* @return {?}
*/
FormioAuthService.prototype.setUserRoles = /**
* @return {?}
*/
function () {
var _this = this;
if (this.accessReady) {
this.accessReady.then((/**
* @return {?}
*/
function () {
lodash.each(_this.roles, (/**
* @param {?} role
* @param {?} roleName
* @return {?}
*/
function (role, roleName) {
if (_this.user.roles.indexOf(role._id) !== -1) {
_this.is[roleName] = true;
}
}));
}));
}
};
/**
* @return {?}
*/
FormioAuthService.prototype.logoutError = /**
* @return {?}
*/
function () {
this.setUser(null);
/** @type {?} */
var namespace = formiojs.Formio.namespace || 'formio';
localStorage.removeItem(namespace + "Token");
this.onError.emit();
};
/**
* @return {?}
*/
FormioAuthService.prototype.logout = /**
* @return {?}
*/
function () {
var _this = this;
this.setUser(null);
/** @type {?} */
var namespace = formiojs.Formio.namespace || 'formio';
localStorage.removeItem(namespace + "Token");
formiojs.Formio.logout()
.then((/**
* @return {?}
*/
function () { return _this.onLogout.emit(); }))
.catch((/**
* @return {?}
*/
function () { return _this.logoutError(); }));
};
FormioAuthService.decorators = [
{ type: core.Injectable },
];
/** @nocollapse */
FormioAuthService.ctorParameters = function () { return [
{ type: FormioAppConfig },
{ type: FormioAuthConfig }
]; };
return FormioAuthService;
}());
/**
* @fileoverview added by tsickle
* Generated from: auth/auth.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var FormioAuthComponent = /** @class */ (function () {
function FormioAuthComponent() {
}
FormioAuthComponent.decorators = [
{ type: core.Component, args: [{
template: "<div class=\"card card-primary panel panel-default\"> <div class=\"card-header panel-heading\"> <ul class=\"nav nav-tabs card-header-tabs\"> <li class=\"nav-item\" role=\"presentation\" routerLinkActive=\"active\"><a class=\"nav-link\" routerLink=\"login\" routerLinkActive=\"active\">Login</a></li> <li class=\"nav-item\" role=\"presentation\" routerLinkActive=\"active\"><a class=\"nav-link\" routerLink=\"register\" routerLinkActive=\"active\">Register</a></li> </ul> </div> <div class=\"card-body panel-body\"> <router-outlet></router-outlet> </div> </div> "
},] },
];
return FormioAuthComponent;
}());
/**
* @fileoverview added by tsickle
* Generated from: auth/login/login.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var FormioAuthLoginComponent = /** @class */ (function () {
function FormioAuthLoginComponent(service) {
this.service = service;
}
FormioAuthLoginComponent.decorators = [
{ type: core.Component, args: [{
template: "<formio [src]=\"service.loginForm\" (submit)=\"service.onLoginSubmit($event)\"></formio> "
},] },
];
/** @nocollapse */
FormioAuthLoginComponent.ctorParameters = function () { return [
{ type: FormioAuthService }
]; };
return FormioAuthLoginComponent;
}());
/**
* @fileoverview added by tsickle
* Generated from: auth/register/register.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var FormioAuthRegisterComponent = /** @class */ (function () {
function FormioAuthRegisterComponent(service) {
this.service = service;
}
FormioAuthRegisterComponent.decorators = [
{ type: core.Component, args: [{
template: "<formio [src]=\"service.registerForm\" (submit)=\"service.onRegisterSubmit($event)\"></formio> "
},] },
];
/** @nocollapse */
FormioAuthRegisterComponent.ctorParameters = function () { return [
{ type: FormioAuthService }
]; };
return FormioAuthRegisterComponent;
}());
/**
* @fileoverview added by tsickle
* Generated from: auth/auth.routes.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @param {?=} config
* @return {?}
*/
function FormioAuthRoutes(config) {
return [
{
path: '',
component: config && config.auth ? config.auth : FormioAuthComponent,
children: [
{
path: '',
redirectTo: 'login',
pathMatch: 'full'
},
{
path: 'login',
component: config && config.login ? config.login : FormioAuthLoginComponent
},
{
path: 'register',
component: config && config.register ? config.register : FormioAuthRegisterComponent
}
]
}
];
}
/**
* @fileoverview added by tsickle
* Generated from: formio.service.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var FormioService = /** @class */ (function () {
function FormioService(url, options) {
this.url = url;
this.options = options;
this.formio = new formiojs.Formio(this.url, this.options);
}
/**
* @param {?} fn
* @return {?}
*/
FormioService.prototype.requestWrapper = /**
* @param {?} fn
* @return {?}
*/
function (fn) {
/** @type {?} */
var record;
/** @type {?} */
var called = false;
return rxjs.Observable.create((/**
* @param {?} observer
* @return {?}
*/
function (observer) {
try {
if (!called) {
called = true;
fn()
.then((/**
* @param {?} _record
* @return {?}
*/
function (_record) {
record = _record;
observer.next(record);
observer.complete();
}))
.catch((/**
* @param {?} err
* @return {?}
*/
function (err) { return observer.error(err); }));
}
else if (record) {
observer.next(record);
observer.complete();
}
}
catch (err) {
observer.error(err);
}
}));
};
/**
* @param {?} form
* @param {?=} options
* @return {?}
*/
FormioService.prototype.saveForm = /**
* @param {?} form
* @param {?=} options
* @return {?}
*/
function (form, options) {
var _this = this;
return this.requestWrapper((/**
* @return {?}
*/
function () { return _this.formio.saveForm(form, options); }));
};
/**
* @param {?=} query
* @param {?=} options
* @return {?}
*/
FormioService.prototype.loadForm = /**
* @param {?=} query
* @param {?=} options
* @return {?}
*/
function (query, options) {
var _this = this;
return this.requestWrapper((/**
* @return {?}
*/
function () { return _this.formio.loadForm(query, options); }));
};
/**
* @param {?} query
* @param {?=} options
* @return {?}
*/
FormioService.prototype.loadForms = /**
* @param {?} query
* @param {?=} options
* @return {?}
*/
function (query, options) {
var _this = this;
return this.requestWrapper((/**
* @return {?}
*/
function () { return _this.formio.loadForms(query, options); }));
};
/**
* @param {?=} query
* @param {?=} options
* @return {?}
*/
FormioService.prototype.loadSubmission = /**
* @param {?=} query
* @param {?=} options
* @return {?}
*/
function (query, options) {
var _this = this;
return this.requestWrapper((/**
* @return {?}
*/
function () { return _this.formio.loadSubmission(query, options); }));
};
/**
* @param {?} user
* @param {?} form
* @param {?} submission
* @return {?}
*/
FormioService.prototype.userPermissions = /**
* @param {?} user
* @param {?} form
* @param {?} submission
* @return {?}
*/
function (user, form, submission) {
var _this = this;
return this.requestWrapper((/**
* @return {?}
*/
function () { return _this.formio.userPermissions(user, form, submission); }));
};
/**
* @param {?=} data
* @param {?=} options
* @return {?}
*/
FormioService.prototype.deleteSubmission = /**
* @param {?=} data
* @param {?=} options
* @return {?}
*/
function (data, options) {
var _this = this;
return this.requestWrapper((/**
* @return {?}
*/
function () { return _this.formio.deleteSubmission(data, options); }));
};
/**
* @param {?} submission
* @param {?=} options
* @return {?}
*/
FormioService.prototype.saveSubmission = /**
* @param {?} submission
* @param {?=} options
* @return {?}
*/
function (submission, options) {
var _this = this;
return this.requestWrapper((/**
* @return {?}
*/
function () { return _this.formio.saveSubmission(submission, options); }));
};
/**
* @param {?=} query
* @param {?=} options
* @return {?}
*/
FormioService.prototype.loadSubmissions = /**
* @param {?=} query
* @param {?=} options
* @return {?}
*/
function (query, options) {
var _this = this;
return this.requestWrapper((/**
* @return {?}
*/
function () { return _this.formio.loadSubmissions(query, options); }));
};
return FormioService;
}());
/**
* @fileoverview added by tsickle
* Generated from: components/alerts/formio.alerts.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var FormioAlerts = /** @class */ (function () {
function FormioAlerts() {
this.alerts = [];
}
/**
* @param {?} alert
* @return {?}
*/
FormioAlerts.prototype.setAlert = /**
* @param {?} alert
* @return {?}
*/
function (alert) {
this.alerts = [alert];
};
/**
* @param {?} alert
* @return {?}
*/
FormioAlerts.prototype.addAlert = /**
* @param {?} alert
* @return {?}
*/
function (alert) {
this.alerts.push(alert);
};
/**
* @param {?} alerts
* @return {?}
*/
FormioAlerts.prototype.setAlerts = /**
* @param {?} alerts
* @return {?}
*/
function (alerts) {
this.alerts = alerts;
};
return FormioAlerts;
}());
/**
* @fileoverview added by tsickle
* Generated from: custom-component/custom-tags.service.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var CustomTagsService = /** @class */ (function () {
function CustomTagsService() {
this.tags = [];
}
/**
* @param {?} tag
* @return {?}
*/
CustomTagsService.prototype.addCustomTag = /**
* @param {?} tag
* @return {?}
*/
function (tag) {
this.tags.push(tag);
};
CustomTagsService.decorators = [
{ type: core.Injectable },
];
return CustomTagsService;
}());
/**
* @fileoverview added by tsickle
* Generated from: types/alerts-position.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @enum {number} */
var AlertsPosition = {
none: 0,
top: 1,
bottom: 2,
both: 3,
};
AlertsPosition[AlertsPosition.none] = 'none';
AlertsPosition[AlertsPosition.top] = 'top';
AlertsPosition[AlertsPosition.bottom] = 'bottom';
AlertsPosition[AlertsPosition.both] = 'both';
var __assign = (undefined && undefined.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var FormioBaseComponent = /** @class */ (function () {
function FormioBaseComponent(ngZone, config, customTags) {
var _this = this;
this.ngZone = ngZone;
this.config = config;
this.customTags = customTags;
this.submission = {};
this.noeval = false;
this.readOnly = false;
this.viewOnly = false;
this.hooks = {};
this.watchSubmissionErrors = false;
this.render = new core.EventEmitter();
this.customEvent = new core.EventEmitter();
this.fileUploadingStatus = new core.EventEmitter();
this.submit = new core.EventEmitter();
this.prevPage = new core.EventEmitter();
this.nextPage = new core.EventEmitter();
this.beforeSubmit = new core.EventEmitter();
this.change = new core.EventEmitter();
this.invalid = new core.EventEmitter();
this.errorChange = new core.EventEmitter();
this.formLoad = new core.EventEmitter();
this.submissionLoad = new core.EventEmitter();
this.ready = new core.EventEmitter();
this.AlertsPosition = AlertsPosition;
this.initialized = false;
this.alerts = new FormioAlerts();
this.submitting = false;
this.submissionSuccess = false;
this.isLoading = true;
this.formioReady = new Promise((/**
* @param {?} ready
* @return {?}
*/
function (ready) {
_this.formioReadyResolve = ready;
}));
}
/**
* @return {?}
*/
FormioBaseComponent.prototype.getRenderer = /**
* @return {?}
*/
function () {
return this.renderer;
};
/**
* @return {?}
*/
FormioBaseComponent.prototype.getRendererOptions = /**
* @return {?}
*/
function () {
/** @type {?} */
var extraTags = this.customTags ? this.customTags.tags : [];
return lodash.assign({}, {
icons: lodash.get(this.config, 'icons', 'fontawesome'),
noAlerts: lodash.get(this.options, 'noAlerts', true),
readOnly: this.readOnly,
viewAsHtml: this.viewOnly,
i18n: lodash.get(this.options, 'i18n', null),
fileService: lodash.get(this.options, 'fileService', null),
hooks: this.hooks,
sanitizeConfig: {
addTags: extraTags
}
}, this.renderOptions || {});
};
/**
* @return {?}
*/
FormioBaseComponent.prototype.createRenderer = /**
* @return {?}
*/
function () {
/** @type {?} */
var Renderer = this.getRenderer();
/** @type {?} */
var form = (new Renderer(this.formioElement ? this.formioElement.nativeElement : null, this.form, this.getRendererOptions()));
return form.instance;
};
/**
* @param {?} form
* @return {?}
*/
FormioBaseComponent.prototype.setForm = /**
* @param {?} form
* @return {?}
*/
function (form) {
var _this = this;
this.form = form;
if (this.formio) {
this.formio.destroy();
}
// Clear out the element to render the new form.
if (this.formioElement && this.formioElement.nativeElement) {
this.formioElement.nativeElement.innerHTML = '';
}
this.formio = this.createRenderer();
this.formio.submission = this.submission;
if (this.renderOptions && this.renderOptions.validateOnInit) {
this.formio.setValue(this.submission, { validateOnInit: true });
}
if (this.url) {
this.formio.setUrl(this.url, this.formioOptions || {});
}
if (this.src) {
this.formio.setUrl(this.src, this.formioOptions || {});
}
this.formio.nosubmit = true;
this.formio.on('prevPage', (/**
* @param {?} data
* @return {?}
*/
function (data) { return _this.ngZone.run((/**
* @return {?}
*/
function () { return _this.onPrevPage(data); })); }));
this.formio.on('nextPage', (/**
* @param {?} data
* @return {?}
*/
function (data) { return _this.ngZone.run((/**
* @return {?}
*/
function () { return _this.onNextPage(data); })); }));
this.formio.on('change', (/**
* @param {?} value
* @param {?} flags
* @param {?} isModified
* @return {?}
*/
function (value, flags, isModified) { return _this.ngZone.run((/**
* @return {?}
*/
function () { return _this.onChange(value, flags, isModified); })); }));
this.formio.on('customEvent', (/**
* @param {?} event
* @return {?}
*/
function (event) {
return _this.ngZone.run((/**
* @return {?}
*/
function () { return _this.customEvent.emit(event); }));
}));
['fileUploadingStart', 'fileUploadingEnd'].forEach((/**
* @param {?} eventName
* @param {?} index
* @return {?}
*/
function (eventName, index) {
/** @type {?} */
var status = !!index ? 'end' : 'start';
_this.formio.on(eventName, (/**
* @return {?}
*/
function () {
return _this.ngZone.run((/**
* @return {?}
*/
function () { return _this.fileUploadingStatus.emit(status); }));
}));
}));
this.formio.on('submit', (/**
* @param {?} submission
* @param {?} saved
* @return {?}
*/
function (submission, saved) {
return _this.ngZone.run((/**
* @return {?}
*/
function () { return _this.submitForm(submission, saved); }));
}));
this.formio.on('error', (/**
* @param {?} err
* @return {?}
*/
function (err) { return _this.ngZone.run((/**
* @return {?}
*/
function () {
_this.submissionSuccess = false;
return _this.onError(err);
})); }));
this.formio.on('render', (/**
* @return {?}
*/
function () { return _this.ngZone.run((/**
* @return {?}
*/
function () { return _this.render.emit(); })); }));
this.formio.on('formLoad', (/**
* @param {?} loadedForm
* @return {?}
*/
function (loadedForm) {
return _this.ngZone.run((/**
* @return {?}
*/
function () { return _this.formLoad.emit(loadedForm); }));
}));
return this.formio.ready.then((/**
* @return {?}
*/
function () {
_this.ngZone.run((/**
* @return {?}
*/
function () {
_this.isLoading = false;
_this.ready.emit(_this);
_this.formioReadyResolve(_this.formio);
if (_this.formio.submissionReady) {
_this.formio.submissionReady.then((/**
* @param {?} submission
* @return {?}
*/
function (submission) {
_this.submissionLoad.emit(submission);
}));
}
}));
return _this.formio;
}));
};
/**
* @return {?}
*/
FormioBaseComponent.prototype.initialize = /**
* @return {?}
*/
function () {
if (this.initialized) {
return;
}
/** @type {?} */
var extraTags = this.customTags ? this.customTags.tags : [];
/** @type {?} */
var defaultOptions = {
errors: {
message: 'Please fix the following errors before submitting.'
},
alerts: {
submitMessage: 'Submission Complete.'
},
disableAlerts: false,
hooks: {
beforeSubmit: null
},
sanitizeConfig: {
addTags: extraTags
},
alertsPosition: AlertsPosition.top,
};
this.options = Object.assign(defaultOptions, this.options);
if (this.options.disableAlerts) {
this.options.alertsPosition = AlertsPosition.none;
}
this.initialized = true;
};
/**
* @return {?}
*/
FormioBaseComponent.prototype.ngOnInit = /**
* @return {?}
*/
function () {
var _this = this;
Evaluator__default['default'].noeval = this.noeval;
this.initialize();
if (this.language) {
if (typeof this.language === 'string') {
this.formio.language = this.language;
}
else {
this.language.subscribe((/**
* @param {?} lang
* @return {?}
*/
function (lang) {
_this.formio.language = lang;
}));
}
}
if (this.refresh) {
this.refresh.subscribe((/**
* @param {?} refresh
* @return {?}
*/
function (refresh) {
return _this.onRefresh(refresh);
}));
}
if (this.error) {
this.error.subscribe((/**
* @param {?} err
* @return {?}
*/
function (err) { return _this.onError(err); }));
}
if (this.success) {
this.success.subscribe((/**
* @param {?} message
* @return {?}
*/
function (message) {
_this.alerts.setAlert({
type: 'success',
message: message || lodash.get(_this.options, 'alerts.submitMessage')
});
}));
}
if (this.src) {
if (!this.service) {
this.service = new FormioService(this.src);
}
this.isLoading = true;
this.service.loadForm({ params: { live: 1 } }).subscribe((/**
* @param {?} form
* @return {?}
*/
function (form) {
if (form && form.components) {
_this.ngZone.runOutsideAngular((/**
* @return {?}
*/
function () {
_this.setForm(form);
}));
}
// if a submission is also provided.
if (lodash.isEmpty(_this.submission) &&
_this.service &&
_this.service.formio.submissionId) {
_this.service.loadSubmission().subscribe((/**
* @param {?} submission
* @return {?}
*/
function (submission) {
if (_this.readOnly) {
_this.formio.options.readOnly = true;
}
_this.submission = _this.formio.submission = submission;
}), (/**
* @param {?} err
* @return {?}
*/
function (err) { return _this.onError(err); }));
}
}), (/**
* @param {?} err
* @return {?}
*/
function (err) { return _this.onError(err); }));
}
if (this.url && !this.service) {
this.service = new FormioService(this.url);
}
};
/**
* @return {?}
*/
FormioBaseComponent.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
if (this.formio) {
this.formio.destroy();
}
};
/**
* @param {?} refresh
* @return {?}
*/
FormioBaseComponent.prototype.onRefresh = /**
* @param {?} refresh
* @return {?}
*/
function (refresh) {
var _this = this;
this.formioReady.then((/**
* @return {?}
*/
function () {
if (refresh.form) {
_this.formio.setForm(refresh.form).then((/**
* @return {?}
*/
function () {
if (refresh.submission) {
_this.formio.setSubmission(refresh.submission);
}
}));
}
else if (refresh.submission) {
_this.formio.setSubmission(refresh.submission);
}
else {
switch (refresh.property) {
case 'submission':
_this.formio.submission = refresh.value;
break;
case 'form':
_this.formio.form = refresh.value;
break;
}
}
}));
};
/**
* @param {?} changes
* @return {?}
*/
FormioBaseComponent.prototype.ngOnChanges = /**
* @param {?} changes
* @return {?}
*/
function (changes) {
var _this = this;
Evaluator__default['default'].noeval = this.noeval;
this.initialize();
if (changes.form && changes.form.currentValue) {
this.ngZone.runOutsideAngular((/**
* @return {?}
*/
function () {
_this.setForm(changes.form.currentValue);
}));
}
this.formioReady.then((/**
* @return {?}
*/
function () {
if (changes.submission && changes.submission.currentValue) {
_this.formio.setSubmission(changes.submission.currentValue, {
fromSubmission: false,
});
}
if (changes.hideComponents && changes.hideComponents.currentValue) {
/** @type {?} */
var hiddenComponents_1 = changes.hideComponents.currentValue;
_this.formio.options.hide = hiddenComponents_1;
_this.formio.everyComponent((/**
* @param {?} component
* @return {?}
*/
function (component) {
component.options.hide = hiddenComponents_1;
if (hiddenComponents_1.includes(component.component.key)) {
component.visible = false;
}
}));
}
}));
};
/**
* @param {?} data
* @return {?}
*/
FormioBaseComponent.prototype.onPrevPage = /**
* @param {?} data
* @return {?}
*/
function (data) {
this.alerts.setAlerts([]);
this.prevPage.emit(data);
};
/**
* @param {?} data
* @return {?}
*/
FormioBaseComponent.prototype.onNextPage = /**
* @param {?} data
* @return {?}
*/
function (data) {
this.alerts.setAlerts([]);
this.nextPage.emit(data);
};
/**
* @param {?} submission
* @param {?} saved
* @param {?=} noemit
* @return {?}
*/
FormioBaseComponent.prototype.onSubmit = /**
* @param {?} submission
* @param {?} saved
* @param {?=} noemit
* @return {?}
*/
function (submission, saved, noemit) {
this.submitting = false;
this.submissionSuccess = true;
if (saved) {
this.formio.emit('submitDone', submission);
}
if (!noemit) {
this.submit.emit(submission);
}
if (!this.success) {
this.alerts.setAlert({
type: 'success',
message: lodash.get(this.options, 'alerts.submitMessage')
});
}
};
/**
* @param {?} err
* @return {?}
*/
FormioBaseComponent.prototype.onError = /**
* @param {?} err
* @return {?}
*/
function (err) {
var _this = this;
this.alerts.setAlerts([]);
this.submitting = false;
this.isLoading = false;
if (!err) {
return;
}
// Make sure it is an array.
/** @type {?} */
var errors = Array.isArray(err) ? err : [err];
// Emit these errors again.
this.errorChange.emit(errors);
if (err.silent) {
return;
}
if (this.formio && errors.length) {
this.formio.emit('submitError', errors);
}
// Iterate through each one and set the alerts array.
errors.forEach((/**
* @param {?} error
* @return {?}
*/
function (error) {
var _a = error
? error.details
? {
message: error.details.map((/**
* @param {?} detail
* @return {?}
*/
function (detail) { return detail.message; })),
paths: error.details.map((/**
* @param {?} detail
* @return {?}
*/
function (detail) { return detail.path; })),
}
: {
message: error.message || error.toString(),
paths: error.path ? [error.path] : [],
}
: {
message: '',
paths: [],
}, message = _a.message, paths = _a.paths;
/** @type {?} */
var shouldErrorDisplay = true;
if (_this.formio) {
paths.forEach((/**
* @param {?} path
* @param {?} index
* @return {?}
*/
function (path, index) {
/** @type {?} */
var component = _this.formio.getComponent(path);
if (component) {
/** @type {?} */
var components = Array.isArray(component) ? component : [component];
/** @type {?} */
var messageText_1 = Array.isArray(message) ? message[index] : message;
components.forEach((/**
* @param {?} comp
* @return {?}
*/
function (comp) { return comp.setCustomValidity(messageText_1, true); }));
_this.alerts.addAlert({
type: 'danger',
message: message[index],
component: component,
});
shouldErrorDisplay = false;
}
}));
if (((/** @type {?} */ (window))).VPAT_ENABLED) {
if (typeof error === 'string' && _this.formio.components) {
_this.formio.components.forEach((/**
* @param {?} comp
* @return {?}
*/
function (comp) {
if (comp && comp.type !== 'button') {
comp.setCustomValidity(message, true);
}
}));
}
}
if (!_this.noAlerts) {
_this.formio.showErrors();
}
}
if (shouldErrorDisplay) {
_this.alerts.addAlert({
type: 'danger',
message: message,
component: error.component,
});
}
}));
};
/**
* @param {?} key
* @return {?}
*/
FormioBaseComponent.prototype.focusOnComponet = /**
* @param {?} key
* @return {?}
*/
function (key) {
if (this.formio) {
this.formio.focusOnComponent(key);
}
};
/**
* @param {?} submission
* @param {?=} saved
* @return {?}
*/
FormioBaseComponent.prototype.submitExecute = /**
* @param {?} submission
* @param {?=} saved
* @return {?}
*/
function (submission, saved) {
var _this = this;
if (saved === void 0) { saved = false; }
if (this.service && !this.url && !saved) {
this.service
.saveSubmission(submission)
.subscribe((/**
* @param {?} sub
* @return {?}
*/
function (sub) { return _this.onSubmit(sub, true); }), (/**
* @param {?} err
* @return {?}
*/
function (err) { return _this.onError(err); }));
}
else {
this.onSubmit(submission, false);
}
};
/**
* @param {?} submission
* @param {?=} saved
* @return {?}
*/
FormioBaseComponent.prototype.submitForm = /**
* @param {?} submission
* @param {?=} saved
* @return {?}
*/
function (submission, saved) {
var _this = this;
if (saved === void 0) { saved = false; }
// Keep double submits from occurring...
if (this.submitting) {
return;
}
this.submissionSuccess = false;
this.submitting = true;
this.beforeSubmit.emit(submission);
// if they provide a beforeSubmit hook, then allow them to alter the submission asynchronously
// or even provide a custom Error method.
/** @type {?} */
var beforeSubmit = lodash.get(this.options, 'hooks.beforeSubmit');
if (beforeSubmit) {
beforeSubmit(submission, (/**
* @param {?} err
* @param {?} sub
* @return {?}
*/
function (err, sub) {
if (err) {
_this.onError(err);