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,325 lines (1,311 loc) • 157 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('index', ['exports', '@angular/core', 'lodash', 'formiojs', '@angular/common', '@angular/router', 'rxjs', 'formiojs/utils/Evaluator'], factory) :
(global = 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';
Evaluator = Evaluator && Evaluator.hasOwnProperty('default') ? Evaluator['default'] : 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);
localStorage.removeItem('formioToken');
this.onError.emit();
};
/**
* @return {?}
*/
FormioAuthService.prototype.logout = /**
* @return {?}
*/
function () {
var _this = this;
this.setUser(null);
localStorage.removeItem('formioToken');
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: components/loader/formio.loader.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var FormioLoader = /** @class */ (function () {
function FormioLoader() {
this.loading$ = new rxjs.BehaviorSubject(true);
this.loading = true;
}
/**
* @param {?} loading
* @return {?}
*/
FormioLoader.prototype.setLoading = /**
* @param {?} loading
* @return {?}
*/
function (loading) {
this.loading = loading;
this.loading$.next(loading);
};
FormioLoader.decorators = [
{ type: core.Injectable },
];
return FormioLoader;
}());
/**
* @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
* @return {?}
*/
FormioService.prototype.saveForm = /**
* @param {?} form
* @return {?}
*/
function (form) {
var _this = this;
return this.requestWrapper((/**
* @return {?}
*/
function () { return _this.formio.saveForm(form); }));
};
/**
* @param {?=} options
* @return {?}
*/
FormioService.prototype.loadForm = /**
* @param {?=} options
* @return {?}
*/
function (options) {
var _this = this;
return this.requestWrapper((/**
* @return {?}
*/
function () { return _this.formio.loadForm(options); }));
};
/**
* @return {?}
*/
FormioService.prototype.loadSubmission = /**
* @return {?}
*/
function () {
var _this = this;
return this.requestWrapper((/**
* @return {?}
*/
function () { return _this.formio.loadSubmission(); }));
};
/**
* @param {?} submission
* @return {?}
*/
FormioService.prototype.saveSubmission = /**
* @param {?} submission
* @return {?}
*/
function (submission) {
var _this = this;
return this.requestWrapper((/**
* @return {?}
*/
function () { return _this.formio.saveSubmission(submission); }));
};
/**
* @return {?}
*/
FormioService.prototype.loadSubmissions = /**
* @return {?}
*/
function () {
var _this = this;
return this.requestWrapper((/**
* @return {?}
*/
function () { return _this.formio.loadSubmissions(); }));
};
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: FormioBaseComponent.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var FormioBaseComponent = /** @class */ (function () {
function FormioBaseComponent(ngZone, loader, config, customTags) {
var _this = this;
this.ngZone = ngZone;
this.loader = loader;
this.config = config;
this.customTags = customTags;
this.submission = {};
this.noeval = false;
this.readOnly = false;
this.viewOnly = false;
this.hooks = {};
this.render = new core.EventEmitter();
this.customEvent = 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.initialized = false;
this.alerts = new FormioAlerts();
this.submitting = false;
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();
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
* @return {?}
*/
function (value) { return _this.ngZone.run((/**
* @return {?}
*/
function () { return _this.change.emit(value); })); }));
this.formio.on('customEvent', (/**
* @param {?} event
* @return {?}
*/
function (event) {
return _this.ngZone.run((/**
* @return {?}
*/
function () { return _this.customEvent.emit(event); }));
}));
this.formio.on('submit', (/**
* @param {?} submission
* @return {?}
*/
function (submission) {
return _this.ngZone.run((/**
* @return {?}
*/
function () { return _this.submitForm(submission); }));
}));
this.formio.on('error', (/**
* @param {?} err
* @return {?}
*/
function (err) { return _this.ngZone.run((/**
* @return {?}
*/
function () { 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.loader.setLoading(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 : [];
this.options = Object.assign({
errors: {
message: 'Please fix the following errors before submitting.'
},
alerts: {
submitMessage: 'Submission Complete.'
},
disableAlerts: false,
hooks: {
beforeSubmit: null
},
sanitizeConfig: {
addTags: extraTags
}
}, this.options);
this.initialized = true;
};
/**
* @return {?}
*/
FormioBaseComponent.prototype.ngOnInit = /**
* @return {?}
*/
function () {
var _this = this;
Evaluator.noeval = this.noeval;
this.initialize();
if (this.language) {
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.loader.setLoading(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.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.submission = changes.submission.currentValue;
}
if (changes.hideComponents && changes.hideComponents.currentValue) {
_this.formio.hideComponents(changes.hideComponents.currentValue);
}
}));
};
/**
* @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;
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.loader.setLoading(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) {
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; })).join(' '),
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;
_this.alerts.addAlert({
type: 'danger',
message: message,
});
if (_this.formio) {
paths.forEach((/**
* @param {?} path
* @return {?}
*/
function (path) {
/** @type {?} */
var component = _this.formio.getComponent(path);
/** @type {?} */
var components = Array.isArray(component) ? component : [component];
components.forEach((/**
* @param {?} comp
* @return {?}
*/
function (comp) { return comp.setCustomValidity(message, true); }));
}));
}
}));
};
/**
* @param {?} submission
* @return {?}
*/
FormioBaseComponent.prototype.submitExecute = /**
* @param {?} submission
* @return {?}
*/
function (submission) {
var _this = this;
if (this.service && !this.url) {
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
* @return {?}
*/
FormioBaseComponent.prototype.submitForm = /**
* @param {?} submission
* @return {?}
*/
function (submission) {
var _this = this;
// Keep double submits from occurring...
if (this.submitting) {
return;
}
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);
return;
}
_this.submitExecute(sub);
}));
}
else {
this.submitExecute(submission);
}
};
/** @nocollapse */
FormioBaseComponent.ctorParameters = function () { return [
{ type: core.NgZone },
{ type: FormioLoader },
{ type: FormioAppConfig, decorators: [{ type: core.Optional }] },
{ type: CustomTagsService, decorators: [{ type: core.Optional }] }
]; };
FormioBaseComponent.propDecorators = {
form: [{ type: core.Input }],
submission: [{ type: core.Input }],
src: [{ type: core.Input }],
url: [{ type: core.Input }],
service: [{ type: core.Input }],
options: [{ type: core.Input }],
noeval: [{ type: core.Input }],
formioOptions: [{ type: core.Input }],
renderOptions: [{ type: core.Input }],
readOnly: [{ type: core.Input }],
viewOnly: [{ type: core.Input }],
hideComponents: [{ type: core.Input }],
refresh: [{ type: core.Input }],
error: [{ type: core.Input }],
success: [{ type: core.Input }],
language: [{ type: core.Input }],
hooks: [{ type: core.Input }],
renderer: [{ type: core.Input }],
render: [{ type: core.Output }],
customEvent: [{ type: core.Output }],
submit: [{ type: core.Output }],
prevPage: [{ type: core.Output }],
nextPage: [{ type: core.Output }],
beforeSubmit: [{ type: core.Output }],
change: [{ type: core.Output }],
invalid: [{ type: core.Output }],
errorChange: [{ type: core.Output }],
formLoad: [{ type: core.Output }],
submissionLoad: [{ type: core.Output }],
ready: [{ type: core.Output }],
formioElement: [{ type: core.ViewChild, args: ['formio', { static: true },] }]
};
return FormioBaseComponent;
}());
var __extends = (undefined && undefined.__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 __());
};
})();
/* tslint:disable */
var FormioComponent = /** @class */ (function (_super) {
__extends(FormioComponent, _super);
function FormioComponent(ngZone, loader, config, customTags) {
var _this = _super.call(this, ngZone, loader, config, customTags) || this;
_this.ngZone = ngZone;
_this.loader = loader;
_this.config = config;
_this.customTags = customTags;
if (_this.config) {
formiojs.Formio.setBaseUrl(_this.config.apiUrl);
formiojs.Formio.setProjectUrl(_this.config.appUrl);
}
else {
console.warn('You must provide an AppConfig within your application!');
}
return _this;
}
/**
* @return {?}
*/
FormioComponent.prototype.getRenderer = /**
* @return {?}
*/
function () {
return this.renderer || formiojs.Form;
};
FormioComponent.decorators = [
{ type: core.Component, args: [{
selector: 'formio',
template: "<div> <div *ngIf=\"loader.loading$ | async\" style=\"position:relative;height:200px\"> <formio-loader></formio-loader> </div> <formio-alerts *ngIf=\"!this.options?.disableAlerts\" [alerts]=\"alerts\"></formio-alerts> <div #formio></div> </div> ",
styles: ["@charset \"UTF-8\";.flatpickr-calendar{background:0 0;opacity:0;display:none;text-align:center;visibility:hidden;padding:0;-webkit-animation:none;animation:none;direction:ltr;border:0;font-size:14px;line-height:24px;border-radius:5px;position:absolute;width:307.875px;-webkit-box-sizing:border-box;box-sizing:border-box;-ms-touch-action:manipulation;touch-action:manipulation;background:#fff;-webkit-box-shadow:1px 0 0 #e6e6e6,-1px 0 0 #e6e6e6,0 1px 0 #e6e6e6,0 -1px 0 #e6e6e6,0 3px 13px rgba(0,0,0,.08);box-shadow:1px 0 0 #e6e6e6,-1px 0 0 #e6e6e6,0 1px 0 #e6e6e6,0 -1px 0 #e6e6e6,0 3px 13px rgba(0,0,0,.08)}.flatpickr-calendar.inline,.flatpickr-calendar.open{opacity:1;max-height:640px;visibility:visible}.flatpickr-calendar.open{display:inline-block;z-index:99999}.flatpickr-calendar.animate.open{-webkit-animation:fpFadeInDown .3s cubic-bezier(.23,1,.32,1);animation:fpFadeInDown .3s cubic-bezier(.23,1,.32,1)}.flatpickr-calendar.inline{display:block;position:relative;top:2px}.flatpickr-calendar.static{position:absolute;top:calc(100% + 2px)}.flatpickr-calendar.static.open{z-index:999;display:block}.flatpickr-calendar.multiMonth .flatpickr-days .dayContainer:nth-child(n+1) .flatpickr-day.inRange:nth-child(7n+7){-webkit-box-shadow:none!important;box-shadow:none!important}.flatpickr-calendar.multiMonth .flatpickr-days .dayContainer:nth-child(n+2) .flatpickr-day.inRange:nth-child(7n+1){-webkit-box-shadow:-2px 0 0 #e6e6e6,5px 0 0 #e6e6e6;box-shadow:-2px 0 0 #e6e6e6,5px 0 0 #e6e6e6}.flatpickr-calendar .hasTime .dayContainer,.flatpickr-calendar .hasWeeks .dayContainer{border-bottom:0;border-bottom-right-radius:0;border-bottom-left-radius:0}.flatpickr-calendar .hasWeeks .dayContainer{border-left:0}.flatpickr-calendar.showTimeInput.hasTime .flatpickr-time{height:40px;border-top:1px solid #e6e6e6}.flatpickr-calendar.noCalendar.hasTime .flatpickr-time{height:auto}.flatpickr-calendar:after,.flatpickr-calendar:before{position:absolute;display:block;pointer-events:none;border:solid transparent;content:'';height:0;width:0;left:22px}.flatpickr-calendar.rightMost:after,.flatpickr-calendar.rightMost:before{left:auto;right:22px}.flatpickr-calendar:before{border-width:5px;margin:0 -5px}.flatpickr-calendar:after{border-width:4px;margin:0 -4px}.flatpickr-calendar.arrowTop:after,.flatpickr-calendar.arrowTop:before{bottom:100%}.flatpickr-calendar.arrowTop:before{border-bottom-color:#e6e6e6}.flatpickr-calendar.arrowTop:after{border-bottom-color:#fff}.flatpickr-calendar.arrowBottom:after,.flatpickr-calendar.arrowBottom:before{top:100%}.flatpickr-calendar.arrowBottom:before{border-top-color:#e6e6e6}.flatpickr-calendar.arrowBottom:after{border-top-color:#fff}.flatpickr-calendar:focus{outline:0}.flatpickr-wrapper{position:relative;display:inline-block}.flatpickr-months{di