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

81 lines
1.9 KiB
Plaintext
Raw Normal View History

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";
2018-06-15 11:03:24 -04:00
export default Ember.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() {
2018-06-15 11:03:24 -04:00
Ember.run.schedule("afterRender", () => {
this.$(".host-name").focus();
});
},
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() {
2018-06-15 11:03:24 -04:00
if (this.get("cantSave")) {
return;
}
2018-06-15 11:03:24 -04:00
const props = this.get("buffered").getProperties(
"host",
"path_whitelist",
"class_name"
);
props.category_id = this.get("categoryId");
2018-06-15 11:03:24 -04:00
const host = this.get("host");
2018-06-15 11:03:24 -04:00
host
.save(props)
.then(() => {
host.set(
"category",
Discourse.Category.findById(this.get("categoryId"))
);
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) {
2018-06-15 11:03:24 -04:00
this.get("host")
.destroyRecord()
.then(() => {
this.sendAction("deleteHost", this.get("host"));
});
}
});
},
cancel() {
2018-06-15 11:03:24 -04:00
const host = this.get("host");
if (host.get("isNew")) {
this.sendAction("deleteHost", host);
} else {
this.rollbackBuffer();
2018-06-15 11:03:24 -04:00
this.set("editToggled", false);
}
}
}
});