Radio buttons now added, and only none guests can modify notfication state

This commit is contained in:
wmwragg 2016-07-26 10:34:03 +01:00
parent 30b1e7078f
commit 187818aaa0
1 changed files with 28 additions and 36 deletions

View File

@ -46,22 +46,6 @@ module.exports = React.createClass({
}; };
}, },
onAllClick: function() {
if (this.props.onFinished) {
this.setState({areNotifsMuted: false});
this._save(false);
this.props.onFinished();
}
},
onMuteClick: function() {
if (this.props.onFinished) {
this.setState({areNotifsMuted: true});
this._save(true);
this.props.onFinished();
}
},
_save: function( isMuted ) { _save: function( isMuted ) {
const roomId = this.props.room.roomId; const roomId = this.props.room.roomId;
/* /*
@ -71,35 +55,43 @@ module.exports = React.createClass({
)); ));
} }
*/ */
MatrixClientPeg.get().setRoomMutePushRule( var cli = MatrixClientPeg.get();
"global", roomId, isMuted this.setState({areNotifsMuted: isMuted});
); if (!cli.isGuest()) {
cli.setRoomMutePushRule(
"global", roomId, isMuted
);
}
}, },
_onToggle: function(keyName, checkedValue, uncheckedValue, ev) { _onToggle: function(ev) {
console.log("Checkbox toggle: %s %s", keyName, ev.target.checked); switch (ev.target.value) {
var state = {}; case "all":
state[keyName] = ev.target.checked ? checkedValue : uncheckedValue; if (this.props.onFinished) {
this.setState(state); this._save(false);
this.props.onFinished();
}
break;
case "mute":
if (this.props.onFinished) {
this._save(true);
this.props.onFinished();
}
break;
}
}, },
render: function() { render: function() {
var cli = MatrixClientPeg.get(); var cli = MatrixClientPeg.get();
return ( return (
<div> <div>
{/* <div className="mx_ContextualMenu_field" >
<div className="mx_ContextualMenu_field"> <input disabled={cli.isGuest()} type="radio" name="notification_state" value="all" onChange={this._onToggle} checked={!this.state.areNotifsMuted}/>
<input type="checkbox" disabled={ cli.isGuest() } All notifications
onChange={this._onToggle.bind(this, "areNotifsMuted", true, false)}
defaultChecked={this.state.areNotifsMuted}/>
Mute notifications for this room
</div> </div>
*/} <div className="mx_ContextualMenu_field" >
<div className="mx_ContextualMenu_field" onClick={ this.onAllClick }> <input disabled={cli.isGuest()} type="radio" name="notification_state" value="mute" onChange={this._onToggle} checked={this.state.areNotifsMuted}/>
All notifications - { this.state.areNotifsMuted ? "OFF" : "ON" } Mute
</div>
<div className="mx_ContextualMenu_field" onClick={ this.onMuteClick }>
Mute - { this.state.areNotifsMuted ? "ON" : "OFF" }
</div> </div>
</div> </div>
); );