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";
|
2020-08-27 00:57:13 +08:00
|
|
|
import bootbox from "bootbox";
|
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";
|
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,
|
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() {
|
|
|
|
bootbox.confirm(I18n.t("admin.embedding.confirm_delete"), (result) => {
|
|
|
|
if (result) {
|
2019-05-27 16:42:53 +08:00
|
|
|
this.host.destroyRecord().then(() => {
|
|
|
|
this.deleteHost(this.host);
|
|
|
|
});
|
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);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|