2019-10-24 01:06:54 +08:00
|
|
|
import Controller from "@ember/controller";
|
2015-11-21 09:27:06 +08:00
|
|
|
import I18n from "I18n";
|
2020-03-11 22:28:16 +08:00
|
|
|
import { INPUT_DELAY } from "discourse-common/config/environment";
|
2015-11-21 09:27:06 +08:00
|
|
|
import Permalink from "admin/models/permalink";
|
2020-08-27 00:57:13 +08:00
|
|
|
import bootbox from "bootbox";
|
2020-12-11 03:48:25 +08:00
|
|
|
import discourseDebounce from "discourse/lib/debounce";
|
2020-01-17 01:56:53 +08:00
|
|
|
import { observes } from "discourse-common/utils/decorators";
|
2015-08-11 05:11:27 +08:00
|
|
|
|
2019-10-24 01:06:54 +08:00
|
|
|
export default Controller.extend({
|
2015-07-15 20:54:28 +08:00
|
|
|
loading: false,
|
|
|
|
filter: null,
|
|
|
|
|
2020-12-11 03:48:25 +08:00
|
|
|
@observes("filter")
|
|
|
|
show: discourseDebounce(function () {
|
2019-05-27 16:15:39 +08:00
|
|
|
Permalink.findAll(this.filter).then((result) => {
|
2016-10-21 01:26:41 +08:00
|
|
|
this.set("model", result);
|
|
|
|
this.set("loading", false);
|
2015-07-15 20:54:28 +08:00
|
|
|
});
|
2020-12-11 03:48:25 +08:00
|
|
|
}, INPUT_DELAY),
|
2015-07-15 20:54:28 +08:00
|
|
|
|
|
|
|
actions: {
|
|
|
|
recordAdded(arg) {
|
2019-05-27 16:15:39 +08:00
|
|
|
this.model.unshiftObject(arg);
|
2015-07-15 20:54:28 +08:00
|
|
|
},
|
|
|
|
|
2020-06-22 11:14:16 +08:00
|
|
|
copyUrl(pl) {
|
|
|
|
let linkElement = document.querySelector(`#admin-permalink-${pl.id}`);
|
|
|
|
let textArea = document.createElement("textarea");
|
|
|
|
textArea.value = linkElement.textContent;
|
|
|
|
document.body.appendChild(textArea);
|
|
|
|
textArea.select();
|
|
|
|
document.execCommand("Copy");
|
|
|
|
textArea.remove();
|
|
|
|
},
|
|
|
|
|
2015-07-15 20:54:28 +08:00
|
|
|
destroy: function (record) {
|
2016-10-21 01:26:41 +08:00
|
|
|
return bootbox.confirm(
|
|
|
|
I18n.t("admin.permalink.delete_confirm"),
|
|
|
|
I18n.t("no_value"),
|
|
|
|
I18n.t("yes_value"),
|
|
|
|
(result) => {
|
2015-07-15 20:54:28 +08:00
|
|
|
if (result) {
|
2016-10-21 01:26:41 +08:00
|
|
|
record.destroy().then(
|
|
|
|
(deleted) => {
|
2015-07-15 20:54:28 +08:00
|
|
|
if (deleted) {
|
2019-05-27 16:15:39 +08:00
|
|
|
this.model.removeObject(record);
|
2015-07-15 20:54:28 +08:00
|
|
|
} else {
|
|
|
|
bootbox.alert(I18n.t("generic_error"));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
bootbox.alert(I18n.t("generic_error"));
|
|
|
|
}
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
}
|
2015-07-15 20:54:28 +08:00
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|