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