This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/app/components/table-header-toggle.js
2021-06-22 13:00:04 -05:00

47 lines
1.2 KiB
JavaScript

import Component from "@ember/component";
import { iconHTML } from "discourse-common/lib/icon-library";
export default Component.extend({
tagName: "th",
classNames: ["sortable"],
attributeBindings: ["title"],
labelKey: null,
chevronIcon: null,
columnIcon: null,
translated: false,
automatic: false,
onActiveRender: null,
toggleProperties() {
if (this.order === this.field) {
this.set("asc", this.asc ? null : true);
} else {
this.setProperties({ order: this.field, asc: null });
}
},
toggleChevron() {
if (this.order === this.field) {
let chevron = iconHTML(this.asc ? "chevron-up" : "chevron-down");
this.set("chevronIcon", `${chevron}`.htmlSafe());
} else {
this.set("chevronIcon", null);
}
},
click() {
this.toggleProperties();
},
didReceiveAttrs() {
this._super(...arguments);
if (!this.automatic && !this.translated) {
this.set("labelKey", this.field);
}
this.set("id", `table-header-toggle-${this.field.replace(/\s/g, "")}`);
this.toggleChevron();
},
didRender() {
if (this.onActiveRender && this.chevronIcon) {
this.onActiveRender(this.element);
}
},
});