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

81 lines
1.8 KiB
Plaintext
Raw Normal View History

2018-06-15 23:03:24 +08: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";
2018-06-15 23:03:24 +08:00
export default Ember.Component.extend(bufferedProperty("host"), {
editToggled: false,
2018-06-15 23:03:24 +08:00
tagName: "tr",
categoryId: null,
2018-06-15 23:03:24 +08:00
editing: Ember.computed.or("host.isNew", "editToggled"),
2018-06-15 23:03:24 +08:00
@on("didInsertElement")
@observes("editing")
_focusOnInput() {
2018-06-15 23:03:24 +08:00
Ember.run.schedule("afterRender", () => {
this.$(".host-name").focus();
});
},
2018-06-15 23:03:24 +08:00
@computed("buffered.host", "host.isSaving")
cantSave(host, isSaving) {
return isSaving || Ember.isEmpty(host);
},
actions: {
edit() {
2018-06-15 23:03:24 +08:00
this.set("categoryId", this.get("host.category.id"));
this.set("editToggled", true);
},
save() {
if (this.cantSave) {
2018-06-15 23:03:24 +08:00
return;
}
const props = this.buffered.getProperties(
2018-06-15 23:03:24 +08:00
"host",
"path_whitelist",
"class_name"
);
props.category_id = this.categoryId;
const host = this.host;
2018-06-15 23:03:24 +08:00
host
.save(props)
.then(() => {
host.set(
"category",
Discourse.Category.findById(this.categoryId)
2018-06-15 23:03:24 +08:00
);
this.set("editToggled", false);
})
.catch(popupAjaxError);
},
delete() {
2018-06-15 23:03:24 +08:00
bootbox.confirm(I18n.t("admin.embedding.confirm_delete"), result => {
if (result) {
this.host
2018-06-15 23:03:24 +08:00
.destroyRecord()
.then(() => {
this.deleteHost(this.host);
2018-06-15 23:03:24 +08:00
});
}
});
},
cancel() {
const host = this.host;
2018-06-15 23:03:24 +08:00
if (host.get("isNew")) {
this.deleteHost(host);
} else {
this.rollbackBuffer();
2018-06-15 23:03:24 +08:00
this.set("editToggled", false);
}
}
}
});