import spinner from "templates/spinner.js"; import { __ } from 'i18n'; import { html } from "lit"; function getRoleHelpText (role) { if (role === 'moderator') { return __("Moderators are privileged users who can change the roles of other users (except those with admin or owner affiliations."); } else if (role === 'participant') { return __("The default role, implies that you can read and write messages."); } else if (role == 'visitor') { return __("Visitors aren't allowed to write messages in a moderated multi-user chat."); } } function getAffiliationHelpText (aff) { if (aff === 'owner') { return __("Owner is the highest affiliation. Owners can modify roles and affiliations of all other users."); } else if (aff === 'admin') { return __("Admin is the 2nd highest affiliation. Admins can modify roles and affiliations of all other users except owners."); } else if (aff === 'outcast') { return __("To ban a user, you give them the affiliation of \"outcast\"."); } } const role_option = (o) => html` `; const affiliation_option = (o) => html` `; const tplRoleFormToggle = (o) => html` `; const tplRoleListItem = (el, o) => html`
  • `; const affiliation_form_toggle = (o) => html` `; const affiliation_list_item = (el, o) => html`
  • `; const tplNavigation = (o) => html` `; export default (el, o) => { const i18n_affiliation = __('Affiliation'); const i18n_no_users_with_aff = __('No users with that affiliation found.') const i18n_no_users_with_role = __('No users with that role found.'); const i18n_filter = __('Type here to filter the search results'); const i18n_role = __('Role'); const i18n_show_users = __('Show users'); const i18n_helptext_role = __( "Roles are assigned to users to grant or deny them certain abilities in a multi-user chat. "+ "They're assigned either explicitly or implicitly as part of an affiliation. "+ "A role that's not due to an affiliation, is only valid for the duration of the user's session." ); const i18n_helptext_affiliation = __( "An affiliation is a long-lived entitlement which typically implies a certain role and which "+ "grants privileges and responsibilities. For example admins and owners automatically have the "+ "moderator role." ); const show_both_tabs = o.queryable_roles.length && o.queryable_affiliations.length; return html` ${o.alert_message ? html`` : '' } ${ show_both_tabs ? tplNavigation(o) : '' }
    ${ o.queryable_affiliations.length ? html`

    ${i18n_helptext_affiliation}

    ${ (Array.isArray(o.users_with_affiliation) && o.users_with_affiliation.length > 5) ? html`` : '' }
    ${ getAffiliationHelpText(o.affiliation) ? html`

    ${getAffiliationHelpText(o.affiliation)}

    ` : '' }
      ${ (o.loading_users_with_affiliation) ? html`
    • ${spinner()}
    • ` : '' } ${ (Array.isArray(o.users_with_affiliation) && o.users_with_affiliation.length === 0) ? html`
    • ${i18n_no_users_with_aff}
    • ` : '' } ${ (o.users_with_affiliation instanceof Error) ? html`
    • ${o.users_with_affiliation.message}
    • ` : (o.users_with_affiliation || []).map(item => ((item.nick || item.jid).match(new RegExp(o.affiliations_filter, 'i')) ? affiliation_list_item(el, Object.assign({item}, o)) : '')) }
    ` : '' } ${ o.queryable_roles.length ? html`

    ${i18n_helptext_role}

    ${ (Array.isArray(o.users_with_role) && o.users_with_role.length > 5) ? html`` : '' }
    ${ getRoleHelpText(o.role) ? html`

    ${getRoleHelpText(o.role)}

    ` : ''}
      ${ o.loading_users_with_role ? html`
    • ${spinner()}
    • ` : '' } ${ (o.users_with_role && o.users_with_role.length === 0) ? html`
    • ${i18n_no_users_with_role}
    • ` : '' } ${ (o.users_with_role || []).map(item => (item.nick.match(o.roles_filter) ? tplRoleListItem(el, Object.assign({item}, o)) : '')) }
    `: '' }
    `; }