From 83fe8ea02bb5d415c07ac95eaf864149edf1b6d4 Mon Sep 17 00:00:00 2001 From: or-else Date: Tue, 8 Aug 2017 11:16:50 +0300 Subject: [PATCH] refactoring permissions editor --- css/base.css | 14 ++++-- index.html | 123 ++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 109 insertions(+), 28 deletions(-) diff --git a/css/base.css b/css/base.css index 7ab5950d..3c594ed6 100644 --- a/css/base.css +++ b/css/base.css @@ -393,21 +393,29 @@ ul.menu > li.separator:hover { } /* END of InPlaceEdit styles */ -ul.permission-editor { - list-style-type: none; +table.permission-editor { + width: 100%; } -ul.permission-editor > li { +table.permission-editor td { margin: 0.35rem 0; font-size: 1.1rem; vertical-align: middle; } +table.permission-editor td.checkbox { + text-align: center; +} + .permission-editor .material-icons { font-size: 1.1rem; line-height: 1.1rem; vertical-align: middle; +} + +.material-icons.clickable { cursor: pointer; + border-bottom: none; } .clickable { diff --git a/index.html b/index.html index 3d40dbe7..f3ffa6a9 100644 --- a/index.html +++ b/index.html @@ -358,7 +358,6 @@ class CheckBox extends React.PureComponent { constructor(props) { super(props); - this.handleChange = this.handleChange.bind(this); } @@ -368,9 +367,15 @@ render() { return ( - this.props.checked ? - check_box : - check_box_outline_blank + this.props.onChange ? ( + this.props.checked ? + check_box : + check_box_outline_blank + ) : ( + this.props.checked ? + check_box : + check_box_outline_blank + ) ); } } @@ -381,7 +386,7 @@ var PermissionsEditor = React.createClass({ getInitialState: function() { return { - mode: (this.props.mode || "").replace("N", "") + mode: this.props.mode }; }, @@ -421,8 +426,10 @@ 'D': 'Delete (D)', 'O': 'Owner (O)' }; + var skip = this.props.skip || ""; - var mode = this.state.mode || ""; + var mode = (this.state.mode || "").replace("N", ""); + var compare = (this.props.compare || "").replace("N", ""); var items = []; for (var i=0; i -1)} onChange={this.handleChange}/> {names[c]} + + {names[c]} + + -1)} onChange={this.handleChange}/> + {this.props.compare ? + -1)}/> + : null} + ); } return (
-
    + + {this.props.compare ? + + + + : + null} + {items} - +
    {this.props.modeTitle}{this.props.compareTitle}

    @@ -1632,6 +1652,8 @@ selectedContact: null, muted: undefined, access: null, + modeGiven: null, + modeWant: null, auth: null, anon: null, contactList: [], @@ -1689,6 +1711,8 @@ address: topic.name, groupTopic: (topic.getType() === "grp"), access: acs.getMode(), + modeGiven: acs.getGiven(), + modeWant: acs.getWant(), auth: defacs.auth, anon: defacs.anon }); @@ -1740,25 +1764,64 @@ this.props.onChangePermissions(this.props.topic, checked ? "-P" : "+P"); }, - handlePermissionsChanged: function(perm) { - if (this.state.showPermissionEditorFor === 'auth') { - this.props.onTopicDescUpdate(this.props.topic, null, null, {auth: perm}); - } else if (this.state.showPermissionEditorFor === 'anon') { - this.props.onTopicDescUpdate(this.props.topic, null, null, {anon: perm}); - } else if (this.state.showPermissionEditorFor === 'mode') { - this.props.onChangePermissions(this.props.topic, perm); + handlePermissionsChanged: function(perm, uid) { + switch (this.state.showPermissionEditorFor) { + case 'auth': + this.props.onTopicDescUpdate(this.props.topic, null, null, {auth: perm}); + break; + case 'anon': + this.props.onTopicDescUpdate(this.props.topic, null, null, {anon: perm}); + break; + case 'mode': + case 'want': + this.props.onChangePermissions(this.props.topic, perm); + break; + case 'given': + this.props.onChangePermissions(this.props.topic, perm, uid); + break; } this.setState({showPermissionEditorFor: undefined}); }, handleLaunchPermissionsEditor: function(which) { + var toEdit, toCompare, toSkip, titleEdit, titleCompare; + switch (which) { + case 'mode': + toEdit = this.state.access; + break; + case 'want': + toEdit = this.state.modeWant; + toCompare = this.state.modeGiven; + toSkip ='O'; + titleEdit = 'Requested'; + titleCompare = 'Granted'; + break; + case 'given': + toEdit = this.state.modeGiven; + toCompare = this.state.modeWant; + titleEdit = 'Granted'; + titleCompare = 'Requested'; + break; + case 'auth': + toEdit = this.state.auth; + toSkip = 'O'; + break; + case 'anon': + toEdit = this.state.auth; + toSkip = 'O'; + break; + default: + console.log("Unknown permission editing mode '" + which + "'"); + break; + } this.setState({ showPermissionEditorFor: which, - editedPermissions: which === 'mode' ? - this.state.access : - which === 'auth' ? this.state.auth : this.state.anon, - editedPermissionsSkipped: "O" + editedPermissions: toEdit, + immutablePermissions: toCompare, + editedPermissionsTitle: titleEdit, + immutablePermissionsTitle: titleCompare, + editedPermissionsSkipped: toSkip }); }, @@ -1813,6 +1876,10 @@ this.state.showPermissionEditorFor ? + onClick={this.handleLaunchPermissionsEditor.bind(this, 'want')}> {this.state.access}
    @@ -2619,12 +2686,18 @@ } }, - handleChangePermissions: function(topicName, want) { + handleChangePermissions: function(topicName, mode, uid) { var topic = Tinode.getTopic(topicName); if (topic) { var am = topic.getAccessMode(); - am.updateWant(want); - topic.setMeta({sub: {mode: am.getWant()}}); + if (uid) { + am.updateGiven(mode); + mode = am.getGiven(); + } else { + am.updateWant(mode); + mode = am.getWant(); + } + topic.setMeta({sub: {user: uid, mode: mode}}); } },