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";
|
2018-06-15 11:03:24 -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";
|
2018-06-15 11:03:24 -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,
|
2018-06-15 11:03:24 -04:00
|
|
|
tagName: "tr",
|
2015-08-18 17:15:46 -04:00
|
|
|
categoryId: null,
|
|
|
|
|
2019-10-30 16:28:29 -04:00
|
|
|
editing: or("host.isNew", "editToggled"),
|
2015-08-18 17:15:46 -04:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
@on("didInsertElement")
|
|
|
|
@observes("editing")
|
2015-08-18 17:15:46 -04:00
|
|
|
_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();
|
2018-06-15 11:03:24 -04:00
|
|
|
});
|
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() {
|
2018-06-15 11:03:24 -04:00
|
|
|
this.set("categoryId", this.get("host.category.id"));
|
|
|
|
this.set("editToggled", true);
|
2015-08-18 17:15:46 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
save() {
|
2019-05-27 04:15:39 -04:00
|
|
|
if (this.cantSave) {
|
2018-06-15 11:03:24 -04:00
|
|
|
return;
|
|
|
|
}
|
2015-08-18 17:15:46 -04:00
|
|
|
|
2019-05-27 04:15:39 -04:00
|
|
|
const props = this.buffered.getProperties(
|
2018-06-15 11:03:24 -04:00
|
|
|
"host",
|
|
|
|
"path_whitelist",
|
|
|
|
"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
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
host
|
|
|
|
.save(props)
|
|
|
|
.then(() => {
|
2019-11-08 13:30:41 -05:00
|
|
|
host.set("category", Category.findById(this.categoryId));
|
2018-06-15 11:03:24 -04:00
|
|
|
this.set("editToggled", false);
|
|
|
|
})
|
|
|
|
.catch(popupAjaxError);
|
2015-08-18 17:15:46 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
delete() {
|
2018-06-15 11:03:24 -04:00
|
|
|
bootbox.confirm(I18n.t("admin.embedding.confirm_delete"), result => {
|
2015-08-18 17:15:46 -04:00
|
|
|
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;
|
2018-06-15 11:03:24 -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();
|
2018-06-15 11:03:24 -04:00
|
|
|
this.set("editToggled", false);
|
2015-08-18 17:15:46 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|