diff --git a/src/components/views/elements/PowerSelector.js b/src/components/views/elements/PowerSelector.js index 6a31259494..2d90711739 100644 --- a/src/components/views/elements/PowerSelector.js +++ b/src/components/views/elements/PowerSelector.js @@ -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 = { this.props.value }; + input = { _t( + "Custom of %(powerLevel)s", + { powerLevel: this.props.value }, + ) }; } else { input = { selectValue }; + select = { this.state.levelRoleMap[selectValue] }; } 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 ; }); diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index ae74da0a18..261299ad86 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -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",