2018-06-15 23:03:24 +08:00
|
|
|
import { iconHTML } from "discourse-common/lib/icon-library";
|
|
|
|
import { bufferedRender } from "discourse-common/lib/buffered-render";
|
2017-02-20 21:42:33 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
export default Ember.Component.extend(
|
|
|
|
bufferedRender({
|
|
|
|
tagName: "th",
|
|
|
|
classNames: ["sortable"],
|
|
|
|
rerenderTriggers: ["order", "ascending"],
|
2017-02-20 21:42:33 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
buildBuffer(buffer) {
|
|
|
|
const icon = this.get("icon");
|
2017-02-20 21:42:33 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
if (icon) {
|
|
|
|
buffer.push(iconHTML(icon));
|
|
|
|
}
|
2017-02-20 21:42:33 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
buffer.push(I18n.t(this.get("i18nKey")));
|
2017-02-20 21:42:33 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
if (this.get("field") === this.get("order")) {
|
|
|
|
buffer.push(
|
|
|
|
iconHTML(this.get("ascending") ? "chevron-up" : "chevron-down")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
2017-02-20 21:42:33 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
click() {
|
|
|
|
const currentOrder = this.get("order");
|
|
|
|
const field = this.get("field");
|
2017-02-20 21:42:33 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
if (currentOrder === field) {
|
|
|
|
this.set("ascending", this.get("ascending") ? null : true);
|
|
|
|
} else {
|
|
|
|
this.setProperties({ order: field, ascending: null });
|
|
|
|
}
|
2017-02-20 21:42:33 +08:00
|
|
|
}
|
2018-06-15 23:03:24 +08:00
|
|
|
})
|
|
|
|
);
|