"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); }; Object.defineProperty(exports, "__esModule", { value: true }); var core_1 = require("@angular/core"); var common_1 = require("@angular/common"); var objectutils_1 = require("../utils/objectutils"); var forms_1 = require("@angular/forms"); exports.SELECTBUTTON_VALUE_ACCESSOR = { provide: forms_1.NG_VALUE_ACCESSOR, useExisting: core_1.forwardRef(function () { return SelectButton; }), multi: true }; var SelectButton = /** @class */ (function () { function SelectButton(cd) { this.cd = cd; this.tabindex = 0; this.onOptionClick = new core_1.EventEmitter(); this.onChange = new core_1.EventEmitter(); this.onModelChange = function () { }; this.onModelTouched = function () { }; } Object.defineProperty(SelectButton.prototype, "options", { get: function () { return this._options; }, set: function (val) { var opts = this.optionLabel ? objectutils_1.ObjectUtils.generateSelectItems(val, this.optionLabel) : val; this._options = opts; }, enumerable: true, configurable: true }); SelectButton.prototype.writeValue = function (value) { this.value = value; this.cd.markForCheck(); }; SelectButton.prototype.registerOnChange = function (fn) { this.onModelChange = fn; }; SelectButton.prototype.registerOnTouched = function (fn) { this.onModelTouched = fn; }; SelectButton.prototype.setDisabledState = function (val) { this.disabled = val; }; SelectButton.prototype.onItemClick = function (event, option, index) { if (this.disabled || option.disabled) { return; } if (this.multiple) { var itemIndex_1 = this.findItemIndex(option); if (itemIndex_1 != -1) this.value = this.value.filter(function (val, i) { return i != itemIndex_1; }); else this.value = (this.value || []).concat([option.value]); } else { this.value = option.value; } this.onOptionClick.emit({ originalEvent: event, option: option, index: index }); this.onModelChange(this.value); this.onChange.emit({ originalEvent: event, value: this.value }); }; SelectButton.prototype.onFocus = function (event) { this.focusedItem = event.target; }; SelectButton.prototype.onBlur = function (event) { this.focusedItem = null; this.onModelTouched(); }; SelectButton.prototype.isSelected = function (option) { if (this.multiple) return this.findItemIndex(option) != -1; else return objectutils_1.ObjectUtils.equals(option.value, this.value, this.dataKey); }; SelectButton.prototype.findItemIndex = function (option) { var index = -1; if (this.value) { for (var i = 0; i < this.value.length; i++) { if (this.value[i] == option.value) { index = i; break; } } } return index; }; __decorate([ core_1.Input(), __metadata("design:type", Number) ], SelectButton.prototype, "tabindex", void 0); __decorate([ core_1.Input(), __metadata("design:type", Boolean) ], SelectButton.prototype, "multiple", void 0); __decorate([ core_1.Input(), __metadata("design:type", Object) ], SelectButton.prototype, "style", void 0); __decorate([ core_1.Input(), __metadata("design:type", String) ], SelectButton.prototype, "styleClass", void 0); __decorate([ core_1.Input(), __metadata("design:type", Boolean) ], SelectButton.prototype, "disabled", void 0); __decorate([ core_1.Input(), __metadata("design:type", String) ], SelectButton.prototype, "dataKey", void 0); __decorate([ core_1.Input(), __metadata("design:type", String) ], SelectButton.prototype, "optionLabel", void 0); __decorate([ core_1.Output(), __metadata("design:type", core_1.EventEmitter) ], SelectButton.prototype, "onOptionClick", void 0); __decorate([ core_1.Output(), __metadata("design:type", core_1.EventEmitter) ], SelectButton.prototype, "onChange", void 0); __decorate([ core_1.ContentChild(core_1.TemplateRef), __metadata("design:type", Object) ], SelectButton.prototype, "itemTemplate", void 0); __decorate([ core_1.Input(), __metadata("design:type", Array), __metadata("design:paramtypes", [Array]) ], SelectButton.prototype, "options", null); SelectButton = __decorate([ core_1.Component({ selector: 'p-selectButton', template: "\n
\n
\n \n \n {{option.label||'ui-btn'}}\n \n \n \n \n
\n
\n ", providers: [exports.SELECTBUTTON_VALUE_ACCESSOR] }), __metadata("design:paramtypes", [core_1.ChangeDetectorRef]) ], SelectButton); return SelectButton; }()); exports.SelectButton = SelectButton; var SelectButtonModule = /** @class */ (function () { function SelectButtonModule() { } SelectButtonModule = __decorate([ core_1.NgModule({ imports: [common_1.CommonModule], exports: [SelectButton], declarations: [SelectButton] }) ], SelectButtonModule); return SelectButtonModule; }()); exports.SelectButtonModule = SelectButtonModule; //# sourceMappingURL=selectbutton.js.map