var compare = require('natural-orderby').compare; var errors = require("./errors.js"); var SortingField = (function () { function SortingField(converter, fieldsDOMSelector) { if (fieldsDOMSelector === void 0) { fieldsDOMSelector = "th"; } this._order = undefined; if (converter.parseMetas === undefined || converter.parseMetas.fields === undefined) throw new Error(errors.sortingFieldNeedDatas); else { var fields = document.querySelectorAll(fieldsDOMSelector); if (fields === undefined) throw new Error(errors.sortingFieldsNotInHTML); else if (fields.length !== converter.parseMetas.fields.length) throw new Error(errors.sortingFieldsNbFail); else { this._converter = converter; this._fieldsDOMSelector = fieldsDOMSelector; } } } Object.defineProperty(SortingField.prototype, "datasFieldNb", { get: function () { return this._datasFieldNb; }, set: function (datasFieldNb) { if (datasFieldNb !== undefined && this._converter.parseMetas.fields[datasFieldNb] === undefined) throw new Error(errors.sortingFieldFieldNotFound); else this._datasFieldNb = datasFieldNb; }, enumerable: true, configurable: true }); Object.defineProperty(SortingField.prototype, "order", { get: function () { return this._order; }, enumerable: true, configurable: true }); SortingField.prototype.field2HTML = function () { if (this._converter === undefined || this._fieldsDOMSelector === "" || this._datasFieldNb === undefined) throw new Error(errors.sortingField2HTMLFail); else { var fields = document.querySelectorAll(this._fieldsDOMSelector); var htmlContent = fields[this._datasFieldNb].innerHTML; htmlContent = "" + htmlContent + ""; fields[this._datasFieldNb].innerHTML = htmlContent; var sortingElement = document.getElementById("freeDatas2HTMLSorting" + this._datasFieldNb), field_1 = this; sortingElement.addEventListener("click", function (e) { e.preventDefault(); var order = field_1._order; if (order === undefined || order === "desc") field_1._order = "asc"; else field_1._order = "desc"; field_1._converter.datasSortedField = field_1; field_1._converter.refreshView(); }); } }; return SortingField; }()); export { SortingField };