This repository has been archived on 2025-05-04. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
discourse/app/assets/javascripts/discourse/controllers/full-page-search.js.es6

39 lines
1 KiB
JavaScript

import { translateResults } from "discourse/lib/search-for-term";
export default Ember.Controller.extend({
needs: ["application"],
loading: Em.computed.not("model"),
queryParams: ["q"],
q: null,
modelChanged: function() {
if (this.get("searchTerm") !== this.get("q")) {
this.set("searchTerm", this.get("q"));
}
}.observes("model"),
qChanged: function() {
const model = this.get("model");
if (model && this.get("model.q") !== this.get("q")) {
this.set("searchTerm", this.get("q"));
this.send("search");
}
}.observes("q"),
_showFooter: function() {
this.set("controllers.application.showFooter", !this.get("loading"));
}.observes("loading"),
actions: {
search() {
this.set("q", this.get("searchTerm"));
this.set("model", null);
Discourse.ajax("/search", { data: { q: this.get("searchTerm") } }).then(results => {
this.set("model", translateResults(results) || {});
this.set("model.q", this.get("q"));
});
}
}
});