2019-10-31 04:28:29 +08:00
|
|
|
import { or } from "@ember/object/computed";
|
2019-10-30 21:48:24 +08:00
|
|
|
import { schedule } from "@ember/runloop";
|
2019-10-24 00:30:52 +08:00
|
|
|
import Component from "@ember/component";
|
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";
|
2015-08-19 05:15:46 +08:00
|
|
|
|
2019-10-24 00:30:52 +08:00
|
|
|
export default Component.extend(bufferedProperty("host"), {
|
2015-08-19 05:15:46 +08:00
|
|
|
editToggled: false,
|
2018-06-15 23:03:24 +08:00
|
|
|
tagName: "tr",
|
2015-08-19 05:15:46 +08:00
|
|
|
categoryId: null,
|
|
|
|
|
2019-10-31 04:28:29 +08:00
|
|
|
editing: or("host.isNew", "editToggled"),
|
2015-08-19 05:15:46 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
@on("didInsertElement")
|
|
|
|
@observes("editing")
|
2015-08-19 05:15:46 +08:00
|
|
|
_focusOnInput() {
|
2019-10-30 21:48:24 +08:00
|
|
|
schedule("afterRender", () => {
|
2019-07-16 18:45:15 +08:00
|
|
|
this.element.querySelector(".host-name").focus();
|
2018-06-15 23:03:24 +08:00
|
|
|
});
|
2015-08-19 05:15:46 +08:00
|
|
|
},
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
@computed("buffered.host", "host.isSaving")
|
2015-08-19 05:15:46 +08:00
|
|
|
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);
|
2015-08-19 05:15:46 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
save() {
|
2019-05-27 16:15:39 +08:00
|
|
|
if (this.cantSave) {
|
2018-06-15 23:03:24 +08:00
|
|
|
return;
|
|
|
|
}
|
2015-08-19 05:15:46 +08:00
|
|
|
|
2019-05-27 16:15:39 +08:00
|
|
|
const props = this.buffered.getProperties(
|
2018-06-15 23:03:24 +08:00
|
|
|
"host",
|
|
|
|
"path_whitelist",
|
|
|
|
"class_name"
|
|
|
|
);
|
2019-05-27 16:15:39 +08:00
|
|
|
props.category_id = this.categoryId;
|
2015-08-19 05:15:46 +08:00
|
|
|
|
2019-05-27 16:15:39 +08:00
|
|
|
const host = this.host;
|
2016-08-24 02:55:52 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
host
|
|
|
|
.save(props)
|
|
|
|
.then(() => {
|
2019-05-27 16:42:53 +08:00
|
|
|
host.set("category", Discourse.Category.findById(this.categoryId));
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("editToggled", false);
|
|
|
|
})
|
|
|
|
.catch(popupAjaxError);
|
2015-08-19 05:15:46 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
delete() {
|
2018-06-15 23:03:24 +08:00
|
|
|
bootbox.confirm(I18n.t("admin.embedding.confirm_delete"), result => {
|
2015-08-19 05:15:46 +08:00
|
|
|
if (result) {
|
2019-05-27 16:42:53 +08:00
|
|
|
this.host.destroyRecord().then(() => {
|
|
|
|
this.deleteHost(this.host);
|
|
|
|
});
|
2015-08-19 05:15:46 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
cancel() {
|
2019-05-27 16:15:39 +08:00
|
|
|
const host = this.host;
|
2018-06-15 23:03:24 +08:00
|
|
|
if (host.get("isNew")) {
|
2019-01-10 18:06:01 +08:00
|
|
|
this.deleteHost(host);
|
2015-08-19 05:15:46 +08:00
|
|
|
} else {
|
|
|
|
this.rollbackBuffer();
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("editToggled", false);
|
2015-08-19 05:15:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|