ngx-bootstrap
Version:
Native Angular Bootstrap Components
57 lines • 4.24 kB
JavaScript
import { Component } from '@angular/core';
import { isBs3 } from '../utils/theme-provider';
import { DatePickerInnerComponent } from './datepicker-inner.component';
var YearPickerComponent = /** @class */ (function () {
function YearPickerComponent(datePicker) {
this.rows = [];
this.datePicker = datePicker;
}
Object.defineProperty(YearPickerComponent.prototype, "isBs4", {
get: function () {
return !isBs3();
},
enumerable: true,
configurable: true
});
YearPickerComponent.prototype.ngOnInit = function () {
var self = this;
this.datePicker.stepYear = { years: this.datePicker.yearRange };
this.datePicker.setRefreshViewHandler(function () {
var years = new Array(this.yearRange);
var date;
var start = self.getStartingYear(this.activeDate.getFullYear());
for (var i = 0; i < this.yearRange; i++) {
date = new Date(start + i, 0, 1);
date = this.fixTimeZone(date);
years[i] = this.createDateObject(date, this.formatYear);
years[i].uid = this.uniqueId + '-' + i;
}
self.title = [years[0].label, years[this.yearRange - 1].label].join(' - ');
self.rows = this.split(years, self.datePicker.yearColLimit);
}, 'year');
this.datePicker.setCompareHandler(function (date1, date2) {
return date1.getFullYear() - date2.getFullYear();
}, 'year');
this.datePicker.refreshView();
};
YearPickerComponent.prototype.getStartingYear = function (year) {
// todo: parseInt
return ((year - 1) / this.datePicker.yearRange * this.datePicker.yearRange + 1);
};
YearPickerComponent.decorators = [
{ type: Component, args: [{
selector: 'yearpicker',
template: "\n<table *ngIf=\"datePicker.datepickerMode==='year'\" role=\"grid\">\n <thead>\n <tr>\n <th>\n <button type=\"button\" class=\"btn btn-default btn-sm pull-left float-left\"\n (click)=\"datePicker.move(-1)\" tabindex=\"-1\">\u2039</button>\n </th>\n <th [attr.colspan]=\"((datePicker.yearColLimit - 2) <= 0) ? 1 : datePicker.yearColLimit - 2\">\n <button [id]=\"datePicker.uniqueId + '-title'\" role=\"heading\"\n type=\"button\" class=\"btn btn-default btn-sm\"\n (click)=\"datePicker.toggleMode(0)\"\n [disabled]=\"datePicker.datepickerMode === datePicker.maxMode\"\n [ngClass]=\"{disabled: datePicker.datepickerMode === datePicker.maxMode}\" tabindex=\"-1\" style=\"width:100%;\">\n <strong>{{ title }}</strong>\n </button>\n </th>\n <th>\n <button type=\"button\" class=\"btn btn-default btn-sm pull-right float-right\"\n (click)=\"datePicker.move(1)\" tabindex=\"-1\">\u203A</button>\n </th>\n </tr>\n </thead>\n <tbody>\n <tr *ngFor=\"let rowz of rows\">\n <td *ngFor=\"let dtz of rowz\" class=\"text-center\" role=\"gridcell\" [attr.id]=\"dtz.uid\">\n <button type=\"button\" style=\"min-width:100%;\" class=\"btn btn-default\"\n [ngClass]=\"{'btn-link': isBs4 && !dtz.selected && !datePicker.isActive(dtz), 'btn-info': dtz.selected || (isBs4 && !dtz.selected && datePicker.isActive(dtz)), disabled: dtz.disabled, active: !isBs4 && datePicker.isActive(dtz)}\"\n [disabled]=\"dtz.disabled\"\n (click)=\"datePicker.select(dtz.date)\" tabindex=\"-1\">\n <span [ngClass]=\"{'text-success': isBs4 && dtz.current, 'text-info': !isBs4 && dtz.current}\">{{ dtz.label }}</span>\n </button>\n </td>\n </tr>\n </tbody>\n</table>\n ",
styles: [
"\n :host .btn-info .text-success {\n color: #fff !important;\n }\n "
]
},] },
];
/** @nocollapse */
YearPickerComponent.ctorParameters = function () { return [
{ type: DatePickerInnerComponent, },
]; };
return YearPickerComponent;
}());
export { YearPickerComponent };
//# sourceMappingURL=yearpicker.component.js.map