ng2-bootstrap
Version:
Native Angular Bootstrap Components
104 lines (103 loc) • 5.7 kB
JavaScript
;
var core_1 = require('@angular/core');
var forms_1 = require('@angular/forms');
var datepicker_inner_component_1 = require('./datepicker-inner.component');
var datepicker_config_1 = require('./datepicker.config');
exports.DATEPICKER_CONTROL_VALUE_ACCESSOR = {
provide: forms_1.NG_VALUE_ACCESSOR,
useExisting: core_1.forwardRef(function () { return DatePickerComponent; }),
multi: true
};
/* tslint:disable:component-selector-name component-selector-type */
/* tslint:enable:component-selector-name component-selector-type */
var DatePickerComponent = (function () {
function DatePickerComponent(config) {
/** sets datepicker mode, supports: `day`, `month`, `year` */
this.datepickerMode = 'day';
/** if false week numbers will be hidden */
this.showWeeks = true;
this.selectionDone = new core_1.EventEmitter(undefined);
this.onChange = Function.prototype;
this.onTouched = Function.prototype;
this._now = new Date();
this.config = config;
this.configureOptions();
}
Object.defineProperty(DatePickerComponent.prototype, "activeDate", {
/** currently active date */
get: function () {
return this._activeDate || this._now;
},
set: function (value) {
this._activeDate = value;
},
enumerable: true,
configurable: true
});
DatePickerComponent.prototype.configureOptions = function () {
Object.assign(this, this.config);
};
DatePickerComponent.prototype.onUpdate = function (event) {
this.onChange(event);
};
DatePickerComponent.prototype.onSelectionDone = function (event) {
this.selectionDone.emit(event);
};
// todo: support null value
DatePickerComponent.prototype.writeValue = function (value) {
if (this._datePicker.compare(value, this._activeDate) === 0) {
return;
}
if (value && value instanceof Date) {
this.activeDate = value;
this._datePicker.select(value, false);
return;
}
this.activeDate = value ? new Date(value) : void 0;
};
DatePickerComponent.prototype.registerOnChange = function (fn) {
this.onChange = fn;
};
DatePickerComponent.prototype.registerOnTouched = function (fn) {
this.onTouched = fn;
};
DatePickerComponent.decorators = [
{ type: core_1.Component, args: [{
selector: 'datepicker',
template: "\n <datepicker-inner [activeDate]=\"activeDate\"\n (update)=\"onUpdate($event)\"\n [datepickerMode]=\"datepickerMode\"\n [initDate]=\"initDate\"\n [minDate]=\"minDate\"\n [maxDate]=\"maxDate\"\n [minMode]=\"minMode\"\n [maxMode]=\"maxMode\"\n [showWeeks]=\"showWeeks\"\n [formatDay]=\"formatDay\"\n [formatMonth]=\"formatMonth\"\n [formatYear]=\"formatYear\"\n [formatDayHeader]=\"formatDayHeader\"\n [formatDayTitle]=\"formatDayTitle\"\n [formatMonthTitle]=\"formatMonthTitle\"\n [startingDay]=\"startingDay\"\n [yearRange]=\"yearRange\"\n [customClass]=\"customClass\"\n [dateDisabled]=\"dateDisabled\"\n [onlyCurrentMonth]=\"onlyCurrentMonth\"\n [shortcutPropagation]=\"shortcutPropagation\"\n [monthColLimit]=\"monthColLimit\"\n [yearColLimit]=\"yearColLimit\"\n (selectionDone)=\"onSelectionDone($event)\">\n <daypicker tabindex=\"0\"></daypicker>\n <monthpicker tabindex=\"0\"></monthpicker>\n <yearpicker tabindex=\"0\"></yearpicker>\n </datepicker-inner>\n ",
providers: [exports.DATEPICKER_CONTROL_VALUE_ACCESSOR]
},] },
];
/** @nocollapse */
DatePickerComponent.ctorParameters = function () { return [
{ type: datepicker_config_1.DatepickerConfig, },
]; };
DatePickerComponent.propDecorators = {
'datepickerMode': [{ type: core_1.Input },],
'initDate': [{ type: core_1.Input },],
'minDate': [{ type: core_1.Input },],
'maxDate': [{ type: core_1.Input },],
'minMode': [{ type: core_1.Input },],
'maxMode': [{ type: core_1.Input },],
'showWeeks': [{ type: core_1.Input },],
'formatDay': [{ type: core_1.Input },],
'formatMonth': [{ type: core_1.Input },],
'formatYear': [{ type: core_1.Input },],
'formatDayHeader': [{ type: core_1.Input },],
'formatDayTitle': [{ type: core_1.Input },],
'formatMonthTitle': [{ type: core_1.Input },],
'startingDay': [{ type: core_1.Input },],
'yearRange': [{ type: core_1.Input },],
'onlyCurrentMonth': [{ type: core_1.Input },],
'shortcutPropagation': [{ type: core_1.Input },],
'monthColLimit': [{ type: core_1.Input },],
'yearColLimit': [{ type: core_1.Input },],
'customClass': [{ type: core_1.Input },],
'dateDisabled': [{ type: core_1.Input },],
'activeDate': [{ type: core_1.Input },],
'selectionDone': [{ type: core_1.Output },],
'_datePicker': [{ type: core_1.ViewChild, args: [datepicker_inner_component_1.DatePickerInnerComponent,] },],
};
return DatePickerComponent;
}());
exports.DatePickerComponent = DatePickerComponent;