DEV: Refactor the last few bootbox dialogs (#18416)

This commit is contained in:
Penar Musaraj
2022-10-07 11:38:27 -04:00
committed by GitHub
parent 6426932834
commit a1d67122b1
34 changed files with 331 additions and 333 deletions

View File

@ -1,12 +1,13 @@
import { gte, sort } from "@ember/object/computed";
import Controller from "@ember/controller";
import I18n from "I18n";
import bootbox from "bootbox";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { inject as service } from "@ember/service";
const MAX_FIELDS = 30;
export default Controller.extend({
dialog: service(),
fieldTypes: null,
createDisabled: gte("model.length", MAX_FIELDS),
sortedFields: sort("model", "fieldSortOrder"),
@ -53,18 +54,17 @@ export default Controller.extend({
// Only confirm if we already been saved
if (f.get("id")) {
bootbox.confirm(
I18n.t("admin.user_fields.delete_confirm"),
function (result) {
if (result) {
f.destroyRecord()
.then(function () {
model.removeObject(f);
})
.catch(popupAjaxError);
}
}
);
this.dialog.yesNoConfirm({
message: I18n.t("admin.user_fields.delete_confirm"),
didConfirm: () => {
return f
.destroyRecord()
.then(function () {
model.removeObject(f);
})
.catch(popupAjaxError);
},
});
} else {
model.removeObject(f);
}