2020-05-14 04:23:41 +08:00
|
|
|
import I18n from "I18n";
|
2019-11-08 05:38:28 +08:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2019-11-01 01:37:24 +08:00
|
|
|
import { isEmpty } from "@ember/utils";
|
2019-10-31 04:28:29 +08:00
|
|
|
import { or } from "@ember/object/computed";
|
2019-10-30 21:48:24 +08:00
|
|
|
import { schedule } from "@ember/runloop";
|
2019-10-24 00:30:52 +08:00
|
|
|
import Component from "@ember/component";
|
2015-08-19 05:15:46 +08:00
|
|
|
import { bufferedProperty } from "discourse/mixins/buffered-content";
|
2019-11-08 05:38:28 +08:00
|
|
|
import { on, observes } from "discourse-common/utils/decorators";
|
2015-08-19 05:15:46 +08:00
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
2019-11-09 02:30:41 +08:00
|
|
|
import Category from "discourse/models/category";
|
2015-08-19 05:15:46 +08:00
|
|
|
|
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,
|
|
|
|
|
2019-10-31 04:28:29 +08:00
|
|
|
editing: or("host.isNew", "editToggled"),
|
2015-08-19 05:15:46 +08:00
|
|
|
|
|
|
|
@on("didInsertElement")
|
|
|
|
@observes("editing")
|
|
|
|
_focusOnInput() {
|
2019-10-30 21:48:24 +08:00
|
|
|
schedule("afterRender", () => {
|
2019-07-16 18:45:15 +08:00
|
|
|
this.element.querySelector(".host-name").focus();
|
2015-08-19 05:15:46 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
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",
|
|
|
|
"path_whitelist",
|
|
|
|
"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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|