Merge branch 'luke/fix-member-info-power-level-display' into luke/fix-restrict-power-level-options

This commit is contained in:
Luke Barnard 2017-11-14 12:41:36 +00:00
commit c3492634bd
2 changed files with 19 additions and 21 deletions

View file

@ -46,7 +46,6 @@ module.exports = React.createClass({
getInitialState: function() {
return {
levelRoleMap: {},
reverseRoles: {},
// List of power levels to show in the drop-down
options: [],
};
@ -70,17 +69,12 @@ module.exports = React.createClass({
_initStateFromProps: function(newProps, initial) {
// This needs to be done now because levelRoleMap has translated strings
const levelRoleMap = Roles.levelRoleMap(newProps.usersDefault);
const reverseRoles = {};
Object.keys(levelRoleMap).forEach(function(key) {
reverseRoles[levelRoleMap[key]] = key;
});
const options = Object.keys(levelRoleMap).filter((l) => {
return l === undefined || l <= newProps.maxValue;
});
this.setState({
levelRoleMap,
reverseRoles,
options,
});
@ -92,8 +86,8 @@ module.exports = React.createClass({
},
onSelectChange: function(event) {
this.setState({ custom: event.target.value === "Custom" });
if (event.target.value !== "Custom") {
this.setState({ custom: event.target.value === "SELECT_VALUE_CUSTOM" });
if (event.target.value !== "SELECT_VALUE_CUSTOM") {
this.props.onChange(this.getValue());
}
},
@ -109,14 +103,13 @@ module.exports = React.createClass({
},
getValue: function() {
let value;
if (this.refs.select) {
value = this.state.reverseRoles[this.refs.select.value];
if (this.refs.custom) {
if (value === undefined) value = parseInt( this.refs.custom.value );
}
if (this.refs.custom) {
return parseInt(this.refs.custom.value);
}
return value;
if (this.refs.select) {
return this.refs.select.value;
}
return undefined;
},
render: function() {
@ -124,7 +117,10 @@ module.exports = React.createClass({
if (this.state.custom) {
let input;
if (this.props.disabled) {
input = <span>{ this.props.value }</span>;
input = <span>{ _t(
"Custom of %(powerLevel)s",
{ powerLevel: this.props.value },
) }</span>;
} else {
input = <input
ref="custom"
@ -140,22 +136,23 @@ module.exports = React.createClass({
let selectValue;
if (this.state.custom) {
selectValue = "Custom";
selectValue = "SELECT_VALUE_CUSTOM";
} else {
selectValue = this.state.levelRoleMap[this.props.value] || "Custom";
selectValue = this.state.levelRoleMap[selectValue] ?
this.props.value : "SELECT_VALUE_CUSTOM";
}
let select;
if (this.props.disabled) {
select = <span>{ selectValue }</span>;
select = <span>{ this.state.levelRoleMap[selectValue] }</span>;
} else {
// Each level must have a definition in this.state.levelRoleMap
let options = this.state.options.map((level) => {
return {
value: this.state.levelRoleMap[level],
value: level,
text: Roles.textualPowerLevel(level, this.props.usersDefault),
};
});
options.push({ value: "Custom", text: _t("Custom level") });
options.push({ value: "SELECT_VALUE_CUSTOM", text: _t("Custom level") });
options = options.map((op) => {
return <option value={op.value} key={op.value}>{ op.text }</option>;
});

View file

@ -580,6 +580,7 @@
"%(items)s and %(count)s others|other": "%(items)s and %(count)s others",
"%(items)s and %(count)s others|one": "%(items)s and one other",
"%(items)s and %(lastItem)s": "%(items)s and %(lastItem)s",
"Custom of %(powerLevel)s": "Custom of %(powerLevel)s",
"Custom level": "Custom level",
"Room directory": "Room directory",
"Start chat": "Start chat",