UNPKG

@wjya/ngx-webapp-icpc.group.pms

Version:

angular webapp : icpc.group.pms

94 lines 6.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var data_source_helper_1 = require("../../../service/data-source.helper"); var core_1 = require("@angular/core"); var forms_1 = require("@angular/forms"); var MessageTemplateDialogComponent = /** @class */ (function () { function MessageTemplateDialogComponent(fb, dataSourceHelper) { this.fb = fb; this.dataSourceHelper = dataSourceHelper; this.modalIsVisible = false; this.controlArray = []; this.dataSource = this.dataSourceHelper.templateDataForms; this.weixinMessageTemplatesDataSource = this.dataSourceHelper.weixinMessageTemplates; this.validateForm = this.fb.group({ id: [null], code: [null, [forms_1.Validators.required]], title: [null, [forms_1.Validators.required]], url: [null, [forms_1.Validators.required]], }); } MessageTemplateDialogComponent.prototype.ngOnInit = function () { }; MessageTemplateDialogComponent.prototype.loadAll = function (id, templateIdShort) { var _this = this; this.templateIdShort = templateIdShort; this.validateForm = this.fb.group({ id: [null], code: [null, [forms_1.Validators.required]], title: [null, [forms_1.Validators.required]], url: [null, [forms_1.Validators.required]], }); this.dataSource.findOne(id).subscribe(function (res) { if (res.body) { _this.controlArray = res.body; res.body.map(function (val) { if (val.label.indexOf(':') !== -1) { val.label = val.label.replace(':', ''); } _this.validateForm.addControl(val.name, new forms_1.FormControl(null, forms_1.Validators.required)); }); _this.resetForm(); _this.modalIsVisible = true; } }); }; MessageTemplateDialogComponent.prototype.getFormControl = function (name) { return this.validateForm.controls[name]; }; MessageTemplateDialogComponent.prototype.resetForm = function () { this.validateForm.reset(); for (var _i = 0, _a = Object.keys(this.validateForm.controls); _i < _a.length; _i++) { var key = _a[_i]; this.validateForm.controls[key].markAsPristine(); } }; MessageTemplateDialogComponent.prototype.handleCancel = function () { this.modalIsVisible = false; }; MessageTemplateDialogComponent.prototype.onSave = function (val) { var _this = this; var obj = {}; this.controlArray.map(function (item) { for (var _i = 0, _a = Object.keys(val); _i < _a.length; _i++) { var key = _a[_i]; if (item.name === key) { obj[key] = val[key]; delete val[key]; } } }); obj = JSON.stringify(obj); val.templateIdShort = this.templateIdShort; val.content = obj; this.weixinMessageTemplatesDataSource.create(val).subscribe(function (success) { _this.modalIsVisible = false; }); }; MessageTemplateDialogComponent.decorators = [ { type: core_1.Component, args: [{ selector: 'zx-message-template-dialog', template: "<nz-modal [nzVisible]=\"modalIsVisible\" [nzWidth]=\"600\" [nzTitle]=\"modalTitle\" [nzContent]=\"modalContent\" [nzFooter]=\"modalFooter\" (nzOnCancel)=\"handleCancel()\"><ng-template #modalTitle><span>\u65B0\u5EFA\u6D88\u606F</span> <span>\u8BF7\u8F93\u5165\u6DFB\u52A0\u7684\u6D88\u606F\u4FE1\u606F</span></ng-template><ng-template #modalContent><form nz-form [formGroup]=\"validateForm\"><div nz-form-item nz-row class=\"hidden\"><div nz-form-label nz-col [nzSpan]=\"24\"><label>ID</label></div><div nz-col [nzSpan]=\"24\" nz-form-control><nz-input formControlName=\"id\" [nzPlaceHolder]=\"'ID'\" [nzSize]=\"'large'\"></nz-input></div></div><div nz-form-item nz-row><div nz-form-label nz-col [nzSpan]=\"4\"><label nz-form-item-required>\u7F16\u7801</label></div><div nz-col [nzSpan]=\"20\" nz-form-control nzHasFeedback><nz-input formControlName=\"code\" [nzPlaceHolder]=\"'\u8BF7\u8F93\u5165\u7F16\u7801'\" [nzSize]=\"'large'\"></nz-input></div></div><div nz-form-item nz-row><div nz-form-label nz-col [nzSpan]=\"4\"><label nz-form-item-required>\u6D88\u606F\u6807\u9898</label></div><div nz-col [nzSpan]=\"20\" nz-form-control nzHasFeedback><nz-input formControlName=\"title\" [nzPlaceHolder]=\"'\u8BF7\u8F93\u5165\u6D88\u606F\u6807\u9898'\" [nzSize]=\"'large'\"></nz-input></div></div><div nz-form-item nz-row><div nz-form-label nz-col [nzSpan]=\"4\"><label nz-form-item-required>\u8DF3\u8F6C\u8FDE\u63A5</label></div><div nz-col [nzSpan]=\"20\" nz-form-control><nz-input formControlName=\"url\" [nzPlaceHolder]=\"'\u8BF7\u8F93\u5165\u8DF3\u8F6C\u94FE\u63A5'\" [nzSize]=\"'large'\"></nz-input></div></div><div nz-form-item nz-row *ngFor=\"let item of controlArray\"><div nz-form-label nz-col [nzSpan]=\"4\"><label nz-form-item-required>{{item.label}}</label></div><div nz-col [nzSpan]=\"20\" nz-form-control><nz-input [formControlName]=\"item.name\" [nzPlaceHolder]=\"'\u8BF7\u8F93\u5165' + item.label\" [nzSize]=\"'large'\"></nz-input></div></div></form></ng-template><ng-template #modalFooter><button nz-button [nzType]=\"'default'\" [nzSize]=\"'large'\" (click)=\"handleCancel()\"><span>\u53D6 \u6D88</span></button> <button nz-button [nzType]=\"'primary'\" [nzSize]=\"'large'\" (click)=\"onSave(validateForm.value)\" [disabled]=\"!validateForm.valid\"><span>\u4FDD \u5B58</span></button></ng-template></nz-modal>", styles: [ "\n :host .hidden {\n display: none;\n }\n " ] },] }, ]; /** @nocollapse */ MessageTemplateDialogComponent.ctorParameters = function () { return [ { type: forms_1.FormBuilder, }, { type: data_source_helper_1.DataSourceHelper, }, ]; }; return MessageTemplateDialogComponent; }()); exports.MessageTemplateDialogComponent = MessageTemplateDialogComponent; //# sourceMappingURL=message-template-dialog.component.js.map