UNPKG

4.15 kBJavaScriptView Raw
1import { Component } from '@angular/core';
2import { isBs3 } from '../utils/ng2-bootstrap-config';
3import { DatePickerInnerComponent } from './datepicker-inner.component';
4export var YearPickerComponent = (function () {
5 function YearPickerComponent(datePicker) {
6 this.rows = [];
7 this.datePicker = datePicker;
8 }
9 Object.defineProperty(YearPickerComponent.prototype, "isBs4", {
10 get: function () {
11 return !isBs3();
12 },
13 enumerable: true,
14 configurable: true
15 });
16 YearPickerComponent.prototype.ngOnInit = function () {
17 var self = this;
18 this.datePicker.stepYear = { years: this.datePicker.yearRange };
19 this.datePicker.setRefreshViewHandler(function () {
20 var years = new Array(this.yearRange);
21 var date;
22 var start = self.getStartingYear(this.activeDate.getFullYear());
23 for (var i = 0; i < this.yearRange; i++) {
24 date = new Date(start + i, 0, 1);
25 date = this.fixTimeZone(date);
26 years[i] = this.createDateObject(date, this.formatYear);
27 years[i].uid = this.uniqueId + '-' + i;
28 }
29 self.title = [years[0].label,
30 years[this.yearRange - 1].label].join(' - ');
31 self.rows = this.split(years, self.datePicker.yearColLimit);
32 }, 'year');
33 this.datePicker.setCompareHandler(function (date1, date2) {
34 return date1.getFullYear() - date2.getFullYear();
35 }, 'year');
36 this.datePicker.refreshView();
37 };
38 YearPickerComponent.prototype.getStartingYear = function (year) {
39 // todo: parseInt
40 return ((year - 1) / this.datePicker.yearRange) * this.datePicker.yearRange + 1;
41 };
42 YearPickerComponent.decorators = [
43 { type: Component, args: [{
44 selector: 'yearpicker',
45 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\"\n (click)=\"datePicker.move(-1)\" tabindex=\"-1\">\n <i class=\"glyphicon glyphicon-chevron-left\"></i>\n </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()\"\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\"\n (click)=\"datePicker.move(1)\" tabindex=\"-1\">\n <i class=\"glyphicon glyphicon-chevron-right\"></i>\n </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\">\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 "
46 },] },
47 ];
48 /** @nocollapse */
49 YearPickerComponent.ctorParameters = function () { return [
50 { type: DatePickerInnerComponent, },
51 ]; };
52 return YearPickerComponent;
53}());
54//# sourceMappingURL=yearpicker.component.js.map
\No newline at end of file