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-12-18 21:18:52 +08:00
|
|
|
import discourseDebounce from "discourse-common/lib/debounce";
|
2020-01-17 01:56:53 +08:00
|
|
|
import { observes } from "discourse-common/utils/decorators";
|
2022-02-09 14:11:41 +08:00
|
|
|
import { clipboardCopy } from "discourse/lib/utilities";
|
2022-09-14 23:06:56 +08:00
|
|
|
import { inject as service } from "@ember/service";
|
2022-11-10 03:23:08 +08:00
|
|
|
import { or } from "@ember/object/computed";
|
2015-08-11 05:11:27 +08:00
|
|
|
|
2019-10-24 01:06:54 +08:00
|
|
|
export default Controller.extend({
|
2022-09-14 23:06:56 +08:00
|
|
|
dialog: service(),
|
2015-07-15 20:54:28 +08:00
|
|
|
loading: false,
|
|
|
|
filter: null,
|
2022-11-10 03:23:08 +08:00
|
|
|
showSearch: or("model.length", "filter"),
|
2015-07-15 20:54:28 +08:00
|
|
|
|
2020-12-18 21:18:52 +08:00
|
|
|
_debouncedShow() {
|
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-18 21:18:52 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
@observes("filter")
|
|
|
|
show() {
|
|
|
|
discourseDebounce(this, this._debouncedShow, 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}`);
|
2022-02-09 14:11:41 +08:00
|
|
|
clipboardCopy(linkElement.textContent);
|
2020-06-22 11:14:16 +08:00
|
|
|
},
|
|
|
|
|
2021-11-13 21:01:55 +08:00
|
|
|
destroy(record) {
|
2022-09-14 23:06:56 +08:00
|
|
|
return this.dialog.yesNoConfirm({
|
|
|
|
message: I18n.t("admin.permalink.delete_confirm"),
|
|
|
|
didConfirm: () => {
|
|
|
|
return record.destroy().then(
|
|
|
|
(deleted) => {
|
|
|
|
if (deleted) {
|
|
|
|
this.model.removeObject(record);
|
|
|
|
} else {
|
|
|
|
this.dialog.alert(I18n.t("generic_error"));
|
2015-07-15 20:54:28 +08:00
|
|
|
}
|
2022-09-14 23:06:56 +08:00
|
|
|
},
|
|
|
|
function () {
|
|
|
|
this.dialog.alert(I18n.t("generic_error"));
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
2015-07-15 20:54:28 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|