ferngully-aurelia-tools
Version:
Ferngully Tools for Aurelia
166 lines • 8.57 kB
JavaScript
System.register(["aurelia-framework", "aurelia-binding", "../../../services/logging-service", "../../../services/dom-service", "./editable-inline.css"], function (exports_1, context_1) {
"use strict";
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);
};
var __moduleName = context_1 && context_1.id;
var aurelia_framework_1, aurelia_binding_1, logging_service_1, dom_service_1, EditableInline;
return {
setters: [
function (aurelia_framework_1_1) {
aurelia_framework_1 = aurelia_framework_1_1;
},
function (aurelia_binding_1_1) {
aurelia_binding_1 = aurelia_binding_1_1;
},
function (logging_service_1_1) {
logging_service_1 = logging_service_1_1;
},
function (dom_service_1_1) {
dom_service_1 = dom_service_1_1;
},
function (_1) {
}
],
execute: function () {
EditableInline = (function () {
function EditableInline(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);
}
Object.defineProperty(EditableInline.prototype, "clickElement", {
get: function () {
return this.element;
},
enumerable: true,
configurable: true
});
EditableInline.prototype.bind = function () {
var _this = this;
this.subscription = this.bindingEngine.propertyObserver(this, "target")
.subscribe(function (newValue, oldValue) {
_this.isDirty = (_this.originalValue !== newValue);
});
this.element.addClass("editableInline");
this.clickElement.on('click.editable-inline', function (event) {
_this.beginEdit();
});
};
EditableInline.prototype.unbind = function () {
if (this.subscription) {
this.subscription.dispose();
this.subscription = null;
}
this.clickElement.off('click.editable-inline');
};
EditableInline.prototype.beginEdit = function () {
var _this = this;
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, function (event) { return _this.onKeyPressInEditor(event); }, function () { _this.validateAndSave(); });
this.editing = true;
};
EditableInline.prototype.endEdit = function () {
this.editing = false;
this.editableInlineEditor.hide();
};
EditableInline.prototype.onKeyPressInEditor = function (event) {
switch (event.which) {
case 13:
if (event.shiftKey || event.ctrlKey) {
return true;
}
else {
this.validateAndSave();
return false;
}
case 9:
this.validateAndSave();
var nextCell_1 = null;
if (event.shiftKey) {
nextCell_1 = this.element.prev(".editableInline");
if (nextCell_1.length === 0) {
nextCell_1 = this.domService.nextInDOM(".editableInline", this.element, true, this.container);
}
}
else {
nextCell_1 = this.element.next(".editableInline");
if (nextCell_1.length === 0) {
nextCell_1 = this.domService.nextInDOM(".editableInline", this.element, false, this.container);
}
}
if (nextCell_1) {
setTimeout(function () { nextCell_1.click(); }, 10);
}
return false;
case 27:
this.target = this.originalValue;
this.endEdit();
event.stopPropagation();
return false;
default:
return true;
}
;
};
EditableInline.prototype.validateAndSave = function () {
if (this.editing) {
var currentUneditedValue = (this.target || "") + "";
var newValue = (this.editableInlineEditor.value || "") + "";
if (currentUneditedValue !== newValue) {
this.target = this.editableInlineEditor.value;
}
this.endEdit();
}
};
__decorate([
aurelia_framework_1.bindable({ defaultBindingMode: aurelia_binding_1.bindingMode.twoWay }),
__metadata("design:type", Object)
], EditableInline.prototype, "target", void 0);
__decorate([
aurelia_framework_1.bindable,
__metadata("design:type", String)
], EditableInline.prototype, "container", void 0);
__decorate([
aurelia_framework_1.bindable,
__metadata("design:type", Number)
], EditableInline.prototype, "maxLength", void 0);
__decorate([
aurelia_framework_1.bindable,
__metadata("design:type", Object)
], EditableInline.prototype, "editorData", void 0);
__decorate([
aurelia_framework_1.bindable,
__metadata("design:type", Object)
], EditableInline.prototype, "editableInlineEditor", void 0);
EditableInline = __decorate([
aurelia_framework_1.customAttribute('editable-inline'),
aurelia_framework_1.autoinject,
__metadata("design:paramtypes", [Element,
aurelia_framework_1.BindingEngine,
logging_service_1.LoggingService,
dom_service_1.DOMService])
], EditableInline);
return EditableInline;
}());
exports_1("EditableInline", EditableInline);
}
};
});
//# sourceMappingURL=editable-inline.js.map