0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-22 17:30:29 +01:00
discourse-custom-wizard/assets/javascripts/discourse/components/wizard-user-chooser.js.es6

59 Zeilen
1,6 KiB
Text

import UserChooserComponent from "select-kit/components/user-chooser";
2024-07-09 11:26:34 +02:00
import I18n from "I18n";
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 };
});
});
},
});