UNPKG

angular2-json-schema-form

Version:
107 lines 5.51 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 MaterialTabsComponent = (function () { function MaterialTabsComponent(jsf) { this.jsf = jsf; this.selectedItem = 0; this.showAddTab = true; } MaterialTabsComponent.prototype.ngOnInit = function () { this.options = this.layoutNode.options; this.itemCount = this.layoutNode.items.length - 1; this.updateControl(); }; MaterialTabsComponent.prototype.select = function (index) { if (this.layoutNode.items[index].type === '$ref') { this.itemCount = this.layoutNode.items.length; this.jsf.addItem({ layoutNode: this.layoutNode.items[index], layoutIndex: this.layoutIndex.concat(index), dataIndex: this.dataIndex.concat(index) }); this.updateControl(); } ; this.selectedItem = index; }; MaterialTabsComponent.prototype.updateControl = function () { var lastItem = this.layoutNode.items[this.layoutNode.items.length - 1]; if (lastItem.type === '$ref' && this.itemCount >= (lastItem.options.maxItems || 1000000)) { this.showAddTab = false; } }; MaterialTabsComponent.prototype.setTitle = function (item, index) { if (item === void 0) { item = null; } if (index === void 0) { index = null; } var text; var value; var values = this.jsf.getControlValue(this); if (this.layoutNode.type.slice(-5) === 'array' && item.type !== '$ref') { text = index_1.JsonPointer.getFirst([ [item, '/options/legend'], [item, '/options/title'], [item, '/title'], [this.layoutNode, '/options/title'], [this.layoutNode, '/options/legend'], [this.layoutNode, '/title'], ]); } else { text = index_1.JsonPointer.getFirst([ [item, '/title'], [item, '/options/title'], [item, '/options/legend'], [this.layoutNode, '/title'], [this.layoutNode, '/options/title'], [this.layoutNode, '/options/legend'] ]); if (item.type === '$ref') text = '+ ' + text; } if (!text) return text; if (this.layoutNode.type === 'tabarray' && Array.isArray(values)) { value = values[index]; } else { value = values; } return index_1.parseText(text, value, values, index); }; return MaterialTabsComponent; }()); __decorate([ core_1.Input(), __metadata("design:type", Object) ], MaterialTabsComponent.prototype, "layoutNode", void 0); __decorate([ core_1.Input(), __metadata("design:type", Array) ], MaterialTabsComponent.prototype, "layoutIndex", void 0); __decorate([ core_1.Input(), __metadata("design:type", Array) ], MaterialTabsComponent.prototype, "dataIndex", void 0); MaterialTabsComponent = __decorate([ core_1.Component({ moduleId: module.id, selector: 'material-tabs-widget', template: "\n <ul\n [class]=\"options?.labelHtmlClass\">\n <li *ngFor=\"let item of layoutNode?.items; let i = index; trackBy: item?.dataPointer\"\n [class]=\"options?.itemLabelHtmlClass + (selectedItem === i ?\n (' ' + options?.activeClass + ' ' + options?.style?.selected) :\n (' ' + options?.style?.unselected))\"\n role=\"presentation\"\n data-tabs>\n <a *ngIf=\"showAddTab || item.type !== '$ref'\"\n [innerHTML]=\"setTitle(item, i)\"\n (click)=\"select(i)\"></a>\n </li>\n </ul>\n\n <div *ngFor=\"let layoutItem of layoutNode?.items; let i = index; trackBy: layoutItem?.dataPointer\"\n [class]=\"options?.htmlClass\">\n\n <select-framework-widget *ngIf=\"selectedItem === i\"\n [class]=\"options?.fieldHtmlClass + ' ' + options?.activeClass + ' ' + options?.style?.selected\"\n [dataIndex]=\"layoutNode?.dataType === 'array' ? (dataIndex || []).concat(i) : dataIndex\"\n [layoutIndex]=\"(layoutIndex || []).concat(i)\"\n [layoutNode]=\"layoutItem\"></select-framework-widget>\n\n </div>", styles: ["a { cursor: pointer; }"], }), __metadata("design:paramtypes", [json_schema_form_service_1.JsonSchemaFormService]) ], MaterialTabsComponent); exports.MaterialTabsComponent = MaterialTabsComponent; //# sourceMappingURL=material-tabs.component.js.map