mirror of
https://github.com/discourse/discourse.git
synced 2025-01-30 04:56:06 +08:00
DEV: migrates username-preference to gjs (#27864)
This commit is contained in:
parent
015a38d014
commit
5cdd6d7c37
|
@ -1,13 +1,19 @@
|
||||||
import Component from "@glimmer/component";
|
import Component from "@glimmer/component";
|
||||||
import { tracked } from "@glimmer/tracking";
|
import { tracked } from "@glimmer/tracking";
|
||||||
|
import { Input } from "@ember/component";
|
||||||
|
import { on } from "@ember/modifier";
|
||||||
import { action } from "@ember/object";
|
import { action } from "@ember/object";
|
||||||
import { empty, or } from "@ember/object/computed";
|
import { empty, or } from "@ember/object/computed";
|
||||||
import { service } from "@ember/service";
|
import { service } from "@ember/service";
|
||||||
|
import { htmlSafe } from "@ember/template";
|
||||||
import { isEmpty } from "@ember/utils";
|
import { isEmpty } from "@ember/utils";
|
||||||
|
import DButton from "discourse/components/d-button";
|
||||||
|
import DModalCancel from "discourse/components/d-modal-cancel";
|
||||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||||
import { setting } from "discourse/lib/computed";
|
import { setting } from "discourse/lib/computed";
|
||||||
import DiscourseURL, { userPath } from "discourse/lib/url";
|
import DiscourseURL, { userPath } from "discourse/lib/url";
|
||||||
import User from "discourse/models/user";
|
import User from "discourse/models/user";
|
||||||
|
import i18n from "discourse-common/helpers/i18n";
|
||||||
import I18n from "discourse-i18n";
|
import I18n from "discourse-i18n";
|
||||||
|
|
||||||
export default class UsernamePreference extends Component {
|
export default class UsernamePreference extends Component {
|
||||||
|
@ -97,4 +103,65 @@ export default class UsernamePreference extends Component {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<template>
|
||||||
|
{{#if this.editing}}
|
||||||
|
<form class="form-horizontal">
|
||||||
|
<div class="control-group">
|
||||||
|
<Input
|
||||||
|
{{on "input" this.onInput}}
|
||||||
|
@value={{this.newUsername}}
|
||||||
|
maxlength={{this.maxLength}}
|
||||||
|
class="input-xxlarge username-preference__input"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div class="instructions">
|
||||||
|
<p>
|
||||||
|
{{#if this.taken}}
|
||||||
|
{{i18n "user.change_username.taken"}}
|
||||||
|
{{/if}}
|
||||||
|
<span>{{this.errorMessage}}</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="control-group">
|
||||||
|
<DButton
|
||||||
|
@action={{this.changeUsername}}
|
||||||
|
@disabled={{this.saveDisabled}}
|
||||||
|
@translatedLabel={{this.saveButtonText}}
|
||||||
|
type="submit"
|
||||||
|
class="btn-primary username-preference__submit"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<DModalCancel @close={{this.toggleEditing}} />
|
||||||
|
|
||||||
|
{{#if this.saved}}{{i18n "saved"}}{{/if}}
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
{{else}}
|
||||||
|
<div class="controls">
|
||||||
|
<span
|
||||||
|
class="static username-preference__current-username"
|
||||||
|
>{{@user.username}}</span>
|
||||||
|
|
||||||
|
{{#if @user.can_edit_username}}
|
||||||
|
<DButton
|
||||||
|
@action={{this.toggleEditing}}
|
||||||
|
@icon="pencil-alt"
|
||||||
|
@title="user.username.edit"
|
||||||
|
class="btn-small username-preference__edit-username"
|
||||||
|
/>
|
||||||
|
{{/if}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{#if this.siteSettings.enable_mentions}}
|
||||||
|
<div class="instructions">
|
||||||
|
{{htmlSafe
|
||||||
|
(i18n "user.username.short_instructions" username=@user.username)
|
||||||
|
}}
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
{{/if}}
|
||||||
|
</template>
|
||||||
}
|
}
|
|
@ -1,58 +0,0 @@
|
||||||
{{#if this.editing}}
|
|
||||||
<form class="form-horizontal">
|
|
||||||
<div class="control-group">
|
|
||||||
<Input
|
|
||||||
{{on "input" this.onInput}}
|
|
||||||
@value={{this.newUsername}}
|
|
||||||
maxlength={{this.maxLength}}
|
|
||||||
class="input-xxlarge username-preference__input"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div class="instructions">
|
|
||||||
<p>
|
|
||||||
{{#if this.taken}}
|
|
||||||
{{i18n "user.change_username.taken"}}
|
|
||||||
{{/if}}
|
|
||||||
<span>{{this.errorMessage}}</span>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="control-group">
|
|
||||||
<DButton
|
|
||||||
@action={{this.changeUsername}}
|
|
||||||
@disabled={{this.saveDisabled}}
|
|
||||||
@translatedLabel={{this.saveButtonText}}
|
|
||||||
type="submit"
|
|
||||||
class="btn-primary username-preference__submit"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<DModalCancel @close={{this.toggleEditing}} />
|
|
||||||
|
|
||||||
{{#if this.saved}}{{i18n "saved"}}{{/if}}
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
{{else}}
|
|
||||||
<div class="controls">
|
|
||||||
<span
|
|
||||||
class="static username-preference__current-username"
|
|
||||||
>{{@user.username}}</span>
|
|
||||||
|
|
||||||
{{#if @user.can_edit_username}}
|
|
||||||
<DButton
|
|
||||||
@action={{fn this.toggleEditing @user}}
|
|
||||||
@icon="pencil-alt"
|
|
||||||
@title="user.username.edit"
|
|
||||||
class="btn-small username-preference__edit-username"
|
|
||||||
/>
|
|
||||||
{{/if}}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{{#if this.siteSettings.enable_mentions}}
|
|
||||||
<div class="instructions">
|
|
||||||
{{html-safe
|
|
||||||
(i18n "user.username.short_instructions" username=@user.username)
|
|
||||||
}}
|
|
||||||
</div>
|
|
||||||
{{/if}}
|
|
||||||
{{/if}}
|
|
Loading…
Reference in New Issue
Block a user