ferngully-aurelia-tools
Version:
Ferngully Tools for Aurelia
139 lines • 5.45 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 { customAttribute, bindable, autoinject, BindingEngine } from "aurelia-framework";
import { bindingMode as BindingMode } from "aurelia-binding";
import { LoggingService } from "../../../services/logging-service";
import { DOMService } from "../../../services/dom-service";
import "./editable-inline.css";
let EditableInline = class EditableInline {
constructor(el, bindingEngine, logger, domService) {
this.bindingEngine = bindingEngine;
this.logger = logger;
this.domService = domService;
this.container = "body";
this.isDirty = false;
this.subscription = null;
this.editing = false;
this.element = $(el);
}
get clickElement() {
return this.element;
}
bind() {
this.subscription = this.bindingEngine.propertyObserver(this, "target")
.subscribe((newValue, oldValue) => {
this.isDirty = (this.originalValue !== newValue);
});
this.element.addClass("editableInline");
this.clickElement.on('click.editable-inline', (event) => {
this.beginEdit();
});
}
unbind() {
if (this.subscription) {
this.subscription.dispose();
this.subscription = null;
}
this.clickElement.off('click.editable-inline');
}
beginEdit() {
if (!this.originalValue) {
this.originalValue = this.target;
}
if (this.maxLength != undefined) {
this.editableInlineEditor.maxLength = this.maxLength;
}
this.editableInlineEditor.show(this.element, this.editorData, this.target, (event) => { return this.onKeyPressInEditor(event); }, () => { this.validateAndSave(); });
this.editing = true;
}
endEdit() {
this.editing = false;
this.editableInlineEditor.hide();
}
onKeyPressInEditor(event) {
switch (event.which) {
case 13:
if (event.shiftKey || event.ctrlKey) {
return true;
}
else {
this.validateAndSave();
return false;
}
case 9:
this.validateAndSave();
let nextCell = null;
if (event.shiftKey) {
nextCell = this.element.prev(".editableInline");
if (nextCell.length === 0) {
nextCell = this.domService.nextInDOM(".editableInline", this.element, true, this.container);
}
}
else {
nextCell = this.element.next(".editableInline");
if (nextCell.length === 0) {
nextCell = this.domService.nextInDOM(".editableInline", this.element, false, this.container);
}
}
if (nextCell) {
setTimeout(() => { nextCell.click(); }, 10);
}
return false;
case 27:
this.target = this.originalValue;
this.endEdit();
event.stopPropagation();
return false;
default:
return true;
}
;
}
validateAndSave() {
if (this.editing) {
var currentUneditedValue = (this.target || "") + "";
var newValue = (this.editableInlineEditor.value || "") + "";
if (currentUneditedValue !== newValue) {
this.target = this.editableInlineEditor.value;
}
this.endEdit();
}
}
};
__decorate([
bindable({ defaultBindingMode: BindingMode.twoWay }),
__metadata("design:type", Object)
], EditableInline.prototype, "target", void 0);
__decorate([
bindable,
__metadata("design:type", String)
], EditableInline.prototype, "container", void 0);
__decorate([
bindable,
__metadata("design:type", Number)
], EditableInline.prototype, "maxLength", void 0);
__decorate([
bindable,
__metadata("design:type", Object)
], EditableInline.prototype, "editorData", void 0);
__decorate([
bindable,
__metadata("design:type", Object)
], EditableInline.prototype, "editableInlineEditor", void 0);
EditableInline = __decorate([
customAttribute('editable-inline'),
autoinject,
__metadata("design:paramtypes", [Element,
BindingEngine,
LoggingService,
DOMService])
], EditableInline);
export { EditableInline };
//# sourceMappingURL=editable-inline.js.map