ng2-easyform
Version:
angular2 angular4 ng2
1,218 lines (1,186 loc) • 86.4 kB
JavaScript
import { Injectable, Directive, Input, Optional, Host, Inject, NgModule, Component, HostListener, ViewChild, ViewContainerRef, ComponentFactoryResolver, ElementRef } from '@angular/core';
import { FormBuilder, FormControl, FormGroup, Validators, FormGroupDirective, NgControl, ControlContainer, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { DateAdapter, MAT_DATE_LOCALE, MAT_DATE_FORMATS, MatDatepickerModule, MatInputModule, MatSelectModule, MatCheckboxModule, MatRadioModule, ErrorStateMatcher } from '@angular/material';
import * as _moment from 'moment';
import _moment__default, { unix } from 'moment';
import { CommonModule } from '@angular/common';
import { Observable } from 'rxjs';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Bootstrap3GridModule } from 'ng2-bootstrap3-grid';
var QueryOperate = /** @class */ (function () {
function QueryOperate(name, operate, advanced) {
this.advanced = false;
this.name = name;
this.advanced = advanced;
this.operate = operate;
}
QueryOperate.nomal = new QueryOperate("nomal", "nomal", false); //非高级查询
QueryOperate.eq = new QueryOperate("eq", "=", true); //= equal
QueryOperate.cn = new QueryOperate("cn", "LIKE", true); //LIKE '%data%'
return QueryOperate;
}());
var FieldBase = /** @class */ (function () {
function FieldBase(options) {
// debugger
this.value = options.value;
this.id = options.id;
this.selector = options.selector || this.controlType; //文本框等基础表单元素可以让 controlType 等于selector
this.key = options.key || '';
this.label = options.label || '';
this.span = options.span == null ? 6 : options.span;
this.required = !!options.required;
this.order = options.order == null ? 1 : options.order;
this.controlType = options.controlType || '';
this.validator = options.validator;
this.asyncValidator = options.asyncValidator;
this.labelOffset = options.labelOffset == null ? 75 : options.labelOffset;
this.labelSpan = options.labelSpan == null ? 3 : options.labelSpan;
this.isObject = options.isObject == null ? false : options.isObject;
this.disabled = options.disabled == null ? false : options.disabled;
this.hidden = options.hidden == null ? false : options.hidden;
this.statusChange = options.statusChange;
this.valueChange = options.valueChange;
this.op = options.op || QueryOperate.nomal;
this.params = options.params;
}
return FieldBase;
}());
var __extends = (undefined && undefined.__extends) || (function () {
var 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 function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var FieldGroup = /** @class */ (function (_super) {
__extends(FieldGroup, _super);
function FieldGroup(options) {
var _this = _super.call(this, options) || this;
_this.controlType = "group";
_this.groupName = options.groupName;
_this.fields = options.fields || [];
return _this;
}
return FieldGroup;
}(FieldBase));
var FieldArray = /** @class */ (function () {
function FieldArray(options) {
this.arrayName = options.arrayName;
this.groups = options.groups || [];
}
return FieldArray;
}());
var __decorate = (undefined && undefined.__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 = (undefined && undefined.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var FieldControlService = /** @class */ (function () {
function FieldControlService(fb) {
this.fb = fb;
}
FieldControlService.prototype.toFormGroup = function (fields) {
var _this = this;
var group = {};
fields.forEach(function (field) {
if (field instanceof FieldArray) {
var arraygroups = new Array();
for (var fieldGroup in field.groups) {
var fieldGroupArray = [fieldGroup];
arraygroups.push(_this.toFormGroup(fieldGroupArray));
}
group[field.arrayName] = _this.fb.array(arraygroups);
}
else if (field instanceof FieldGroup) {
group[field.key] = _this.toFormGroup(field.fields);
}
else if (field instanceof FieldBase) {
var validators = [];
var asyncValidators = [];
if (field.required) {
validators.push(Validators.required);
}
if (field.validator) {
validators.push(field.validator);
}
if (field.asyncValidator) {
asyncValidators.push(field.asyncValidator);
}
if (validators.length > 0 && asyncValidators.length > 0) {
group[field.key] = new FormControl({ value: field.value, disabled: field.disabled } || '', validators, asyncValidators);
}
else if (validators.length > 0) {
group[field.key] = new FormControl({ value: field.value, disabled: field.disabled } || '', validators);
}
else if (asyncValidators.length > 0) {
group[field.key] = new FormControl({ value: field.value, disabled: field.disabled } || '', null, asyncValidators);
}
else {
group[field.key] = new FormControl({ value: field.value, disabled: field.disabled } || '');
}
}
});
return new FormGroup(group);
};
FieldControlService = __decorate([
Injectable(),
__metadata("design:paramtypes", [FormBuilder])
], FieldControlService);
return FieldControlService;
}());
var __extends$1 = (undefined && undefined.__extends) || (function () {
var 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 function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __decorate$1 = (undefined && undefined.__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 FormstatusWrap = /** @class */ (function (_super) {
__extends$1(FormstatusWrap, _super);
function FormstatusWrap() {
return _super !== null && _super.apply(this, arguments) || this;
}
FormstatusWrap = __decorate$1([
Directive({
selector: "999"
})
], FormstatusWrap);
return FormstatusWrap;
}(FormGroupDirective));
var __decorate$2 = (undefined && undefined.__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$1 = (undefined && undefined.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (undefined && undefined.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
var DisableControlDirective = /** @class */ (function () {
function DisableControlDirective(ngControl, controlContainer) {
this.ngControl = ngControl;
this.controlContainer = controlContainer;
// debugger
}
Object.defineProperty(DisableControlDirective.prototype, "disableControl", {
set: function (condition) {
var _this = this;
setTimeout(function () {
var action = condition ? 'disable' : 'enable';
if (_this.ngControl) {
_this.ngControl.control[action]();
}
if (_this.controlContainer) {
_this.controlContainer.control[action]();
}
});
},
enumerable: true,
configurable: true
});
__decorate$2([
Input(),
__metadata$1("design:type", Boolean),
__metadata$1("design:paramtypes", [Boolean])
], DisableControlDirective.prototype, "disableControl", null);
DisableControlDirective = __decorate$2([
Directive({
selector: '[disableControl]'
}),
__param(0, Optional()), __param(0, Host()), __param(1, Optional()), __param(1, Host()),
__metadata$1("design:paramtypes", [NgControl, ControlContainer])
], DisableControlDirective);
return DisableControlDirective;
}());
var __decorate$3 = (undefined && undefined.__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$2 = (undefined && undefined.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param$1 = (undefined && undefined.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
var RequiredControlDirective = /** @class */ (function () {
function RequiredControlDirective(ngControl, controlContainer) {
this.ngControl = ngControl;
this.controlContainer = controlContainer;
// debugger
}
Object.defineProperty(RequiredControlDirective.prototype, "requiredControl", {
set: function (condition) {
var _this = this;
setTimeout(function () {
var action = condition ? 'disable' : 'enable';
debugger;
if (_this.ngControl) {
_this.ngControl.control[action]();
}
if (_this.controlContainer) {
_this.controlContainer.control[action]();
}
});
},
enumerable: true,
configurable: true
});
__decorate$3([
Input(),
__metadata$2("design:type", Boolean),
__metadata$2("design:paramtypes", [Boolean])
], RequiredControlDirective.prototype, "requiredControl", null);
RequiredControlDirective = __decorate$3([
Directive({
selector: '[requiredControl]'
}),
__param$1(0, Optional()), __param$1(0, Host()), __param$1(1, Optional()), __param$1(1, Host()),
__metadata$2("design:paramtypes", [NgControl, ControlContainer])
], RequiredControlDirective);
return RequiredControlDirective;
}());
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
/* global Reflect, Promise */
var 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]; };
function __extends$2(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var /** @type {?} */ moment = _moment__default || _moment;
/**
* Creates an array and fills it with values.
* @template T
* @param {?} length
* @param {?} valueFunction
* @return {?}
*/
function range(length, valueFunction) {
var /** @type {?} */ valuesArray = Array(length);
for (var /** @type {?} */ i = 0; i < length; i++) {
valuesArray[i] = valueFunction(i);
}
return valuesArray;
}
/**
* Adapts Moment.js Dates for use with Angular Material.
*/
var MomentDateAdapter = /** @class */ (function (_super) {
__extends$2(MomentDateAdapter, _super);
function MomentDateAdapter(dateLocale) {
var _this = _super.call(this) || this;
_this.setLocale(dateLocale || moment.locale());
return _this;
}
/**
* @param {?} locale
* @return {?}
*/
MomentDateAdapter.prototype.setLocale = /**
* @param {?} locale
* @return {?}
*/
function (locale) {
var _this = this;
_super.prototype.setLocale.call(this, locale);
var /** @type {?} */ momentLocaleData = moment.localeData(locale);
this._localeData = {
firstDayOfWeek: momentLocaleData.firstDayOfWeek(),
longMonths: momentLocaleData.months(),
shortMonths: momentLocaleData.monthsShort(),
dates: range(31, function (i) { return _this.createDate(2017, 0, i + 1).format('D'); }),
longDaysOfWeek: momentLocaleData.weekdays(),
shortDaysOfWeek: momentLocaleData.weekdaysShort(),
narrowDaysOfWeek: momentLocaleData.weekdaysMin(),
};
};
/**
* @param {?} date
* @return {?}
*/
MomentDateAdapter.prototype.getYear = /**
* @param {?} date
* @return {?}
*/
function (date) {
return this.clone(date).year();
};
/**
* @param {?} date
* @return {?}
*/
MomentDateAdapter.prototype.getMonth = /**
* @param {?} date
* @return {?}
*/
function (date) {
return this.clone(date).month();
};
/**
* @param {?} date
* @return {?}
*/
MomentDateAdapter.prototype.getDate = /**
* @param {?} date
* @return {?}
*/
function (date) {
return this.clone(date).date();
};
/**
* @param {?} date
* @return {?}
*/
MomentDateAdapter.prototype.getDayOfWeek = /**
* @param {?} date
* @return {?}
*/
function (date) {
return this.clone(date).day();
};
/**
* @param {?} style
* @return {?}
*/
MomentDateAdapter.prototype.getMonthNames = /**
* @param {?} style
* @return {?}
*/
function (style) {
// Moment.js doesn't support narrow month names, so we just use short if narrow is requested.
return style == 'long' ? this._localeData.longMonths : this._localeData.shortMonths;
};
/**
* @return {?}
*/
MomentDateAdapter.prototype.getDateNames = /**
* @return {?}
*/
function () {
return this._localeData.dates;
};
/**
* @param {?} style
* @return {?}
*/
MomentDateAdapter.prototype.getDayOfWeekNames = /**
* @param {?} style
* @return {?}
*/
function (style) {
if (style == 'long') {
return this._localeData.longDaysOfWeek;
}
if (style == 'short') {
return this._localeData.shortDaysOfWeek;
}
return this._localeData.narrowDaysOfWeek;
};
/**
* @param {?} date
* @return {?}
*/
MomentDateAdapter.prototype.getYearName = /**
* @param {?} date
* @return {?}
*/
function (date) {
return this.clone(date).format('YYYY');
};
/**
* @return {?}
*/
MomentDateAdapter.prototype.getFirstDayOfWeek = /**
* @return {?}
*/
function () {
return this._localeData.firstDayOfWeek;
};
/**
* @param {?} date
* @return {?}
*/
MomentDateAdapter.prototype.getNumDaysInMonth = /**
* @param {?} date
* @return {?}
*/
function (date) {
return this.clone(date).daysInMonth();
};
/**
* @param {?} date
* @return {?}
*/
MomentDateAdapter.prototype.clone = /**
* @param {?} date
* @return {?}
*/
function (date) {
return date.clone().locale(this.locale);
};
/**
* @param {?} year
* @param {?} month
* @param {?} date
* @return {?}
*/
MomentDateAdapter.prototype.createDate = /**
* @param {?} year
* @param {?} month
* @param {?} date
* @return {?}
*/
function (year, month, date) {
// Moment.js will create an invalid date if any of the components are out of bounds, but we
// explicitly check each case so we can throw more descriptive errors.
if (month < 0 || month > 11) {
throw Error("Invalid month index \"" + month + "\". Month index has to be between 0 and 11.");
}
if (date < 1) {
throw Error("Invalid date \"" + date + "\". Date has to be greater than 0.");
}
var /** @type {?} */ result = moment({ year: year, month: month, date: date }).locale(this.locale);
// If the result isn't valid, the date must have been out of bounds for this month.
if (!result.isValid()) {
throw Error("Invalid date \"" + date + "\" for month with index \"" + month + "\".");
}
return result;
};
/**
* @return {?}
*/
MomentDateAdapter.prototype.today = /**
* @return {?}
*/
function () {
return moment().locale(this.locale);
};
/**
* @param {?} value
* @param {?} parseFormat
* @return {?}
*/
MomentDateAdapter.prototype.parse = /**
* @param {?} value
* @param {?} parseFormat
* @return {?}
*/
function (value, parseFormat) {
if (value && typeof value == 'string') {
return moment(value, parseFormat, this.locale);
}
return value ? moment(value).locale(this.locale) : null;
};
/**
* @param {?} date
* @param {?} displayFormat
* @return {?}
*/
MomentDateAdapter.prototype.format = /**
* @param {?} date
* @param {?} displayFormat
* @return {?}
*/
function (date, displayFormat) {
date = this.clone(date);
if (!this.isValid(date)) {
throw Error('MomentDateAdapter: Cannot format invalid date.');
}
return date.format(displayFormat);
};
/**
* @param {?} date
* @param {?} years
* @return {?}
*/
MomentDateAdapter.prototype.addCalendarYears = /**
* @param {?} date
* @param {?} years
* @return {?}
*/
function (date, years) {
return this.clone(date).add({ years: years });
};
/**
* @param {?} date
* @param {?} months
* @return {?}
*/
MomentDateAdapter.prototype.addCalendarMonths = /**
* @param {?} date
* @param {?} months
* @return {?}
*/
function (date, months) {
return this.clone(date).add({ months: months });
};
/**
* @param {?} date
* @param {?} days
* @return {?}
*/
MomentDateAdapter.prototype.addCalendarDays = /**
* @param {?} date
* @param {?} days
* @return {?}
*/
function (date, days) {
return this.clone(date).add({ days: days });
};
/**
* @param {?} date
* @return {?}
*/
MomentDateAdapter.prototype.toIso8601 = /**
* @param {?} date
* @return {?}
*/
function (date) {
return this.clone(date).format();
};
/**
* Returns the given value if given a valid Moment or null. Deserializes valid ISO 8601 strings
* (https://www.ietf.org/rfc/rfc3339.txt) and valid Date objects into valid Moments and empty
* string into null. Returns an invalid date for all other values.
*/
/**
* Returns the given value if given a valid Moment or null. Deserializes valid ISO 8601 strings
* (https://www.ietf.org/rfc/rfc3339.txt) and valid Date objects into valid Moments and empty
* string into null. Returns an invalid date for all other values.
* @param {?} value
* @return {?}
*/
MomentDateAdapter.prototype.deserialize = /**
* Returns the given value if given a valid Moment or null. Deserializes valid ISO 8601 strings
* (https://www.ietf.org/rfc/rfc3339.txt) and valid Date objects into valid Moments and empty
* string into null. Returns an invalid date for all other values.
* @param {?} value
* @return {?}
*/
function (value) {
var /** @type {?} */ date;
if (value instanceof Date) {
date = moment(value);
}
if (typeof value === 'string') {
if (!value) {
return null;
}
date = moment(value, moment.ISO_8601).locale(this.locale);
}
if (date && this.isValid(date)) {
return date;
}
return _super.prototype.deserialize.call(this, value);
};
/**
* @param {?} obj
* @return {?}
*/
MomentDateAdapter.prototype.isDateInstance = /**
* @param {?} obj
* @return {?}
*/
function (obj) {
return moment.isMoment(obj);
};
/**
* @param {?} date
* @return {?}
*/
MomentDateAdapter.prototype.isValid = /**
* @param {?} date
* @return {?}
*/
function (date) {
return this.clone(date).isValid();
};
/**
* @return {?}
*/
MomentDateAdapter.prototype.invalid = /**
* @return {?}
*/
function () {
return moment.invalid();
};
MomentDateAdapter.decorators = [
{ type: Injectable },
];
/** @nocollapse */
MomentDateAdapter.ctorParameters = function () { return [
{ type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [MAT_DATE_LOCALE,] },] },
]; };
return MomentDateAdapter;
}(DateAdapter));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var /** @type {?} */ MAT_MOMENT_DATE_FORMATS = {
parse: {
dateInput: 'l',
},
display: {
dateInput: 'l',
monthYearLabel: 'MMM YYYY',
dateA11yLabel: 'LL',
monthYearA11yLabel: 'MMMM YYYY',
},
};
var __extends$3 = (undefined && undefined.__extends) || (function () {
var 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 function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __decorate$5 = (undefined && undefined.__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;
};
// import {default as _rollupMoment, Moment} from 'moment';
// const moment = _rollupMoment || _moment;
var EfDateAdapter = /** @class */ (function (_super) {
__extends$3(EfDateAdapter, _super);
function EfDateAdapter() {
return _super !== null && _super.apply(this, arguments) || this;
}
EfDateAdapter.prototype.parse = function (value, parseFormat) {
return _super.prototype.parse.call(this, value, parseFormat);
};
EfDateAdapter.prototype.deserialize = function (value) {
if (value && typeof value == 'string'
&& (value.length == 13 || value.length == 10) && parseInt(value)) {
return unix(parseInt(value));
}
else if (value && typeof value == 'number') {
if (value / 1000000000 > 1000) {
return unix(value / 1000);
}
else {
return unix(value);
}
}
else {
return _super.prototype.deserialize.call(this, value);
}
};
EfDateAdapter = __decorate$5([
Injectable()
], EfDateAdapter);
return EfDateAdapter;
}(MomentDateAdapter));
var uilist = new Array();
var uimap = new Map();
var uimap1 = new Map();
function UIComponent(options) {
//
if (!options["name"]) {
var l = options.component.name.length;
// options["name"] = options.component.name.substr(0, l - 9)
options.name = options.component.name;
}
uilist.push(options);
uimap.set(options.selector, options.component);
uimap1.set(options.selector, options);
// console.log("uicomponent: selector", options.selector);
// console.log("uicomponent: component", options.component);
return function (_a) {
var Function = _a.constructor;
};
}
// import 'rxjs/add/operator/toPromise';
// import 'rxjs/add/operator/map';
// @Injectable()
var EfDictdataService = /** @class */ (function () {
function EfDictdataService(http) {
this.http = http;
}
EfDictdataService.prototype.handleError = function (error) {
console.error('An error occurred', error);
return Promise.reject(error.message || error);
};
return EfDictdataService;
}());
var __extends$4 = (undefined && undefined.__extends) || (function () {
var 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 function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var InputField = /** @class */ (function (_super) {
__extends$4(InputField, _super);
function InputField(options) {
var _this = _super.call(this, options) || this;
_this.minLength = options.minLength;
_this.maxLength = options.maxLength;
_this.pattern = options.pattern;
return _this;
}
return InputField;
}(FieldBase));
var __extends$5 = (undefined && undefined.__extends) || (function () {
var 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 function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var OptionsField = /** @class */ (function (_super) {
__extends$5(OptionsField, _super);
function OptionsField(options) {
var _this = _super.call(this, options) || this;
_this.options = [];
_this.options = options['options'] || [];
_this.optionsUrl = options['optionsUrl'] || undefined;
_this.optionsOb = options['optionsOb'] || undefined;
_this.dictName = options['dictName'] || undefined;
_this.optionId = options['optionId'] || "key";
_this.optionName = options['optionName'] || "value";
_this.multiple = options.multiple || false;
return _this;
}
return OptionsField;
}(FieldBase));
var __decorate$6 = (undefined && undefined.__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 EasyFormCoreModule = /** @class */ (function () {
function EasyFormCoreModule() {
}
EasyFormCoreModule_1 = EasyFormCoreModule;
EasyFormCoreModule.forRoot = function () {
return {
ngModule: EasyFormCoreModule_1,
providers: [
FieldControlService,
{ provide: DateAdapter, useClass: EfDateAdapter },
{ provide: MAT_DATE_FORMATS, useValue: MAT_MOMENT_DATE_FORMATS }
],
};
};
EasyFormCoreModule = EasyFormCoreModule_1 = __decorate$6([
NgModule({
imports: [
CommonModule,
],
exports: [
DisableControlDirective,
RequiredControlDirective,
],
declarations: [
//avoid aot fails,ugly
FormstatusWrap,
DisableControlDirective,
RequiredControlDirective,
],
providers: [
FieldControlService,
],
entryComponents: [],
})
], EasyFormCoreModule);
return EasyFormCoreModule;
var EasyFormCoreModule_1;
}());
var __extends$6 = (undefined && undefined.__extends) || (function () {
var 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 function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var MdDatepickerField = /** @class */ (function (_super) {
__extends$6(MdDatepickerField, _super);
function MdDatepickerField(options) {
var _this = _super.call(this, options) || this;
_this.selector = 'ef-md-datepicker';
return _this;
}
return MdDatepickerField;
}(FieldBase));
var __decorate$7 = (undefined && undefined.__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$4 = (undefined && undefined.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var MdDatepickerComponent = /** @class */ (function () {
function MdDatepickerComponent() {
this.span = 12;
this.touchUi = false;
}
MdDatepickerComponent_1 = MdDatepickerComponent;
MdDatepickerComponent.prototype.ngOnInit = function () {
this.formControl = this.form.get(this.field.key);
this.span = this.field.span == undefined ? 4 : this.field.span;
this.label = this.field.label;
this.eNfxFlex = "calc(" + (this.span / 12) * 100 + "% - 15px)";
// this.eNfxFlexXs = "calc(100% - 15px)"
this.eNfxFlexXs = "100%";
this.formControl.valueChanges.subscribe(function (value) {
// this
// debugger
});
};
MdDatepickerComponent.prototype.patchValueToView = function () {
// this.model = this.controll.value
};
MdDatepickerComponent.prototype.onResize = function (width) {
if (width < 720) {
this.touchUi = true;
}
else {
this.touchUi = false;
}
};
__decorate$7([
Input(),
__metadata$4("design:type", Object)
], MdDatepickerComponent.prototype, "field", void 0);
__decorate$7([
Input(),
__metadata$4("design:type", FormGroup)
], MdDatepickerComponent.prototype, "form", void 0);
__decorate$7([
HostListener('window:resize', ['$event.target.innerWidth']),
__metadata$4("design:type", Function),
__metadata$4("design:paramtypes", [Object]),
__metadata$4("design:returntype", void 0)
], MdDatepickerComponent.prototype, "onResize", null);
MdDatepickerComponent = MdDatepickerComponent_1 = __decorate$7([
UIComponent({
selector: 'ef-md-datepicker',
component: MdDatepickerComponent_1,
field: MdDatepickerField,
name: "日期选择"
}),
Component({
selector: 'ef-md-datepicker',
template: "\n <mat-form-field [bsCol.sm]=\"span\" [bsCol.xs]=\"12\">\n <input matInput [matDatepicker]=\"myDatepicker\" [placeholder]=\"label\" [formControl]=\"formControl\" [disableControl]=\"field.disabled\">\n <mat-datepicker-toggle matSuffix [for]=\"myDatepicker\"></mat-datepicker-toggle>\n <mat-datepicker [touchUi]=\"touchUi\" #myDatepicker></mat-datepicker> \n <mat-error *ngIf=\"formControl.hasError('matDatepickerParse');else elseBlock\">\n <strong>\u65F6\u95F4\u683C\u5F0F\u4E0D\u6B63\u786E</strong>\n </mat-error> \n <ng-template #elseBlock>\n <mat-error *ngIf=\"formControl.hasError('required')\">\n <strong>\u5FC5\u586B\u9879</strong>\n </mat-error> \n </ng-template>\n </mat-form-field>\n\n "
}),
__metadata$4("design:paramtypes", [])
], MdDatepickerComponent);
return MdDatepickerComponent;
var MdDatepickerComponent_1;
}());
var __extends$7 = (undefined && undefined.__extends) || (function () {
var 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 function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var MdTextinputField = /** @class */ (function (_super) {
__extends$7(MdTextinputField, _super);
function MdTextinputField(options) {
var _this = _super.call(this, options) || this;
_this.selector = 'ef-md-input';
_this.type = options.type || 'text';
return _this;
}
return MdTextinputField;
}(InputField));
var FormUtils = /** @class */ (function () {
function FormUtils() {
}
FormUtils.doFormFieldInputStatusChanges = function (field, status, errors, errorsKeys) {
if (errors == null) {
errorsKeys.length = 0;
return;
}
FormUtils.doErrors(errors, errorsKeys);
if (field.statusChange instanceof Function) {
field.statusChange(status);
}
};
FormUtils.doErrors = function (errors, errorsKeys) {
errorsKeys.length = 0;
for (var p in errors) {
if (p != "required") {
errorsKeys.push(p);
}
}
return errorsKeys;
};
return FormUtils;
}());
var __decorate$8 = (undefined && undefined.__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$5 = (undefined && undefined.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var MdInputComponent = /** @class */ (function () {
function MdInputComponent() {
this.span = 12;
this.errors = {};
this.errorsKeys = [];
}
MdInputComponent_1 = MdInputComponent;
MdInputComponent.prototype.ngOnInit = function () {
var _this = this;
this.fieldControl = this.form.get(this.field.key);
this.span = this.field.span == undefined ? 4 : this.field.span;
this.label = this.field.label;
// this.eNfxFlex = "calc(" + (this.span / 12) * 100 + "% - 15px)"
// this.eNfxFlexXs = "calc(100% - 15px)"
// this.eNfxFlexXs = "100%"
// debugger
this.fieldControl.statusChanges.subscribe(function (data) {
_this.errors = _this.fieldControl.errors;
FormUtils.doFormFieldInputStatusChanges(_this.field, data, _this.errors, _this.errorsKeys);
});
this.fieldControl.valueChanges.subscribe(function (data) {
// debugger
if (_this.field.valueChange instanceof Function) {
_this.field.valueChange(data);
}
});
};
MdInputComponent.prototype.ngAfterViewInit = function () {
};
MdInputComponent.prototype.ngOnChanges = function (changes) {
// debugger
this.fieldControl;
for (var propName in changes) {
var chng = changes[propName];
var cur = JSON.stringify(chng.currentValue);
var prev = JSON.stringify(chng.previousValue);
}
};
__decorate$8([
Input(),
__metadata$5("design:type", MdTextinputField)
], MdInputComponent.prototype, "field", void 0);
__decorate$8([
Input(),
__metadata$5("design:type", FormGroup)
], MdInputComponent.prototype, "form", void 0);
MdInputComponent = MdInputComponent_1 = __decorate$8([
UIComponent({
selector: 'ef-md-input',
component: MdInputComponent_1,
field: MdTextinputField,
name: "文本框"
}),
Component({
selector: 'ef-md-input',
template: "\n <mat-form-field\n [bsCol.sm]=\"span\"\n [bsCol.xs]=\"12\"\n [hideRequiredMarker]=\"false\"\n [hidden]=\"this.field.hidden\">\n <input matInput \n [type]=\"field.type || field.params.inputType \" \n [placeholder]=\"label\" \n [formControl]=\"fieldControl\"\n [disableControl]=\"field.disabled\"\n >\n <mat-error *ngIf=\"fieldControl.hasError('required')\">\n <strong>\u5FC5\u586B\u9879</strong>\n </mat-error> \n <mat-error *ngFor=\"let key of this.errorsKeys\">\n <strong>{{this.errors[key]}}</strong>\n </mat-error> \n </mat-form-field> \n \n "
}),
__metadata$5("design:paramtypes", [])
], MdInputComponent);
return MdInputComponent;
var MdInputComponent_1;
}());
var __extends$8 = (undefined && undefined.__extends) || (function () {
var 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 function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var MdTextareaField = /** @class */ (function (_super) {
__extends$8(MdTextareaField, _super);
function MdTextareaField(options) {
var _this = _super.call(this, options) || this;
_this.selector = 'ef-md-textarea';
_this.type = 'textarea';
return _this;
}
return MdTextareaField;
}(InputField));
var __decorate$9 = (undefined && undefined.__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$6 = (undefined && undefined.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var MdTextareaComponent = /** @class */ (function () {
function MdTextareaComponent() {
this.span = 12;
this.errors = {};
this.errorsKeys = [];
}
MdTextareaComponent_1 = MdTextareaComponent;
MdTextareaComponent.prototype.ngOnInit = function () {
var _this = this;
this.fieldControl = this.form.get(this.field.key);
this.span = this.field.span == undefined ? 4 : this.field.span;
this.lable = this.field.label;
// this.eNfxFlex = "calc(" + (this.span / 12) * 100 + "% - 15px)"
// this.eNfxFlexXs = "calc(100% - 15px)"
// this.eNfxFlexXs = "100%"
// debugger
this.fieldControl.statusChanges.subscribe(function (data) {
_this.errors = _this.fieldControl.errors;
FormUtils.doFormFieldInputStatusChanges(_this.field, data, _this.errors, _this.errorsKeys);
});
};
__decorate$9([
Input(),
__metadata$6("design:type", Object)
], MdTextareaComponent.prototype, "field", void 0);
__decorate$9([
Input(),
__metadata$6("design:type", FormGroup)
], MdTextareaComponent.prototype, "form", void 0);
MdTextareaComponent = MdTextareaComponent_1 = __decorate$9([
UIComponent({
selector: 'ef-md-textarea',
component: MdTextareaComponent_1,
field: MdTextareaField,
name: "文本域"
}),
Component({
selector: 'ef-md-textarea',
template: "\n <mat-form-field [bsCol.sm]=\"span\" [bsCol.xs]=\"12\" [hidden]=\"this.field.hidden\">\n <textarea matInput [type]=\"field.type || field.params.inputType\" [placeholder]=\"lable\" [formControl]=\"fieldControl\"\n [disableControl]=\"field.disabled\">\n </textarea>\n <mat-error *ngIf=\"fieldControl.hasError('required')\">\n <strong>\u5FC5\u586B\u9879</strong>\n </mat-error> \n <mat-error *ngFor=\"let key of this.errorsKeys\">\n <strong>{{this.errors[key]}}</strong>\n </mat-error> \n </mat-form-field> \n \n "
}),
__metadata$6("design:paramtypes", [])
], MdTextareaComponent);
return MdTextareaComponent;
var MdTextareaComponent_1;
}());
var __extends$9 = (undefined && undefined.__extends) || (function () {
var 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 function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var MdCheckboxField = /** @class */ (function (_super) {
__extends$9(MdCheckboxField, _super);
function MdCheckboxField(options) {
var _this = _super.call(this, options) || this;
_this.selector = 'ef-md-checkbox';
return _this;
}
return MdCheckboxField;
}(FieldBase));
var __decorate$10 = (undefined && undefined.__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$7 = (undefined && undefined.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var MdCheckBoxComponent = /** @class */ (function () {
function MdCheckBoxComponent() {
this.span = 12;
this.checked = false;
this.indeterminate = false;
this.labelPosition = 'after';
}
MdCheckBoxComponent_1 = MdCheckBoxComponent;
MdCheckBoxComponent.prototype.ngOnInit = function () {
this.formControl = this.form.get(this.field.key);
this.span = this.field.span == undefined ? 4 : this.field.span;
this.label = this.field.label;
this.eNfxFlex = "calc(" + (this.span / 12) * 100 + "% - 15px)";
// this.eNfxFlexXs = "calc(100% - 15px)"
this.eNfxFlexXs = "100%";
};
__decorate$10([
Input(),
__metadata$7("design:type", Object)
], MdCheckBoxComponent.prototype, "field", void 0);
__decorate$10([
Input(),
__metadata$7("design:type", FormGroup)
], MdCheckBoxComponent.prototype, "form", void 0);
MdCheckBoxComponent = MdCheckBoxComponent_1 = __decorate$10([
UIComponent({
selector: 'ef-md-checkbox',
component: MdCheckBoxComponent_1,
field: MdCheckboxField,
name: "CheckBox"
}),
Component({
selector: 'ef-md-checkbox',
template: "\n <mat-checkbox\n class=\"example-margin\"\n [checked]=\"checked\"\n [indeterminate]=\"indeterminate\"\n [labelPosition]=\"labelPosition\"\n [formControl]=\"formControl\"\n [disableControl]=\"field.disabled\"\n [hidden]=\"this.field.hidden\"\n [bsCol.sm]=\"span\" [bsCol.xs]=\"12\"\n style=\"padding-top: 20px;padding-bottom: 15px; min-height: 65.5px;\">\n {{label}}\n </mat-checkbox> \n "
// min-height:66px
// [eNfxFlex]="eNfxFlex" [eNfxFlex.