0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-24 10:20:28 +01:00
discourse-custom-wizard/assets/javascripts/discourse/components/wizard-user-chooser.js

59 Zeilen
1,6 KiB
JavaScript

2024-07-09 11:26:34 +02:00
import I18n from "I18n";
2024-11-22 17:11:51 +01:00
import UserChooserComponent from "select-kit/components/user-chooser";
export const WIZARD_USER = "wizard-user";
export default UserChooserComponent.extend({
pluginApiIdentifiers: ["wizard-user-chooser"],
classNames: ["user-chooser", "wizard-user-chooser"],
classNameBindings: ["selectKit.options.fullWidthWrap:full-width-wrap"],
valueProperty: "id",
nameProperty: "name",
modifyComponentForRow() {
return "wizard-user-chooser/wizard-user-chooser-row";
},
modifyNoSelection() {
2024-07-09 11:26:34 +02:00
return this.defaultItem(
WIZARD_USER,
I18n.t("admin.wizard.action.poster.wizard_user")
);
},
selectKitOptions: {
fullWidthWrap: false,
autoWrap: false,
},
search() {
const superPromise = this._super(...arguments);
if (!superPromise) {
return;
}
return superPromise.then((results) => {
if (!results || results.length === 0) {
return;
}
return results.map((item) => {
const reconstructed = {};
if (item.username) {
reconstructed.id = item.username;
if (item.username.includes("@")) {
reconstructed.isEmail = true;
} else {
reconstructed.isUser = true;
reconstructed.name = item.name;
reconstructed.showUserStatus = this.showUserStatus;
}
} else if (item.name) {
reconstructed.id = item.name;
reconstructed.name = item.full_name;
reconstructed.isGroup = true;
}
return { ...item, ...reconstructed };
});
});
},
});