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/controllers/jump-to-post.js.es6
Sam Saffron 13cca3eaa0 DEV: run files through prettier
2ae21e9 was prettiered using an old version of prettier.

This re-applies it using latest.
2019-10-31 10:18:29 +11:00

42 lines
1017 B
JavaScript

import { alias } from "@ember/object/computed";
import { next } from "@ember/runloop";
import Controller from "@ember/controller";
import ModalFunctionality from "discourse/mixins/modal-functionality";
export default Controller.extend(ModalFunctionality, {
model: null,
postNumber: null,
postDate: null,
filteredPostsCount: alias("topic.postStream.filteredPostsCount"),
onShow() {
next(() => $("#post-jump").focus());
},
actions: {
jump() {
if (this.postNumber) {
this._jumpToIndex(this.filteredPostsCount, this.postNumber);
} else if (this.postDate) {
this._jumpToDate(this.postDate);
}
}
},
_jumpToIndex(postsCounts, postNumber) {
const where = Math.min(postsCounts, Math.max(1, parseInt(postNumber)));
this.jumpToIndex(where);
this._close();
},
_jumpToDate(date) {
this.jumpToDate(date);
this._close();
},
_close() {
this.setProperties({ postNumber: null, postDate: null });
this.send("closeModal");
}
});