2019-10-31 04:28:29 +08:00
|
|
|
import Category from "discourse/models/category";
|
2019-10-24 00:30:52 +08:00
|
|
|
import Component from "@ember/component";
|
2020-05-14 04:23:41 +08:00
|
|
|
import I18n from "I18n";
|
2015-08-19 05:15:46 +08:00
|
|
|
import { bufferedProperty } from "discourse/mixins/buffered-content";
|
2021-01-20 22:02:27 +08:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2022-10-07 23:38:27 +08:00
|
|
|
import { inject as service } from "@ember/service";
|
2019-11-01 01:37:24 +08:00
|
|
|
import { isEmpty } from "@ember/utils";
|
|
|
|
import { or } from "@ember/object/computed";
|
2015-08-19 05:15:46 +08:00
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
|
|
|
|
2019-10-24 00:30:52 +08:00
|
|
|
export default Component.extend(bufferedProperty("host"), {
|
2015-08-19 05:15:46 +08:00
|
|
|
editToggled: false,
|
|
|
|
tagName: "tr",
|
|
|
|
categoryId: null,
|
2021-10-06 00:59:27 +08:00
|
|
|
category: null,
|
2022-10-07 23:38:27 +08:00
|
|
|
dialog: service(),
|
2015-08-19 05:15:46 +08:00
|
|
|
|
2019-10-31 04:28:29 +08:00
|
|
|
editing: or("host.isNew", "editToggled"),
|
2015-08-19 05:15:46 +08:00
|
|
|
|
2021-10-06 00:59:27 +08:00
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
|
|
|
|
const host = this.host;
|
|
|
|
const categoryId = host.category_id || this.site.uncategorized_category_id;
|
|
|
|
const category = Category.findById(categoryId);
|
|
|
|
|
|
|
|
host.set("category", category);
|
|
|
|
},
|
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("buffered.host", "host.isSaving")
|
2015-08-19 05:15:46 +08:00
|
|
|
cantSave(host, isSaving) {
|
2019-11-01 01:37:24 +08:00
|
|
|
return isSaving || isEmpty(host);
|
2015-08-19 05:15:46 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
edit() {
|
|
|
|
this.set("categoryId", this.get("host.category.id"));
|
|
|
|
this.set("editToggled", true);
|
|
|
|
},
|
|
|
|
|
|
|
|
save() {
|
2019-05-27 16:15:39 +08:00
|
|
|
if (this.cantSave) {
|
2015-08-19 05:15:46 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-27 16:15:39 +08:00
|
|
|
const props = this.buffered.getProperties(
|
2017-05-06 06:08:18 +08:00
|
|
|
"host",
|
2020-07-27 08:23:54 +08:00
|
|
|
"allowed_paths",
|
2017-05-06 06:08:18 +08:00
|
|
|
"class_name"
|
|
|
|
);
|
2019-05-27 16:15:39 +08:00
|
|
|
props.category_id = this.categoryId;
|
2015-08-19 05:15:46 +08:00
|
|
|
|
2019-05-27 16:15:39 +08:00
|
|
|
const host = this.host;
|
2016-08-24 02:55:52 +08:00
|
|
|
|
2015-08-19 05:15:46 +08:00
|
|
|
host
|
|
|
|
.save(props)
|
|
|
|
.then(() => {
|
2019-11-09 02:30:41 +08:00
|
|
|
host.set("category", Category.findById(this.categoryId));
|
2015-08-19 05:15:46 +08:00
|
|
|
this.set("editToggled", false);
|
|
|
|
})
|
|
|
|
.catch(popupAjaxError);
|
|
|
|
},
|
|
|
|
|
|
|
|
delete() {
|
2022-10-07 23:38:27 +08:00
|
|
|
return this.dialog.confirm({
|
|
|
|
message: I18n.t("admin.embedding.confirm_delete"),
|
|
|
|
didConfirm: () => {
|
|
|
|
return this.host.destroyRecord().then(() => {
|
2019-05-27 16:42:53 +08:00
|
|
|
this.deleteHost(this.host);
|
|
|
|
});
|
2022-10-07 23:38:27 +08:00
|
|
|
},
|
2015-08-19 05:15:46 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
cancel() {
|
2019-05-27 16:15:39 +08:00
|
|
|
const host = this.host;
|
2015-08-19 05:15:46 +08:00
|
|
|
if (host.get("isNew")) {
|
2019-01-10 18:06:01 +08:00
|
|
|
this.deleteHost(host);
|
2015-08-19 05:15:46 +08:00
|
|
|
} else {
|
|
|
|
this.rollbackBuffer();
|
|
|
|
this.set("editToggled", false);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|