ng2-encrm-components
Version:
116 lines • 3.74 kB
JavaScript
var core_1 = require('@angular/core');
var id = 'edit-table';
var Types;
(function (Types) {
Types[Types["STRING"] = 0] = "STRING";
Types[Types["BOOLEAN"] = 1] = "BOOLEAN";
})(Types || (Types = {}));
var EditTableComponent = (function () {
function EditTableComponent() {
this.isArray = isArray;
this.toArray = toArray;
this.isBoolean = isBoolean;
this.rows = [
{ key1: 'Me', key2: false },
{ key1: 'Other', key2: true }
];
this.headers = [
['Name', 'key1', 'Enter your name... ', undefined],
['Is stupid', 'key2', true, 100]
];
this.messageNoRows = 'Empty data-table....';
this.event = {
addRow: false
};
this.data = {};
}
EditTableComponent.prototype.save = function (o) {
// log.i('before', o);
var patterObject = this.rows[0];
for (var p in patterObject) {
if (o[p] === undefined) {
if (isBoolean(patterObject[p]))
o[p] = false;
else
o[p] = '';
}
}
// log.i('after', o);
this.rows.push(JSON.parse(JSON.stringify(o)));
this.event.addRow = !this.event.addRow;
};
EditTableComponent.prototype.addRow = function () {
this.data = {};
this.event.addRow = !this.event.addRow;
};
EditTableComponent.prototype.cancel = function () {
this.event.addRow = !this.event.addRow;
this.data = {};
};
EditTableComponent.prototype.getTypes = function (o) {
var types = [];
for (var p in o) {
if (isBoolean(o[p]))
types.push(Types.BOOLEAN);
else
types.push(Types.STRING);
}
return types;
};
EditTableComponent.prototype.unedit = function () {
this.edit = undefined;
};
EditTableComponent.prototype.isEdited = function (o) {
return Object.is(o, this.edit);
};
EditTableComponent.prototype.remove = function (row) {
if (confirm("Are you sure ? ")) {
var index = this.rows.indexOf(row);
this.rows.splice(index, 1);
}
};
EditTableComponent.prototype.ngOnInit = function () {
};
__decorate([
core_1.Input(),
__metadata('design:type', Array)
], EditTableComponent.prototype, "rows", void 0);
__decorate([
core_1.Input(),
__metadata('design:type', Array)
], EditTableComponent.prototype, "headers", void 0);
__decorate([
core_1.Input(),
__metadata('design:type', String)
], EditTableComponent.prototype, "messageNoRows", void 0);
EditTableComponent = __decorate([
core_1.Component({
selector: id,
template: require("./" + id + ".component.html"),
styles: [require("./" + id + ".component.scss")]
}),
__metadata('design:paramtypes', [])
], EditTableComponent);
return EditTableComponent;
}());
exports.EditTableComponent = EditTableComponent;
function isBoolean(bool) {
return typeof bool === 'boolean' ||
(typeof bool === 'object' && typeof bool.valueOf() === 'boolean');
}
function isArray(o) {
return (o instanceof Array);
}
function toArray(o) {
// log.d('object candidate to be array', o);
var a = [];
for (var i in o) {
if (o.hasOwnProperty(i)) {
a.push(i);
}
}
// log.d('object transformed', a);
return a;
}
//# sourceMappingURL=edit-table.component.js.map
;