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