2019-10-23 13:06:54 -04:00
|
|
|
import Controller from "@ember/controller";
|
2021-01-18 12:53:45 -05:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2020-12-18 08:18:52 -05:00
|
|
|
import discourseDebounce from "discourse-common/lib/debounce";
|
2016-04-13 15:16:37 -04:00
|
|
|
let lastSearch;
|
|
|
|
|
2019-10-23 13:06:54 -04:00
|
|
|
export default Controller.extend({
|
2015-11-23 16:45:05 -05:00
|
|
|
searching: false,
|
|
|
|
siteTexts: null,
|
|
|
|
preferred: false,
|
2021-01-18 12:53:45 -05:00
|
|
|
queryParams: ["q", "overridden", "locale"],
|
|
|
|
locale: null,
|
2015-11-23 16:45:05 -05:00
|
|
|
|
2016-11-02 16:22:52 -04:00
|
|
|
q: null,
|
2019-02-21 09:54:54 -05:00
|
|
|
overridden: false,
|
2015-11-23 16:45:05 -05:00
|
|
|
|
2021-01-18 12:53:45 -05:00
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
|
|
|
|
this.set("locale", this.siteSettings.default_locale);
|
|
|
|
},
|
|
|
|
|
2015-11-23 16:45:05 -05:00
|
|
|
_performSearch() {
|
2015-11-30 15:22:58 -05:00
|
|
|
this.store
|
2021-01-18 12:53:45 -05:00
|
|
|
.find("site-text", this.getProperties("q", "overridden", "locale"))
|
2015-11-30 15:22:58 -05:00
|
|
|
.then((results) => {
|
2015-11-23 16:45:05 -05:00
|
|
|
this.set("siteTexts", results);
|
|
|
|
})
|
|
|
|
.finally(() => this.set("searching", false));
|
|
|
|
},
|
|
|
|
|
2021-01-18 12:53:45 -05:00
|
|
|
@discourseComputed()
|
|
|
|
availableLocales() {
|
|
|
|
return JSON.parse(this.siteSettings.available_locales);
|
|
|
|
},
|
|
|
|
|
|
|
|
@discourseComputed("locale")
|
|
|
|
fallbackLocaleFullName() {
|
|
|
|
if (this.siteTexts.extras.fallback_locale) {
|
|
|
|
return this.availableLocales.find((l) => {
|
|
|
|
return l.value === this.siteTexts.extras.fallback_locale;
|
|
|
|
}).name;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-11-23 16:45:05 -05:00
|
|
|
actions: {
|
|
|
|
edit(siteText) {
|
2021-01-18 12:53:45 -05:00
|
|
|
this.transitionToRoute("adminSiteText.edit", siteText.get("id"), {
|
|
|
|
queryParams: {
|
|
|
|
locale: this.locale,
|
|
|
|
},
|
|
|
|
});
|
2015-11-23 16:45:05 -05:00
|
|
|
},
|
|
|
|
|
2019-02-21 09:54:54 -05:00
|
|
|
toggleOverridden() {
|
|
|
|
this.toggleProperty("overridden");
|
|
|
|
this.set("searching", true);
|
2020-12-18 08:18:52 -05:00
|
|
|
discourseDebounce(this, this._performSearch, 400);
|
2019-02-21 09:54:54 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
search() {
|
2019-05-27 04:15:39 -04:00
|
|
|
const q = this.q;
|
2019-02-21 09:54:54 -05:00
|
|
|
if (q !== lastSearch) {
|
2016-04-13 15:16:37 -04:00
|
|
|
this.set("searching", true);
|
2020-12-18 08:18:52 -05:00
|
|
|
discourseDebounce(this, this._performSearch, 400);
|
2016-04-13 15:16:37 -04:00
|
|
|
lastSearch = q;
|
|
|
|
}
|
2015-11-23 16:45:05 -05:00
|
|
|
},
|
2021-01-18 12:53:45 -05:00
|
|
|
|
|
|
|
updateLocale(value) {
|
|
|
|
this.setProperties({
|
|
|
|
searching: true,
|
|
|
|
locale: value,
|
|
|
|
});
|
|
|
|
|
|
|
|
discourseDebounce(this, this._performSearch, 400);
|
|
|
|
},
|
2015-11-23 16:45:05 -05:00
|
|
|
},
|
|
|
|
});
|