mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-05 00:43:53 +00:00
permission explanation
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { Input } from 'reactstrap';
|
|
||||||
import { gettext } from '../../utils/constants';
|
import { gettext } from '../../utils/constants';
|
||||||
|
import Select from 'react-select';
|
||||||
|
import '../../css/select-editor.css';
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
isTextMode: PropTypes.bool.isRequired, // there will be two mode. first: text and select. second: just select
|
isTextMode: PropTypes.bool.isRequired, // there will be two mode. first: text and select. second: just select
|
||||||
@@ -9,6 +10,7 @@ const propTypes = {
|
|||||||
options: PropTypes.array.isRequired,
|
options: PropTypes.array.isRequired,
|
||||||
currentOption: PropTypes.string.isRequired,
|
currentOption: PropTypes.string.isRequired,
|
||||||
translateOption: PropTypes.func.isRequired,
|
translateOption: PropTypes.func.isRequired,
|
||||||
|
translateExplanation: PropTypes.func,
|
||||||
onOptionChanged: PropTypes.func.isRequired,
|
onOptionChanged: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -19,24 +21,36 @@ class SelectEditor extends React.Component {
|
|||||||
this.state = {
|
this.state = {
|
||||||
isEditing: false,
|
isEditing: false,
|
||||||
}
|
}
|
||||||
|
this.options = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
document.addEventListener('click', this.onHideSelect);
|
document.addEventListener('click', this.onHideSelect);
|
||||||
|
this.setOptions();
|
||||||
|
}
|
||||||
|
|
||||||
|
setOptions = () => {
|
||||||
|
this.options = [];
|
||||||
|
const options = this.props.options;
|
||||||
|
for (let i = 0, length = options.length; i < length; i++) {
|
||||||
|
let option = {};
|
||||||
|
option.value = options[i];
|
||||||
|
option.label = <div>{this.props.translateOption(options[i])}{ this.props.translateExplanation && <div className="permission-editor-explanation">{this.props.translateExplanation(options[i])}</div>}</div>;
|
||||||
|
this.options.push(option);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
document.removeEventListener('click', this.onHideSelect);
|
document.removeEventListener('click', this.onHideSelect);
|
||||||
}
|
}
|
||||||
|
|
||||||
onEidtPermission = (e) => {
|
onEditPermission = (e) => {
|
||||||
e.nativeEvent.stopImmediatePropagation();
|
e.nativeEvent.stopImmediatePropagation();
|
||||||
this.setState({isEditing: true});
|
this.setState({isEditing: true});
|
||||||
}
|
}
|
||||||
|
|
||||||
onOptionChanged = (e) => {
|
onOptionChanged = (e) => {
|
||||||
e.nativeEvent.stopImmediatePropagation();
|
let permission = e.value;
|
||||||
let permission = e.target.value;
|
|
||||||
if (permission !== this.props.currentOption) {
|
if (permission !== this.props.currentOption) {
|
||||||
this.props.onOptionChanged(permission);
|
this.props.onOptionChanged(permission);
|
||||||
}
|
}
|
||||||
@@ -56,23 +70,16 @@ class SelectEditor extends React.Component {
|
|||||||
|
|
||||||
// scence1: isTextMode (text)editor-icon --> select
|
// scence1: isTextMode (text)editor-icon --> select
|
||||||
// scence2: !isTextMode select
|
// scence2: !isTextMode select
|
||||||
let selectStyle = {
|
|
||||||
height: '1.5rem',
|
|
||||||
padding: 0
|
|
||||||
};
|
|
||||||
if (!isTextMode) {
|
|
||||||
selectStyle = {};
|
|
||||||
}
|
|
||||||
return (
|
return (
|
||||||
<div className="permission-editor">
|
<div className="permission-editor" onClick={this.onSelectHandler}>
|
||||||
{(!isTextMode || this.state.isEditing) &&
|
{(!isTextMode || this.state.isEditing) &&
|
||||||
<Input style={selectStyle} type="select" onChange={this.onOptionChanged} onClick={this.onSelectHandler} value={currentOption}>
|
<Select
|
||||||
{options.map((item, index) => {
|
options={this.options}
|
||||||
return (
|
className="permission-editor-select"
|
||||||
<option key={index} value={item}>{this.props.translateOption(item)}</option>
|
classNamePrefix="select"
|
||||||
);
|
onChange={this.onOptionChanged}
|
||||||
})}
|
menuPlacement="auto"
|
||||||
</Input>
|
/>
|
||||||
}
|
}
|
||||||
{(isTextMode && !this.state.isEditing) &&
|
{(isTextMode && !this.state.isEditing) &&
|
||||||
<div>
|
<div>
|
||||||
@@ -81,7 +88,7 @@ class SelectEditor extends React.Component {
|
|||||||
<span
|
<span
|
||||||
title={gettext('Edit')}
|
title={gettext('Edit')}
|
||||||
className="fa fa-pencil attr-action-icon"
|
className="fa fa-pencil attr-action-icon"
|
||||||
onClick={this.onEidtPermission}>
|
onClick={this.onEditPermission}>
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
@@ -17,6 +17,10 @@ class SharePermissionEditor extends React.Component {
|
|||||||
return Utils.sharePerms(permission);
|
return Utils.sharePerms(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
translateExplanation = (explanation) => {
|
||||||
|
return Utils.sharePermsExplanation(explanation);
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<SelectEditor
|
<SelectEditor
|
||||||
@@ -26,6 +30,7 @@ class SharePermissionEditor extends React.Component {
|
|||||||
currentOption={this.props.currentPermission}
|
currentOption={this.props.currentPermission}
|
||||||
onOptionChanged={this.props.onPermissionChanged}
|
onOptionChanged={this.props.onPermissionChanged}
|
||||||
translateOption={this.translatePermission}
|
translateOption={this.translatePermission}
|
||||||
|
translateExplanation={this.translateExplanation}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
16
frontend/src/css/select-editor.css
Normal file
16
frontend/src/css/select-editor.css
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
.permission-editor .permission-editor-explanation {
|
||||||
|
user-select: none;
|
||||||
|
padding-left: 10px;
|
||||||
|
color: #9c9c9c;
|
||||||
|
font-size: 12px;
|
||||||
|
word-break: keep-all;
|
||||||
|
word-wrap: break-word;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
}
|
||||||
|
.permission-editor .select__option {
|
||||||
|
padding-top: 2px;
|
||||||
|
padding-bottom: 2px;
|
||||||
|
}
|
||||||
|
.select__control .permission-editor-explanation {
|
||||||
|
display: none;
|
||||||
|
}
|
@@ -1,6 +1,6 @@
|
|||||||
.share-dialog .share-dialog-content {
|
.share-dialog .share-dialog-content {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
min-height: 20rem;
|
min-height: 27rem;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
@@ -21,10 +21,17 @@
|
|||||||
.share-dialog-content .share-dialog-main .tab-content {
|
.share-dialog-content .share-dialog-main .tab-content {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
}
|
}
|
||||||
|
.share-dialog-content .share-dialog-main .tab-pane {
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
.share-dialog-content .share-dialog-main .tab-content thead th {
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
.share-list-container {
|
.share-list-container {
|
||||||
max-height: 15rem;
|
max-height: 18rem;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.share-dialog-content label {
|
.share-dialog-content label {
|
||||||
@@ -73,3 +80,6 @@ input.expire-input {
|
|||||||
margin: 0 0.25rem 0 1.25rem;
|
margin: 0 0.25rem 0 1.25rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.share-dialog-main .permission-editor .select__menu {
|
||||||
|
width: 240px;
|
||||||
|
}
|
||||||
|
@@ -339,6 +339,28 @@ export const Utils = {
|
|||||||
return title;
|
return title;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
sharePermsExplanation: function(permission) {
|
||||||
|
var title;
|
||||||
|
switch(permission) {
|
||||||
|
case 'rw':
|
||||||
|
title = gettext("User can read, write, upload, download and sync files.");
|
||||||
|
break;
|
||||||
|
case 'r':
|
||||||
|
title = gettext("User can read, download and sync files.");
|
||||||
|
break;
|
||||||
|
case 'admin':
|
||||||
|
title = gettext("Besides Write permission, user can also share the library.");
|
||||||
|
break;
|
||||||
|
case 'cloud-edit':
|
||||||
|
title = gettext("User can only view files online via browser. Files can't be downloaded.");
|
||||||
|
break;
|
||||||
|
case 'preview':
|
||||||
|
title = gettext("Same as Preview on cloud. But user can also edit files online via browser.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return title;
|
||||||
|
},
|
||||||
|
|
||||||
formatSize: function(options) {
|
formatSize: function(options) {
|
||||||
/*
|
/*
|
||||||
* param: {bytes, precision}
|
* param: {bytes, precision}
|
||||||
|
Reference in New Issue
Block a user