2019-10-30 21:48:24 +08:00
|
|
|
import { debounce } from "@ember/runloop";
|
2019-10-24 01:06:54 +08:00
|
|
|
import Controller from "@ember/controller";
|
2016-04-14 03:16:37 +08:00
|
|
|
let lastSearch;
|
|
|
|
|
2019-10-24 01:06:54 +08:00
|
|
|
export default Controller.extend({
|
2015-11-24 05:45:05 +08:00
|
|
|
searching: false,
|
|
|
|
siteTexts: null,
|
|
|
|
preferred: false,
|
2018-06-15 23:03:24 +08:00
|
|
|
queryParams: ["q", "overridden"],
|
2015-11-24 05:45:05 +08:00
|
|
|
|
2016-11-03 04:22:52 +08:00
|
|
|
q: null,
|
2019-02-21 22:54:54 +08:00
|
|
|
overridden: false,
|
2015-11-24 05:45:05 +08:00
|
|
|
|
|
|
|
_performSearch() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.store
|
|
|
|
.find("site-text", this.getProperties("q", "overridden"))
|
|
|
|
.then(results => {
|
|
|
|
this.set("siteTexts", results);
|
|
|
|
})
|
|
|
|
.finally(() => this.set("searching", false));
|
2015-11-24 05:45:05 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
edit(siteText) {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.transitionToRoute("adminSiteText.edit", siteText.get("id"));
|
2015-11-24 05:45:05 +08:00
|
|
|
},
|
|
|
|
|
2019-02-21 22:54:54 +08:00
|
|
|
toggleOverridden() {
|
|
|
|
this.toggleProperty("overridden");
|
|
|
|
this.set("searching", true);
|
2019-10-30 21:48:24 +08:00
|
|
|
debounce(this, this._performSearch, 400);
|
2019-02-21 22:54:54 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
search() {
|
2019-05-27 16:15:39 +08:00
|
|
|
const q = this.q;
|
2019-02-21 22:54:54 +08:00
|
|
|
if (q !== lastSearch) {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("searching", true);
|
2019-10-30 21:48:24 +08:00
|
|
|
debounce(this, this._performSearch, 400);
|
2016-04-14 03:16:37 +08:00
|
|
|
lastSearch = q;
|
|
|
|
}
|
2015-11-24 05:45:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|