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/components/directory-toggle.js.es6
2018-06-15 17:03:24 +02:00

48 lines
1.3 KiB
JavaScript

import { iconHTML } from "discourse-common/lib/icon-library";
import { bufferedRender } from "discourse-common/lib/buffered-render";
import computed from "ember-addons/ember-computed-decorators";
export default Ember.Component.extend(
bufferedRender({
tagName: "th",
classNames: ["sortable"],
attributeBindings: ["title"],
rerenderTriggers: ["order", "asc"],
labelKey: null,
@computed("field", "labelKey")
title(field, labelKey) {
if (!labelKey) {
labelKey = `directory.${this.get("field")}`;
}
return I18n.t(labelKey + "_long", { defaultValue: I18n.t(labelKey) });
},
buildBuffer(buffer) {
const icon = this.get("icon");
if (icon) {
buffer.push(iconHTML(icon));
}
const field = this.get("field");
buffer.push(I18n.t(this.get("labelKey") || `directory.${field}`));
if (field === this.get("order")) {
buffer.push(iconHTML(this.get("asc") ? "chevron-up" : "chevron-down"));
}
},
click() {
const currentOrder = this.get("order"),
field = this.get("field");
if (currentOrder === field) {
this.set("asc", this.get("asc") ? null : true);
} else {
this.setProperties({ order: field, asc: null });
}
}
})
);