discourse/app/assets/javascripts/admin/components/embeddable-host.js.es6

78 lines
1.9 KiB
Plaintext
Raw Normal View History

2019-10-29 14:52:36 -04:00
import { schedule } from "@ember/runloop";
import Component from "@ember/component";
2018-06-15 11:03:24 -04:00
import { bufferedProperty } from "discourse/mixins/buffered-content";
import computed from "ember-addons/ember-computed-decorators";
import { on, observes } from "ember-addons/ember-computed-decorators";
import { popupAjaxError } from "discourse/lib/ajax-error";
export default Component.extend(bufferedProperty("host"), {
editToggled: false,
2018-06-15 11:03:24 -04:00
tagName: "tr",
categoryId: null,
2018-06-15 11:03:24 -04:00
editing: Ember.computed.or("host.isNew", "editToggled"),
2018-06-15 11:03:24 -04:00
@on("didInsertElement")
@observes("editing")
_focusOnInput() {
2019-10-29 14:52:36 -04:00
schedule("afterRender", () => {
this.element.querySelector(".host-name").focus();
2018-06-15 11:03:24 -04:00
});
},
2018-06-15 11:03:24 -04:00
@computed("buffered.host", "host.isSaving")
cantSave(host, isSaving) {
return isSaving || Ember.isEmpty(host);
},
actions: {
edit() {
2018-06-15 11:03:24 -04:00
this.set("categoryId", this.get("host.category.id"));
this.set("editToggled", true);
},
save() {
if (this.cantSave) {
2018-06-15 11:03:24 -04:00
return;
}
const props = this.buffered.getProperties(
2018-06-15 11:03:24 -04:00
"host",
"path_whitelist",
"class_name"
);
props.category_id = this.categoryId;
const host = this.host;
2018-06-15 11:03:24 -04:00
host
.save(props)
.then(() => {
host.set("category", Discourse.Category.findById(this.categoryId));
2018-06-15 11:03:24 -04:00
this.set("editToggled", false);
})
.catch(popupAjaxError);
},
delete() {
2018-06-15 11:03:24 -04:00
bootbox.confirm(I18n.t("admin.embedding.confirm_delete"), result => {
if (result) {
this.host.destroyRecord().then(() => {
this.deleteHost(this.host);
});
}
});
},
cancel() {
const host = this.host;
2018-06-15 11:03:24 -04:00
if (host.get("isNew")) {
this.deleteHost(host);
} else {
this.rollbackBuffer();
2018-06-15 11:03:24 -04:00
this.set("editToggled", false);
}
}
}
});