REFACTOR: admin-user-field-item (#7016)
This commit is contained in:
parent
ee692414ce
commit
3bf61fca66
|
@ -2,6 +2,12 @@ import UserField from "admin/models/user-field";
|
||||||
import { bufferedProperty } from "discourse/mixins/buffered-content";
|
import { bufferedProperty } from "discourse/mixins/buffered-content";
|
||||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||||
import { propertyEqual } from "discourse/lib/computed";
|
import { propertyEqual } from "discourse/lib/computed";
|
||||||
|
import { i18n } from "discourse/lib/computed";
|
||||||
|
import {
|
||||||
|
default as computed,
|
||||||
|
observes,
|
||||||
|
on
|
||||||
|
} from "ember-addons/ember-computed-decorators";
|
||||||
|
|
||||||
export default Ember.Component.extend(bufferedProperty("userField"), {
|
export default Ember.Component.extend(bufferedProperty("userField"), {
|
||||||
editing: Ember.computed.empty("userField.id"),
|
editing: Ember.computed.empty("userField.id"),
|
||||||
|
@ -10,58 +16,56 @@ export default Ember.Component.extend(bufferedProperty("userField"), {
|
||||||
cantMoveUp: propertyEqual("userField", "firstField"),
|
cantMoveUp: propertyEqual("userField", "firstField"),
|
||||||
cantMoveDown: propertyEqual("userField", "lastField"),
|
cantMoveDown: propertyEqual("userField", "lastField"),
|
||||||
|
|
||||||
userFieldsDescription: function() {
|
userFieldsDescription: i18n("admin.user_fields.description"),
|
||||||
return I18n.t("admin.user_fields.description");
|
|
||||||
}.property(),
|
|
||||||
|
|
||||||
bufferedFieldType: function() {
|
@computed("buffered.field_type")
|
||||||
return UserField.fieldTypeById(this.get("buffered.field_type"));
|
bufferedFieldType(fieldType) {
|
||||||
}.property("buffered.field_type"),
|
return UserField.fieldTypeById(fieldType);
|
||||||
|
},
|
||||||
|
|
||||||
_focusOnEdit: function() {
|
@on("didInsertElement")
|
||||||
|
@observes("editing")
|
||||||
|
_focusOnEdit() {
|
||||||
if (this.get("editing")) {
|
if (this.get("editing")) {
|
||||||
Ember.run.scheduleOnce("afterRender", this, "_focusName");
|
Ember.run.scheduleOnce("afterRender", this, "_focusName");
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
.observes("editing")
|
|
||||||
.on("didInsertElement"),
|
|
||||||
|
|
||||||
_focusName: function() {
|
_focusName() {
|
||||||
$(".user-field-name").select();
|
$(".user-field-name").select();
|
||||||
},
|
},
|
||||||
|
|
||||||
fieldName: function() {
|
@computed("userField.field_type")
|
||||||
return UserField.fieldTypeById(this.get("userField.field_type")).get(
|
fieldName(fieldType) {
|
||||||
"name"
|
return UserField.fieldTypeById(fieldType).get("name");
|
||||||
);
|
},
|
||||||
}.property("userField.field_type"),
|
|
||||||
|
|
||||||
flags: function() {
|
@computed(
|
||||||
const ret = [];
|
|
||||||
if (this.get("userField.editable")) {
|
|
||||||
ret.push(I18n.t("admin.user_fields.editable.enabled"));
|
|
||||||
}
|
|
||||||
if (this.get("userField.required")) {
|
|
||||||
ret.push(I18n.t("admin.user_fields.required.enabled"));
|
|
||||||
}
|
|
||||||
if (this.get("userField.show_on_profile")) {
|
|
||||||
ret.push(I18n.t("admin.user_fields.show_on_profile.enabled"));
|
|
||||||
}
|
|
||||||
if (this.get("userField.show_on_user_card")) {
|
|
||||||
ret.push(I18n.t("admin.user_fields.show_on_user_card.enabled"));
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret.join(", ");
|
|
||||||
}.property(
|
|
||||||
"userField.editable",
|
"userField.editable",
|
||||||
"userField.required",
|
"userField.required",
|
||||||
"userField.show_on_profile",
|
"userField.show_on_profile",
|
||||||
"userField.show_on_user_card"
|
"userField.show_on_user_card"
|
||||||
),
|
)
|
||||||
|
flags(editable, required, showOnProfile, showOnUserCard) {
|
||||||
|
const ret = [];
|
||||||
|
if (editable) {
|
||||||
|
ret.push(I18n.t("admin.user_fields.editable.enabled"));
|
||||||
|
}
|
||||||
|
if (required) {
|
||||||
|
ret.push(I18n.t("admin.user_fields.required.enabled"));
|
||||||
|
}
|
||||||
|
if (showOnProfile) {
|
||||||
|
ret.push(I18n.t("admin.user_fields.show_on_profile.enabled"));
|
||||||
|
}
|
||||||
|
if (showOnUserCard) {
|
||||||
|
ret.push(I18n.t("admin.user_fields.show_on_user_card.enabled"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret.join(", ");
|
||||||
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
save() {
|
save() {
|
||||||
const self = this;
|
|
||||||
const buffered = this.get("buffered");
|
const buffered = this.get("buffered");
|
||||||
const attrs = buffered.getProperties(
|
const attrs = buffered.getProperties(
|
||||||
"name",
|
"name",
|
||||||
|
@ -76,9 +80,9 @@ export default Ember.Component.extend(bufferedProperty("userField"), {
|
||||||
|
|
||||||
this.get("userField")
|
this.get("userField")
|
||||||
.save(attrs)
|
.save(attrs)
|
||||||
.then(function() {
|
.then(() => {
|
||||||
self.set("editing", false);
|
this.set("editing", false);
|
||||||
self.commitBuffer();
|
this.commitBuffer();
|
||||||
})
|
})
|
||||||
.catch(popupAjaxError);
|
.catch(popupAjaxError);
|
||||||
},
|
},
|
||||||
|
|
|
@ -18,19 +18,19 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{#admin-form-row wrapLabel="true"}}
|
{{#admin-form-row wrapLabel="true"}}
|
||||||
{{input type="checkbox" checked=buffered.editable}} {{i18n 'admin.user_fields.editable.title'}}
|
{{input type="checkbox" checked=buffered.editable}} {{i18n "admin.user_fields.editable.title"}}
|
||||||
{{/admin-form-row}}
|
{{/admin-form-row}}
|
||||||
|
|
||||||
{{#admin-form-row wrapLabel="true"}}
|
{{#admin-form-row wrapLabel="true"}}
|
||||||
{{input type="checkbox" checked=buffered.required}} {{i18n 'admin.user_fields.required.title'}}
|
{{input type="checkbox" checked=buffered.required}} {{i18n "admin.user_fields.required.title"}}
|
||||||
{{/admin-form-row}}
|
{{/admin-form-row}}
|
||||||
|
|
||||||
{{#admin-form-row wrapLabel="true"}}
|
{{#admin-form-row wrapLabel="true"}}
|
||||||
{{input type="checkbox" checked=buffered.show_on_profile}} {{i18n 'admin.user_fields.show_on_profile.title'}}
|
{{input type="checkbox" checked=buffered.show_on_profile}} {{i18n "admin.user_fields.show_on_profile.title"}}
|
||||||
{{/admin-form-row}}
|
{{/admin-form-row}}
|
||||||
|
|
||||||
{{#admin-form-row wrapLabel="true"}}
|
{{#admin-form-row wrapLabel="true"}}
|
||||||
{{input type="checkbox" checked=buffered.show_on_user_card}} {{i18n 'admin.user_fields.show_on_user_card.title'}}
|
{{input type="checkbox" checked=buffered.show_on_user_card}} {{i18n "admin.user_fields.show_on_user_card.title"}}
|
||||||
{{/admin-form-row}}
|
{{/admin-form-row}}
|
||||||
|
|
||||||
{{#admin-form-row}}
|
{{#admin-form-row}}
|
||||||
|
@ -39,15 +39,14 @@
|
||||||
{{/admin-form-row}}
|
{{/admin-form-row}}
|
||||||
{{else}}
|
{{else}}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class='form-display'>
|
<div class="form-display">
|
||||||
<strong>{{userField.name}}</strong>
|
<strong>{{userField.name}}</strong>
|
||||||
<br/>
|
<br/>
|
||||||
{{{userField.description}}}
|
{{{userField.description}}}
|
||||||
</div>
|
</div>
|
||||||
<div class='form-display'>{{fieldName}}</div>
|
<div class="form-display">{{fieldName}}</div>
|
||||||
<div class='form-element controls'>
|
<div class="form-element controls">
|
||||||
{{d-button action=(action "edit") class="btn-default" icon="pencil-alt" label="admin.user_fields.edit"}}
|
{{d-button action=(action "edit") class="btn-default" icon="pencil-alt" label="admin.user_fields.edit"}}
|
||||||
|
|
||||||
{{d-button action=destroyAction actionParam=userField class="btn-danger" icon="far-trash-alt" label="admin.user_fields.delete"}}
|
{{d-button action=destroyAction actionParam=userField class="btn-danger" icon="far-trash-alt" label="admin.user_fields.delete"}}
|
||||||
{{d-button action=moveUpAction actionParam=userField class="btn-default" icon="arrow-up" disabled=cantMoveUp}}
|
{{d-button action=moveUpAction actionParam=userField class="btn-default" icon="arrow-up" disabled=cantMoveUp}}
|
||||||
{{d-button action=moveDownAction actionParam=userField class="btn-default" icon="arrow-down" disabled=cantMoveDown}}
|
{{d-button action=moveDownAction actionParam=userField class="btn-default" icon="arrow-down" disabled=cantMoveDown}}
|
||||||
|
@ -55,4 +54,4 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="row">{{flags}}</div>
|
<div class="row">{{flags}}</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
<div class='clearfix'></div>
|
<div class="clearfix"></div>
|
||||||
|
|
Loading…
Reference in New Issue