Merge branch 'luke/fix-member-info-power-level-display' into luke/fix-restrict-power-level-options
This commit is contained in:
commit
c3492634bd
2 changed files with 19 additions and 21 deletions
|
@ -46,7 +46,6 @@ module.exports = React.createClass({
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
return {
|
return {
|
||||||
levelRoleMap: {},
|
levelRoleMap: {},
|
||||||
reverseRoles: {},
|
|
||||||
// List of power levels to show in the drop-down
|
// List of power levels to show in the drop-down
|
||||||
options: [],
|
options: [],
|
||||||
};
|
};
|
||||||
|
@ -70,17 +69,12 @@ module.exports = React.createClass({
|
||||||
_initStateFromProps: function(newProps, initial) {
|
_initStateFromProps: function(newProps, initial) {
|
||||||
// This needs to be done now because levelRoleMap has translated strings
|
// This needs to be done now because levelRoleMap has translated strings
|
||||||
const levelRoleMap = Roles.levelRoleMap(newProps.usersDefault);
|
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) => {
|
const options = Object.keys(levelRoleMap).filter((l) => {
|
||||||
return l === undefined || l <= newProps.maxValue;
|
return l === undefined || l <= newProps.maxValue;
|
||||||
});
|
});
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
levelRoleMap,
|
levelRoleMap,
|
||||||
reverseRoles,
|
|
||||||
options,
|
options,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -92,8 +86,8 @@ module.exports = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
onSelectChange: function(event) {
|
onSelectChange: function(event) {
|
||||||
this.setState({ custom: event.target.value === "Custom" });
|
this.setState({ custom: event.target.value === "SELECT_VALUE_CUSTOM" });
|
||||||
if (event.target.value !== "Custom") {
|
if (event.target.value !== "SELECT_VALUE_CUSTOM") {
|
||||||
this.props.onChange(this.getValue());
|
this.props.onChange(this.getValue());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -109,14 +103,13 @@ module.exports = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
getValue: function() {
|
getValue: function() {
|
||||||
let value;
|
if (this.refs.custom) {
|
||||||
if (this.refs.select) {
|
return parseInt(this.refs.custom.value);
|
||||||
value = this.state.reverseRoles[this.refs.select.value];
|
|
||||||
if (this.refs.custom) {
|
|
||||||
if (value === undefined) value = parseInt( this.refs.custom.value );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return value;
|
if (this.refs.select) {
|
||||||
|
return this.refs.select.value;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
|
@ -124,7 +117,10 @@ module.exports = React.createClass({
|
||||||
if (this.state.custom) {
|
if (this.state.custom) {
|
||||||
let input;
|
let input;
|
||||||
if (this.props.disabled) {
|
if (this.props.disabled) {
|
||||||
input = <span>{ this.props.value }</span>;
|
input = <span>{ _t(
|
||||||
|
"Custom of %(powerLevel)s",
|
||||||
|
{ powerLevel: this.props.value },
|
||||||
|
) }</span>;
|
||||||
} else {
|
} else {
|
||||||
input = <input
|
input = <input
|
||||||
ref="custom"
|
ref="custom"
|
||||||
|
@ -140,22 +136,23 @@ module.exports = React.createClass({
|
||||||
|
|
||||||
let selectValue;
|
let selectValue;
|
||||||
if (this.state.custom) {
|
if (this.state.custom) {
|
||||||
selectValue = "Custom";
|
selectValue = "SELECT_VALUE_CUSTOM";
|
||||||
} else {
|
} else {
|
||||||
selectValue = this.state.levelRoleMap[this.props.value] || "Custom";
|
selectValue = this.state.levelRoleMap[selectValue] ?
|
||||||
|
this.props.value : "SELECT_VALUE_CUSTOM";
|
||||||
}
|
}
|
||||||
let select;
|
let select;
|
||||||
if (this.props.disabled) {
|
if (this.props.disabled) {
|
||||||
select = <span>{ selectValue }</span>;
|
select = <span>{ this.state.levelRoleMap[selectValue] }</span>;
|
||||||
} else {
|
} else {
|
||||||
// Each level must have a definition in this.state.levelRoleMap
|
// Each level must have a definition in this.state.levelRoleMap
|
||||||
let options = this.state.options.map((level) => {
|
let options = this.state.options.map((level) => {
|
||||||
return {
|
return {
|
||||||
value: this.state.levelRoleMap[level],
|
value: level,
|
||||||
text: Roles.textualPowerLevel(level, this.props.usersDefault),
|
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) => {
|
options = options.map((op) => {
|
||||||
return <option value={op.value} key={op.value}>{ op.text }</option>;
|
return <option value={op.value} key={op.value}>{ op.text }</option>;
|
||||||
});
|
});
|
||||||
|
|
|
@ -580,6 +580,7 @@
|
||||||
"%(items)s and %(count)s others|other": "%(items)s and %(count)s others",
|
"%(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 %(count)s others|one": "%(items)s and one other",
|
||||||
"%(items)s and %(lastItem)s": "%(items)s and %(lastItem)s",
|
"%(items)s and %(lastItem)s": "%(items)s and %(lastItem)s",
|
||||||
|
"Custom of %(powerLevel)s": "Custom of %(powerLevel)s",
|
||||||
"Custom level": "Custom level",
|
"Custom level": "Custom level",
|
||||||
"Room directory": "Room directory",
|
"Room directory": "Room directory",
|
||||||
"Start chat": "Start chat",
|
"Start chat": "Start chat",
|
||||||
|
|
Loading…
Reference in a new issue