ferngully-aurelia-tools
Version:
Ferngully Tools for Aurelia
190 lines • 7.73 kB
JavaScript
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);
};
import { customElement, bindable, autoinject } from "aurelia-framework";
import { DateService } from "../../../services/date-service";
import { AureliaHelperService } from "../../../services/aurelia-helper-service";
import { DisposableCollection } from "../../../services/disposable-collection";
import { bindingMode } from "aurelia-binding";
import "./datepicker.css";
import "bootstrap-datepicker";
import "jquery";
var DatePicker = (function () {
function DatePicker(dateService, aureliaHelperService, disposableCollection) {
this.dateService = dateService;
this.aureliaHelperService = aureliaHelperService;
this.disposableCollection = disposableCollection;
this.format = "table";
this.startDate = false;
this.lang = "en-CA";
}
DatePicker.prototype.attached = function () {
var _this = this;
this.picker = $(this.picker);
if (this.width) {
$(this.$inputElement).css({ width: this.width });
}
if (typeof (this.startDate) == "boolean") {
var yesNo = this.startDate;
if (yesNo) {
this.startDate = this.dateService.today;
}
}
this.picker.datepicker({
format: {
toDisplay: function (date, format, language) {
if (!date) {
return '';
}
return _this.dateService.toString(_this.dateService.translateUtcToLocal(date), _this.rawFormat);
},
toValue: function (date, format, language) {
if (!date) {
return new Date();
}
return _this.dateService.fromString(date, _this.rawFormat);
}
},
startDate: this.startDate ? this.startDate : undefined,
autoclose: this.autoclose,
todayHighlight: true,
todayBtn: true,
language: this.lang
});
this.disposableCollection.push(this.aureliaHelperService.createPropertyWatch(this, "format", function () {
_this.rawFormat = _this.dateService.getSafeParams(_this.format).format;
}));
this.rawFormat = this.dateService.getSafeParams(this.format).format;
this.disposableCollection.push(this.aureliaHelperService.createPropertyWatch(this, "target", function () {
_this.picker.datepicker("setDate", _this.dateService.fromString(_this.target, _this.rawFormat));
}));
if (this.target) {
this.picker.datepicker("setDate", this.dateService.fromString(this.target, this.rawFormat));
}
this.picker.datepicker()
.on('change.date-picker', function (e) { return fireEvent(e.target, "input"); })
.on('show', function (e) {
if (_this.onShow)
_this.onShow(_this);
})
.on('hide', function (e) {
if (_this.onHide)
_this.onHide(_this);
});
this.$inputElement
.on('keydown', function (e) {
_this.keydown(e);
})
.on('change', function (e) {
_this.target = _this.$inputElement.val().toString();
});
this.$buttonElement.on('click', function (e) {
_this.buttonClick();
});
};
DatePicker.prototype.unattached = function () {
this.picker.datepicker().off('change.date-picker')
.off('show')
.off('hide');
this.$inputElement.off('keydown').off('change');
this.$buttonElement.off('click');
this.disposableCollection.dispose();
};
DatePicker.prototype.show = function () {
this.picker.datepicker('show');
this.$inputElement.focus();
};
DatePicker.prototype.hide = function () {
this.picker.datepicker('hide');
};
DatePicker.prototype.keydown = function (event) {
var retval = true;
var $target = $(event.target);
if (this.onKeydown) {
retval = this.onKeydown(event, this);
}
if (retval) {
switch (event.key) {
case "Enter":
case "Escape":
this.hide();
break;
}
}
return retval;
};
DatePicker.prototype.buttonClick = function () {
this.$inputElement.focus();
};
Object.defineProperty(DatePicker.prototype, "$buttonElement", {
get: function () {
return $(this.picker).find("#buttonElement");
},
enumerable: true,
configurable: true
});
Object.defineProperty(DatePicker.prototype, "$inputElement", {
get: function () {
return $(this.picker).find("#inputElement");
},
enumerable: true,
configurable: true
});
__decorate([
bindable({ defaultBindingMode: bindingMode.twoWay }),
__metadata("design:type", String)
], DatePicker.prototype, "target", void 0);
__decorate([
bindable({ defaultBindingMode: bindingMode.oneTime }),
__metadata("design:type", String)
], DatePicker.prototype, "format", void 0);
__decorate([
bindable({ defaultBindingMode: bindingMode.oneTime }),
__metadata("design:type", String)
], DatePicker.prototype, "width", void 0);
__decorate([
bindable({ defaultBindingMode: bindingMode.oneTime }),
__metadata("design:type", Boolean)
], DatePicker.prototype, "autoclose", void 0);
__decorate([
bindable({ defaultBindingMode: bindingMode.oneTime }),
__metadata("design:type", Object)
], DatePicker.prototype, "startDate", void 0);
__decorate([
bindable({ defaultBindingMode: bindingMode.oneWay }),
__metadata("design:type", String)
], DatePicker.prototype, "lang", void 0);
__decorate([
bindable,
__metadata("design:type", Function)
], DatePicker.prototype, "onShow", void 0);
__decorate([
bindable,
__metadata("design:type", Function)
], DatePicker.prototype, "onHide", void 0);
__decorate([
bindable,
__metadata("design:type", Function)
], DatePicker.prototype, "onKeydown", void 0);
DatePicker = __decorate([
autoinject,
customElement('date-picker'),
__metadata("design:paramtypes", [DateService,
AureliaHelperService,
DisposableCollection])
], DatePicker);
return DatePicker;
}());
export { DatePicker };
function fireEvent(element, name) {
var event = document.createEvent("Event");
event.initEvent(name, true, true);
element.dispatchEvent(event);
}
//# sourceMappingURL=datepicker.js.map