UNPKG

@angular-jz/jz

Version:

jim jz

115 lines 5.14 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); }; Object.defineProperty(exports, "__esModule", { value: true }); var core_1 = require("@angular/core"); var forms_1 = require("@angular/forms"); var JZCheckboxComponent = /** @class */ (function () { function JZCheckboxComponent() { this.text = ''; //@Input() public idField: string = 'id'; //@Input() public textField: string = 'text'; this._value = false; this.propagateChange = function (_) { }; this.click = new core_1.EventEmitter(); } JZCheckboxComponent_1 = JZCheckboxComponent; JZCheckboxComponent.prototype.ngOnInit = function () { var _this = this; var me = this; $(this.checkbox.nativeElement).on('ifChanged', function (e) { var newValue = $(me.checkbox.nativeElement).is(':checked'); //let idType:any = null; //if (me.items && me.items.length) { // idType = typeof (me.items[0][me.idField]); //} //var newValue = $(me.select.nativeElement).val(); //newValue = newValue.map((item: any) => { // if (idType == null) return item; // else if (idType == "number") return Number(item); // else if (idType == "string") return String(item); // else if (idType == "object") return item; //}); me._value = newValue; me.propagateChange(me.value); }).on('ifClicked', function (e) { _this.click.emit($(me.checkbox.nativeElement).is(':checked')); }); }; JZCheckboxComponent.prototype.ngOnDestroy = function () { $(this.checkbox.nativeElement).off('ifChanged').off('ifClicked'); }; JZCheckboxComponent.prototype.ngAfterViewInit = function () { $(this.checkbox.nativeElement).iCheck({ checkboxClass: 'icheckbox_square-green', radioClass: 'iradio_square-green', }); }; Object.defineProperty(JZCheckboxComponent.prototype, "value", { get: function () { //return $(this.checkbox.nativeElement).val(); return this._value; }, set: function (value) { if (this._value != value) { this._value = value; this.propagateChange(this.value); if (value) $(this.checkbox.nativeElement).iCheck('check'); else $(this.checkbox.nativeElement).iCheck('uncheck'); //$(this.select.nativeElement).val(this._value); //$(this.select.nativeElement).trigger('change'); } }, enumerable: true, configurable: true }); JZCheckboxComponent.prototype.writeValue = function (value) { this.value = value; }; JZCheckboxComponent.prototype.registerOnChange = function (fn) { this.propagateChange = fn; }; JZCheckboxComponent.prototype.registerOnTouched = function (fn) { }; __decorate([ core_1.ViewChild('checkbox'), __metadata("design:type", core_1.ElementRef) ], JZCheckboxComponent.prototype, "checkbox", void 0); __decorate([ core_1.Input(), __metadata("design:type", String) ], JZCheckboxComponent.prototype, "text", void 0); __decorate([ core_1.Input(), __metadata("design:type", Boolean) ], JZCheckboxComponent.prototype, "_value", void 0); __decorate([ core_1.Output(), __metadata("design:type", Object) ], JZCheckboxComponent.prototype, "click", void 0); JZCheckboxComponent = JZCheckboxComponent_1 = __decorate([ core_1.Component({ selector: 'jz-checkbox', templateUrl: './jz-checkbox.component.html', providers: [{ provide: forms_1.NG_VALUE_ACCESSOR, /* tslint:disable */ useExisting: core_1.forwardRef(function () { return JZCheckboxComponent_1; }), /* tslint:enable */ multi: true }], }) ], JZCheckboxComponent); return JZCheckboxComponent; var JZCheckboxComponent_1; }()); exports.JZCheckboxComponent = JZCheckboxComponent; //# sourceMappingURL=jz-checkbox.component.js.map