aurelia-materialize-bridge
Version:
Aurelia interface to http://materializecss.com/
218 lines • 9.24 kB
JavaScript
import * as tslib_1 from "tslib";
var MdDatePicker_1;
import * as au from "../aurelia";
let MdDatePicker = MdDatePicker_1 = class MdDatePicker {
constructor(element) {
this.element = element;
this.controlId = `md-datepicker-${MdDatePicker_1.id++}`;
this.label = "";
this.placeholder = "";
this.showErrortext = true;
this.calendarIcon = null;
this.done = (e) => {
// we're only interested in events generated by the widget
if (e.firedBy !== this.instance) {
return;
}
// stop propagation for widget triggered change to retrigger it later on an the element
e.stopPropagation();
if (this.suppressDone) {
this.suppressDone = false;
return;
}
this.setValue(this.instance.date);
au.fireEvent(this.element, "blur");
au.fireEvent(this.element, "change");
};
this.mdUnrenderValidateResults = (results, renderer) => {
for (let result of results) {
if (!result.valid) {
renderer.removeMessage(this.inputField, result);
}
}
renderer.removeValidationClasses(this.input);
};
this.mdRenderValidateResults = (results, renderer) => {
if (this.showErrortext && this.inputField) {
for (let result of results) {
if (!result.valid) {
renderer.addMessage(this.inputField, result);
}
}
}
renderer.addValidationClasses(this.input, !results.find(x => !x.valid));
};
}
valueChanged() {
if (this.valueChangedSuppress) {
this.valueChangedSuppress = false;
au.updateLabel(this.input, this.labelElement);
return;
}
if (!this.instance) {
return;
}
this.instance.setDate(this.value);
// suppress done handler because setInputValue will trigger it, change value and possibly cause an infinite loop when a date has time components
this.suppressDone = true;
this.instance.setInputValue();
au.updateLabel(this.input, this.labelElement);
}
setValue(newValue) {
if (this.value !== newValue) {
this.valueChangedSuppress = true;
this.value = newValue;
}
}
attached() {
if (this.placeholder) {
this.input.setAttribute("placeholder", this.placeholder);
}
let container = typeof this.container === "string" ? document.querySelector(this.container) : this.container;
let options = {
autoClose: this.autoClose,
format: this.format,
parse: this.parse,
defaultDate: this.defaultDate,
setDefaultDate: this.setDefaultDate,
disableWeekends: this.disableWeekends,
disableDayFn: this.disableDayFn,
firstDay: this.firstDay,
minDate: this.minDate,
maxDate: this.maxDate,
yearRange: this.yearRange,
isRTL: this.isRtl,
showMonthAfterYear: this.showMonthAfterYear,
showDaysInNextAndPreviousMonths: this.showDaysInNextAndPreviousMonths,
container,
showClearBtn: this.showClearBtn,
i18n: this.i18n,
events: this.events,
onSelect: selectedDate => au.fireMaterializeEvent(this.element, "select", { selectedDate }),
onOpen: () => au.fireMaterializeEvent(this.element, "open"),
onClose: () => au.fireMaterializeEvent(this.element, "close"),
onDraw: () => au.fireMaterializeEvent(this.element, "draw")
};
au.cleanOptions(options);
this.instance = new M.Datepicker(this.input, options);
this.instance.el.addEventListener("change", this.done);
this.element.mdUnrenderValidateResults = this.mdUnrenderValidateResults;
this.element.mdRenderValidateResults = this.mdRenderValidateResults;
this.valueChanged();
}
bind() {
//
}
detached() {
au.MaterializeFormValidationRenderer.removeValidation(this.inputField, this.input);
this.instance.destroy();
this.element.mdUnrenderValidateResults = undefined;
this.element.mdRenderValidateResults = undefined;
}
open() {
this.instance.open();
}
close() {
this.instance.close();
}
};
MdDatePicker.id = 0;
tslib_1.__decorate([
au.ato.bindable.stringMd,
tslib_1.__metadata("design:type", String)
], MdDatePicker.prototype, "label", void 0);
tslib_1.__decorate([
au.ato.bindable.booleanMd,
tslib_1.__metadata("design:type", Boolean)
], MdDatePicker.prototype, "inline", void 0);
tslib_1.__decorate([
au.ato.bindable.stringMd,
tslib_1.__metadata("design:type", String)
], MdDatePicker.prototype, "placeholder", void 0);
tslib_1.__decorate([
au.ato.bindable.booleanMd({ defaultBindingMode: au.bindingMode.oneTime }),
tslib_1.__metadata("design:type", Boolean)
], MdDatePicker.prototype, "autoClose", void 0);
tslib_1.__decorate([
au.ato.bindable.stringMd({ defaultBindingMode: au.bindingMode.oneTime }),
tslib_1.__metadata("design:type", String)
], MdDatePicker.prototype, "format", void 0);
tslib_1.__decorate([
au.bindable({ defaultBindingMode: au.bindingMode.oneTime }),
tslib_1.__metadata("design:type", Function)
], MdDatePicker.prototype, "parse", void 0);
tslib_1.__decorate([
au.bindable({ defaultBindingMode: au.bindingMode.oneTime }),
tslib_1.__metadata("design:type", Date)
], MdDatePicker.prototype, "defaultDate", void 0);
tslib_1.__decorate([
au.ato.bindable.booleanMd({ defaultBindingMode: au.bindingMode.oneTime }),
tslib_1.__metadata("design:type", Boolean)
], MdDatePicker.prototype, "setDefaultDate", void 0);
tslib_1.__decorate([
au.ato.bindable.booleanMd({ defaultBindingMode: au.bindingMode.oneTime }),
tslib_1.__metadata("design:type", Boolean)
], MdDatePicker.prototype, "disableWeekends", void 0);
tslib_1.__decorate([
au.bindable({ defaultBindingMode: au.bindingMode.oneTime }),
tslib_1.__metadata("design:type", Function)
], MdDatePicker.prototype, "disableDayFn", void 0);
tslib_1.__decorate([
au.ato.bindable.numberMd({ defaultBindingMode: au.bindingMode.oneTime }),
tslib_1.__metadata("design:type", Number)
], MdDatePicker.prototype, "firstDay", void 0);
tslib_1.__decorate([
au.bindable({ defaultBindingMode: au.bindingMode.oneTime }),
tslib_1.__metadata("design:type", Date)
], MdDatePicker.prototype, "minDate", void 0);
tslib_1.__decorate([
au.bindable({ defaultBindingMode: au.bindingMode.oneTime }),
tslib_1.__metadata("design:type", Date)
], MdDatePicker.prototype, "maxDate", void 0);
tslib_1.__decorate([
au.bindable({ defaultBindingMode: au.bindingMode.oneTime }),
tslib_1.__metadata("design:type", Object)
], MdDatePicker.prototype, "yearRange", void 0);
tslib_1.__decorate([
au.ato.bindable.booleanMd({ defaultBindingMode: au.bindingMode.oneTime }),
tslib_1.__metadata("design:type", Boolean)
], MdDatePicker.prototype, "isRtl", void 0);
tslib_1.__decorate([
au.ato.bindable.booleanMd({ defaultBindingMode: au.bindingMode.oneTime }),
tslib_1.__metadata("design:type", Boolean)
], MdDatePicker.prototype, "showMonthAfterYear", void 0);
tslib_1.__decorate([
au.ato.bindable.booleanMd({ defaultBindingMode: au.bindingMode.oneTime }),
tslib_1.__metadata("design:type", Boolean)
], MdDatePicker.prototype, "showDaysInNextAndPreviousMonths", void 0);
tslib_1.__decorate([
au.bindable({ defaultBindingMode: au.bindingMode.oneTime }),
tslib_1.__metadata("design:type", Object)
], MdDatePicker.prototype, "container", void 0);
tslib_1.__decorate([
au.ato.bindable.booleanMd({ defaultBindingMode: au.bindingMode.oneTime }),
tslib_1.__metadata("design:type", Boolean)
], MdDatePicker.prototype, "showClearBtn", void 0);
tslib_1.__decorate([
au.bindable({ defaultBindingMode: au.bindingMode.oneTime }),
tslib_1.__metadata("design:type", Object)
], MdDatePicker.prototype, "i18n", void 0);
tslib_1.__decorate([
au.bindable({ defaultBindingMode: au.bindingMode.oneTime }),
tslib_1.__metadata("design:type", Array)
], MdDatePicker.prototype, "events", void 0);
tslib_1.__decorate([
au.ato.bindable.booleanMd,
tslib_1.__metadata("design:type", Boolean)
], MdDatePicker.prototype, "showErrortext", void 0);
tslib_1.__decorate([
au.bindable({ defaultBindingMode: au.bindingMode.twoWay }),
tslib_1.__metadata("design:type", Date)
], MdDatePicker.prototype, "value", void 0);
MdDatePicker = MdDatePicker_1 = tslib_1.__decorate([
au.autoinject,
au.customElement("md-datepicker"),
tslib_1.__metadata("design:paramtypes", [Element])
], MdDatePicker);
export { MdDatePicker };
//# sourceMappingURL=datepicker.js.map