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
2019-05-27 10:15:39 +02:00

48 lines
1.2 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.field}`;
}
return I18n.t(labelKey + "_long", { defaultValue: I18n.t(labelKey) });
},
buildBuffer(buffer) {
const icon = this.icon;
if (icon) {
buffer.push(iconHTML(icon));
}
const field = this.field;
buffer.push(I18n.t(this.labelKey || `directory.${field}`));
if (field === this.order) {
buffer.push(iconHTML(this.asc ? "chevron-up" : "chevron-down"));
}
},
click() {
const currentOrder = this.order,
field = this.field;
if (currentOrder === field) {
this.set("asc", this.asc ? null : true);
} else {
this.setProperties({ order: field, asc: null });
}
}
})
);