mirror of
https://github.com/discourse/discourse.git
synced 2025-01-17 07:42:56 +08:00
47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
|
import Controller, { inject as controller } from "@ember/controller";
|
||
|
import { action } from "@ember/object";
|
||
|
import { service } from "@ember/service";
|
||
|
import { isEmpty } from "@ember/utils";
|
||
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||
|
import { i18n } from "discourse-i18n";
|
||
|
|
||
|
export default class AdminEmbeddingPostsAndTopicsController extends Controller {
|
||
|
@service toasts;
|
||
|
@controller adminEmbedding;
|
||
|
|
||
|
get formData() {
|
||
|
const embedding = this.adminEmbedding.embedding;
|
||
|
|
||
|
return {
|
||
|
embed_by_username: isEmpty(embedding.embed_by_username)
|
||
|
? null
|
||
|
: [embedding.embed_by_username],
|
||
|
embed_post_limit: embedding.embed_post_limit,
|
||
|
embed_title_scrubber: embedding.embed_title_scrubber,
|
||
|
embed_truncate: embedding.embed_truncate,
|
||
|
embed_unlisted: embedding.embed_unlisted,
|
||
|
};
|
||
|
}
|
||
|
|
||
|
@action
|
||
|
async save(data) {
|
||
|
const embedding = this.adminEmbedding.embedding;
|
||
|
|
||
|
try {
|
||
|
await embedding.update({
|
||
|
type: "posts_and_topics",
|
||
|
...data,
|
||
|
embed_by_username: data.embed_by_username[0],
|
||
|
});
|
||
|
this.toasts.success({
|
||
|
duration: 1500,
|
||
|
data: {
|
||
|
message: i18n("admin.embedding.posts_and_topics_settings_saved"),
|
||
|
},
|
||
|
});
|
||
|
} catch (error) {
|
||
|
popupAjaxError(error);
|
||
|
}
|
||
|
}
|
||
|
}
|