2019-10-23 12:55:11 -04:00
|
|
|
import EmberObject from "@ember/object";
|
2020-05-13 16:23:41 -04:00
|
|
|
import I18n from "I18n";
|
2017-06-28 16:56:44 -04:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
|
2019-11-08 14:13:35 -05:00
|
|
|
const WatchedWord = EmberObject.extend({
|
2017-06-28 16:56:44 -04:00
|
|
|
save() {
|
2017-07-31 17:06:26 -04:00
|
|
|
return ajax(
|
2021-04-01 02:14:17 -04:00
|
|
|
"/admin/customize/watched_words" +
|
|
|
|
(this.id ? "/" + this.id : "") +
|
|
|
|
".json",
|
2017-07-31 17:06:26 -04:00
|
|
|
{
|
2017-06-28 16:56:44 -04:00
|
|
|
type: this.id ? "PUT" : "POST",
|
2021-02-25 07:00:58 -05:00
|
|
|
data: {
|
|
|
|
word: this.word,
|
|
|
|
replacement: this.replacement,
|
|
|
|
action_key: this.action,
|
2022-08-02 04:06:03 -04:00
|
|
|
case_sensitive: this.isCaseSensitive,
|
2021-02-25 07:00:58 -05:00
|
|
|
},
|
2017-06-28 16:56:44 -04:00
|
|
|
dataType: "json",
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy() {
|
2021-04-01 02:14:17 -04:00
|
|
|
return ajax("/admin/customize/watched_words/" + this.id + ".json", {
|
2017-07-31 17:06:26 -04:00
|
|
|
type: "DELETE",
|
|
|
|
});
|
2017-06-28 16:56:44 -04:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
WatchedWord.reopenClass({
|
|
|
|
findAll() {
|
2021-04-01 02:14:17 -04:00
|
|
|
return ajax("/admin/customize/watched_words.json").then((list) => {
|
2017-06-28 16:56:44 -04:00
|
|
|
const actions = {};
|
2021-05-27 12:20:26 -04:00
|
|
|
|
|
|
|
list.actions.forEach((action) => {
|
|
|
|
actions[action] = [];
|
2017-06-28 16:56:44 -04:00
|
|
|
});
|
|
|
|
|
2021-05-27 12:20:26 -04:00
|
|
|
list.words.forEach((watchedWord) => {
|
|
|
|
actions[watchedWord.action].pushObject(WatchedWord.create(watchedWord));
|
2017-06-28 16:56:44 -04:00
|
|
|
});
|
|
|
|
|
2021-05-27 12:20:26 -04:00
|
|
|
return Object.keys(actions).map((nameKey) => {
|
2019-10-23 12:55:11 -04:00
|
|
|
return EmberObject.create({
|
2021-05-27 12:20:26 -04:00
|
|
|
nameKey,
|
|
|
|
name: I18n.t("admin.watched_words.actions." + nameKey),
|
|
|
|
words: actions[nameKey],
|
|
|
|
compiledRegularExpression: list.compiled_regular_expressions[nameKey],
|
2017-09-27 15:48:57 -04:00
|
|
|
});
|
2017-06-28 16:56:44 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
export default WatchedWord;
|