angular-formio-proyectoscolfuturo
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 tha
173 lines (172 loc) • 6.12 kB
JavaScript
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
import { Component, EventEmitter } from '@angular/core';
import { FormManagerConfig } from '../form-manager.config';
import { FormManagerService } from '../form-manager.service';
import { ActivatedRoute, Router } from '@angular/router';
import { FormioAuthService } from '../../auth/auth.service';
import _merge from 'lodash/merge';
import _throttle from 'lodash/throttle';
import _cloneDeep from 'lodash/cloneDeep';
import { Formio } from 'formiojs-proyectoscolfuturo';
var FormManagerViewComponent = /** @class */ (function () {
function FormManagerViewComponent(service, router, route, config, auth) {
this.service = service;
this.router = router;
this.route = route;
this.config = config;
this.auth = auth;
this.onSuccess = new EventEmitter();
this.onError = new EventEmitter();
this.currentForm = null;
this.draft = { data: {} };
this.submission = { data: {} };
this.savingDraft = true;
this.triggerSaveDraft = _throttle(this.saveDraft.bind(this), 5000);
}
/**
* @return {?}
*/
FormManagerViewComponent.prototype.ngOnInit = /**
* @return {?}
*/
function () {
var _this = this;
// Reset the formio service to this form only.
this.savingDraft = true;
this.service.formio = new Formio(this.service.formio.formUrl);
this.service.loadForm().then((/**
* @param {?} form
* @return {?}
*/
function (form) {
_this.currentForm = form;
if (_this.auth && _this.auth.userReady && _this.config.saveDraft) {
_this.auth.userReady.then((/**
* @param {?} user
* @return {?}
*/
function (user) {
_this.service.formio.loadSubmissions({ params: {
state: 'draft',
owner: user._id
} }).then((/**
* @param {?} submissions
* @return {?}
*/
function (submissions) {
if (submissions.length > 0) {
_this.draft = submissions[0];
_this.submission = _cloneDeep(_this.draft);
}
_this.savingDraft = false;
}));
}));
}
}));
};
/**
* @return {?}
*/
FormManagerViewComponent.prototype.saveDraft = /**
* @return {?}
*/
function () {
var _this = this;
this.draft.state = 'draft';
if (!this.savingDraft) {
this.savingDraft = true;
this.service.formio.saveSubmission(this.draft).then((/**
* @param {?} submission
* @return {?}
*/
function (submission) {
_this.draft = submission;
_this.savingDraft = false;
}));
}
};
/**
* @param {?} data
* @return {?}
*/
FormManagerViewComponent.prototype.onChange = /**
* @param {?} data
* @return {?}
*/
function (data) {
if (this.config.saveDraft) {
_merge(this.draft.data, data.data);
this.triggerSaveDraft();
}
};
/**
* @param {?} submission
* @return {?}
*/
FormManagerViewComponent.prototype.onSubmit = /**
* @param {?} submission
* @return {?}
*/
function (submission) {
var _this = this;
this.savingDraft = true;
this.submission.data = submission.data;
this.submission.state = 'complete';
this.service.formio.saveSubmission(this.submission).then((/**
* @param {?} saved
* @return {?}
*/
function (saved) {
_this.onSuccess.emit();
_this.router.navigate(['../', 'submission', saved._id], { relativeTo: _this.route });
})).catch((/**
* @param {?} err
* @return {?}
*/
function (err) { return _this.onError.emit(err); }));
};
FormManagerViewComponent.decorators = [
{ type: Component, args: [{
template: "<formio *ngIf=\"currentForm\" [renderer]=\"config.renderer\" [url]=\"service.formio.formUrl\" [form]=\"currentForm\" [submission]=\"submission\" [success]=\"onSuccess\" [error]=\"onError\" (submit)=\"onSubmit($event)\" (change)=\"onChange($event)\" ></formio> "
},] },
];
/** @nocollapse */
FormManagerViewComponent.ctorParameters = function () { return [
{ type: FormManagerService },
{ type: Router },
{ type: ActivatedRoute },
{ type: FormManagerConfig },
{ type: FormioAuthService }
]; };
return FormManagerViewComponent;
}());
export { FormManagerViewComponent };
if (false) {
/** @type {?} */
FormManagerViewComponent.prototype.draft;
/** @type {?} */
FormManagerViewComponent.prototype.submission;
/** @type {?} */
FormManagerViewComponent.prototype.savingDraft;
/** @type {?} */
FormManagerViewComponent.prototype.triggerSaveDraft;
/** @type {?} */
FormManagerViewComponent.prototype.currentForm;
/** @type {?} */
FormManagerViewComponent.prototype.onSuccess;
/** @type {?} */
FormManagerViewComponent.prototype.onError;
/** @type {?} */
FormManagerViewComponent.prototype.service;
/** @type {?} */
FormManagerViewComponent.prototype.router;
/** @type {?} */
FormManagerViewComponent.prototype.route;
/** @type {?} */
FormManagerViewComponent.prototype.config;
/** @type {?} */
FormManagerViewComponent.prototype.auth;
}