UNPKG

angular2-json-schema-form

Version:
79 lines 6.21 kB
"use strict"; var __decorate = (this && this.__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 = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var core_1 = require("@angular/core"); var json_schema_form_service_1 = require("../../library/json-schema-form.service"); var index_1 = require("../../library/utilities/index"); var MaterialCheckboxesComponent = (function () { function MaterialCheckboxesComponent(jsf) { this.jsf = jsf; this.boundControl = false; this.layoutOrientation = 'vertical'; this.checkboxList = []; } MaterialCheckboxesComponent.prototype.ngOnInit = function () { this.options = this.layoutNode.options; if (this.layoutNode.type === 'checkboxes-inline' || this.layoutNode.type === 'checkboxbuttons') { this.layoutOrientation = 'horizontal'; } this.jsf.initializeControl(this); this.checkboxList = index_1.buildTitleMap(this.options.titleMap || this.options.enumNames, this.options.enum, true); if (this.boundControl) { this.formArray = this.jsf.getControl(this); for (var _i = 0, _a = this.checkboxList; _i < _a.length; _i++) { var checkboxItem = _a[_i]; checkboxItem.checked = this.formArray.value.length ? this.formArray.value.indexOf(checkboxItem.value) !== -1 : false; } } }; MaterialCheckboxesComponent.prototype.updateValue = function (event) { if (this.boundControl) { while (this.formArray.value.length) this.formArray.removeAt(0); for (var _i = 0, _a = this.checkboxList; _i < _a.length; _i++) { var checkboxItem = _a[_i]; if (event.target.value === checkboxItem.value) { checkboxItem.checked = event.target.checked; } if (checkboxItem.checked) { var newFormControl = index_1.buildFormGroup(index_1.JsonPointer.get(this.jsf.templateRefLibrary, [this.layoutNode.dataPointer + '/-'])); newFormControl.setValue(checkboxItem.value); this.formArray.push(newFormControl); } } } this.formArray.markAsDirty(); }; return MaterialCheckboxesComponent; }()); __decorate([ core_1.Input(), __metadata("design:type", Object) ], MaterialCheckboxesComponent.prototype, "layoutNode", void 0); __decorate([ core_1.Input(), __metadata("design:type", Array) ], MaterialCheckboxesComponent.prototype, "layoutIndex", void 0); __decorate([ core_1.Input(), __metadata("design:type", Array) ], MaterialCheckboxesComponent.prototype, "dataIndex", void 0); MaterialCheckboxesComponent = __decorate([ core_1.Component({ moduleId: module.id, selector: 'material-checkboxes-widget', template: "\n <label *ngIf=\"options?.title\"\n [class]=\"options?.labelHtmlClass\"\n [class.sr-only]=\"options?.notitle\"\n [innerHTML]=\"options?.title\"></label>\n <div [ngSwitch]=\"layoutOrientation\">\n\n <!-- 'horizontal' = checkboxes-inline or checkboxbuttons -->\n <div *ngSwitchCase=\"'horizontal'\"\n [class]=\"options?.htmlClass\">\n <label *ngFor=\"let checkboxItem of checkboxList\"\n [attr.for]=\"'control' + layoutNode?._id + '/' + checkboxItem.value\"\n [class]=\"options?.itemLabelHtmlClass + (checkboxItem.checked ?\n (' ' + options?.activeClass + ' ' + options?.style?.selected) :\n (' ' + options?.style?.unselected))\">\n <input type=\"checkbox\"\n [attr.required]=\"options?.required\"\n [checked]=\"checkboxItem.checked\"\n [class]=\"options?.fieldHtmlClass\"\n [disabled]=\"controlDisabled\"\n [id]=\"'control' + layoutNode?._id + '/' + checkboxItem.value\"\n [name]=\"formControlName\"\n [readonly]=\"options?.readonly ? 'readonly' : null\"\n [value]=\"checkboxItem.value\"\n (change)=\"updateValue($event)\">\n <span [innerHTML]=\"checkboxItem.name\"></span>\n </label>\n </div>\n\n <!-- 'vertical' = regular checkboxes -->\n <div *ngSwitchDefault>\n <div *ngFor=\"let checkboxItem of checkboxList\"\n [class]=\"options?.htmlClass\">\n <label\n [attr.for]=\"'control' + layoutNode?._id + '/' + checkboxItem.value\"\n [class]=\"options?.itemLabelHtmlClass + (checkboxItem.checked ?\n (' ' + options?.activeClass + ' ' + options?.style?.selected) :\n (' ' + options?.style?.unselected))\">\n <input type=\"checkbox\"\n [attr.required]=\"options?.required\"\n [checked]=\"checkboxItem.checked\"\n [class]=\"options?.fieldHtmlClass\"\n [disabled]=\"controlDisabled\"\n [id]=\"options?.name + '/' + checkboxItem.value\"\n [name]=\"options?.name\"\n [readonly]=\"options?.readonly ? 'readonly' : null\"\n [value]=\"checkboxItem.value\"\n (change)=\"updateValue($event)\">\n <span [innerHTML]=\"checkboxItem?.name\"></span>\n </label>\n </div>\n </div>\n\n </div>", }), __metadata("design:paramtypes", [json_schema_form_service_1.JsonSchemaFormService]) ], MaterialCheckboxesComponent); exports.MaterialCheckboxesComponent = MaterialCheckboxesComponent; //# sourceMappingURL=material-checkboxes.component.js.map