mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 14:33:43 +08:00
c34f8b65cb
As of #23867 this is now a real package, so updating the imports to use the real package name, rather than relying on the alias. The name change in the package name is because `I18n` is not a valid name as NPM packages must be all lowercase. This commit also introduces an eslint rule to prevent importing from the old I18n path. For themes/plugins, the old 'i18n' name remains functional.
82 lines
1.9 KiB
JavaScript
82 lines
1.9 KiB
JavaScript
import Controller from "@ember/controller";
|
|
import { action } from "@ember/object";
|
|
import { gte, sort } from "@ember/object/computed";
|
|
import { inject as service } from "@ember/service";
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
|
import I18n from "discourse-i18n";
|
|
|
|
const MAX_FIELDS = 30;
|
|
|
|
export default class AdminUserFieldsController extends Controller {
|
|
@service dialog;
|
|
|
|
fieldTypes = null;
|
|
fieldSortOrder = ["position"];
|
|
|
|
@gte("model.length", MAX_FIELDS) createDisabled;
|
|
@sort("model", "fieldSortOrder") sortedFields;
|
|
|
|
get firstField() {
|
|
return this.sortedFields[0];
|
|
}
|
|
|
|
get lastField() {
|
|
return this.sortedFields[this.sortedFields.length - 1];
|
|
}
|
|
|
|
@action
|
|
createField() {
|
|
const f = this.store.createRecord("user-field", {
|
|
field_type: "text",
|
|
position: MAX_FIELDS,
|
|
});
|
|
this.model.pushObject(f);
|
|
}
|
|
|
|
@action
|
|
moveUp(f) {
|
|
const idx = this.sortedFields.indexOf(f);
|
|
if (idx) {
|
|
const prev = this.sortedFields.objectAt(idx - 1);
|
|
const prevPos = prev.get("position");
|
|
|
|
prev.update({ position: f.get("position") });
|
|
f.update({ position: prevPos });
|
|
}
|
|
}
|
|
|
|
@action
|
|
moveDown(f) {
|
|
const idx = this.sortedFields.indexOf(f);
|
|
if (idx > -1) {
|
|
const next = this.sortedFields.objectAt(idx + 1);
|
|
const nextPos = next.get("position");
|
|
|
|
next.update({ position: f.get("position") });
|
|
f.update({ position: nextPos });
|
|
}
|
|
}
|
|
|
|
@action
|
|
destroyField(f) {
|
|
const model = this.model;
|
|
|
|
// Only confirm if we already been saved
|
|
if (f.get("id")) {
|
|
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);
|
|
}
|
|
}
|
|
}
|