mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-07 01:41:39 +00:00
optimized code
This commit is contained in:
@@ -118,23 +118,7 @@ class ShareToGroup extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setPermission = (e) => {
|
setPermission = (e) => {
|
||||||
if (e.target.value == 'Read-Write') {
|
this.setState({permission: e.target.value});
|
||||||
this.setState({
|
|
||||||
permission: 'rw',
|
|
||||||
});
|
|
||||||
} else if (e.target.value == 'Read-Only') {
|
|
||||||
this.setState({
|
|
||||||
permission: 'r',
|
|
||||||
});
|
|
||||||
} else if (e.target.value == 'Preview-Edit-on-Cloud') {
|
|
||||||
this.setState({
|
|
||||||
permission: 'cloud-edit',
|
|
||||||
});
|
|
||||||
} else if (e.target.value == 'Preview-on-Cloud') {
|
|
||||||
this.setState({
|
|
||||||
permission: 'preview',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
shareToGroup = () => {
|
shareToGroup = () => {
|
||||||
@@ -227,6 +211,7 @@ class ShareToGroup extends React.Component {
|
|||||||
isMulti
|
isMulti
|
||||||
onChange={this.handleSelectChange}
|
onChange={this.handleSelectChange}
|
||||||
options={this.options}
|
options={this.options}
|
||||||
|
placeholder={gettext('Select a group')}
|
||||||
components={makeAnimated()}
|
components={makeAnimated()}
|
||||||
inputId={'react-select-2-input'}
|
inputId={'react-select-2-input'}
|
||||||
value={this.state.selectedOption}
|
value={this.state.selectedOption}
|
||||||
@@ -234,28 +219,26 @@ class ShareToGroup extends React.Component {
|
|||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<Input type="select" name="select" onChange={this.setPermission}>
|
<Input type="select" name="select" onChange={this.setPermission}>
|
||||||
<option>{gettext('Read-Write')}</option>
|
<option value='rw'>{gettext('Read-Write')}</option>
|
||||||
<option>{gettext('Read-Only')}</option>
|
<option value='r'>{gettext('Read-Only')}</option>
|
||||||
<option>{gettext('Preview-Edit-on-Cloud')}</option>
|
<option value='cloud-edit'>{gettext('Preview-Edit-on-Cloud')}</option>
|
||||||
<option>{gettext('Preview-on-Cloud')}</option>
|
<option value='preview'>{gettext('Preview-on-Cloud')}</option>
|
||||||
</Input>
|
</Input>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<Button onClick={this.shareToGroup}>{gettext('Submit')}</Button>
|
<Button onClick={this.shareToGroup}>{gettext('Submit')}</Button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
|
||||||
<td colSpan={3}>
|
|
||||||
{this.state.errorMsg.length > 0 &&
|
{this.state.errorMsg.length > 0 &&
|
||||||
this.state.errorMsg.map((item, index = 0, arr) => {
|
this.state.errorMsg.map((item, index) => {
|
||||||
|
let errMessage = item.group_name + ': ' + item.error_msg;
|
||||||
return (
|
return (
|
||||||
<p className="error" key={index}>{this.state.errorMsg[index].group_name}
|
<tr key={index}>
|
||||||
{': '}{this.state.errorMsg[index].error_msg}</p>
|
<td colSpan={3}><p className="error">{errMessage}</p></td>
|
||||||
|
</tr>
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
</thead>
|
||||||
<GroupList items={this.state.sharedItems} deleteShareItem={this.deleteShareItem} />
|
<GroupList items={this.state.sharedItems} deleteShareItem={this.deleteShareItem} />
|
||||||
</table>
|
</table>
|
||||||
|
@@ -98,27 +98,7 @@ class ShareToUser extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setPermission = (e) => {
|
setPermission = (e) => {
|
||||||
if (e.target.value == 'Read-Write') {
|
this.setState({permission: e.target.value});
|
||||||
this.setState({
|
|
||||||
permission: 'rw',
|
|
||||||
});
|
|
||||||
} else if (e.target.value == 'Read-Only') {
|
|
||||||
this.setState({
|
|
||||||
permission: 'r',
|
|
||||||
});
|
|
||||||
} else if (e.target.value == 'Admin') {
|
|
||||||
this.setState({
|
|
||||||
permission: 'admin',
|
|
||||||
});
|
|
||||||
} else if (e.target.value == 'Preview-Edit-on-Cloud') {
|
|
||||||
this.setState({
|
|
||||||
permission: 'cloud-edit',
|
|
||||||
});
|
|
||||||
} else if (e.target.value == 'Preview-on-Cloud') {
|
|
||||||
this.setState({
|
|
||||||
permission: 'preview',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
loadOptions = (value, callback) => {
|
loadOptions = (value, callback) => {
|
||||||
@@ -173,6 +153,13 @@ class ShareToUser extends React.Component {
|
|||||||
sharedItems: this.state.sharedItems.concat(items),
|
sharedItems: this.state.sharedItems.concat(items),
|
||||||
selectedOption: null,
|
selectedOption: null,
|
||||||
});
|
});
|
||||||
|
}).catch(error => {
|
||||||
|
if (error.response) {
|
||||||
|
let message = gettext('Library can not be shared to owner.');
|
||||||
|
let errMessage = [];
|
||||||
|
errMessage.push(message);
|
||||||
|
this.setState({errorMsg: errMessage});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
seafileAPI.shareFolder(repoID, path, 'user', this.state.permission, users).then(res => {
|
seafileAPI.shareFolder(repoID, path, 'user', this.state.permission, users).then(res => {
|
||||||
@@ -187,6 +174,13 @@ class ShareToUser extends React.Component {
|
|||||||
sharedItems: this.state.sharedItems.concat(res.data.success),
|
sharedItems: this.state.sharedItems.concat(res.data.success),
|
||||||
selectedOption: null,
|
selectedOption: null,
|
||||||
});
|
});
|
||||||
|
}).catch(error => {
|
||||||
|
if (error.response) {
|
||||||
|
let message = gettext('Library can not be shared to owner.');
|
||||||
|
let errMessage = [];
|
||||||
|
errMessage.push(message);
|
||||||
|
this.setState({errorMsg: errMessage});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -224,7 +218,7 @@ class ShareToUser extends React.Component {
|
|||||||
<AsyncSelect
|
<AsyncSelect
|
||||||
inputId={'react-select-1-input'}
|
inputId={'react-select-1-input'}
|
||||||
className='reviewer-select'
|
className='reviewer-select'
|
||||||
placeholder={gettext('Please enter 1 or more character')}
|
placeholder={gettext('Select users...')}
|
||||||
loadOptions={this.loadOptions}
|
loadOptions={this.loadOptions}
|
||||||
onChange={this.handleSelectChange}
|
onChange={this.handleSelectChange}
|
||||||
value={this.state.selectedOption}
|
value={this.state.selectedOption}
|
||||||
@@ -236,29 +230,32 @@ class ShareToUser extends React.Component {
|
|||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<Input type="select" name="select" onChange={this.setPermission}>
|
<Input type="select" name="select" onChange={this.setPermission}>
|
||||||
<option>{gettext('Read-Write')}</option>
|
<option value='rw'>{gettext('Read-Write')}</option>
|
||||||
<option>{gettext('Read-Only')}</option>
|
<option value='r'>{gettext('Read-Only')}</option>
|
||||||
<option>{gettext('Admin')}</option>
|
<option value='admin'>{gettext('Admin')}</option>
|
||||||
<option>{gettext('Preview-Edit-on-Cloud')}</option>
|
<option value='cloud-edit'>{gettext('Preview-Edit-on-Cloud')}</option>
|
||||||
<option>{gettext('Preview-on-Cloud')}</option>
|
<option value='preview'>{gettext('Preview-on-Cloud')}</option>
|
||||||
</Input>
|
</Input>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<Button onClick={this.shareToUser}>{gettext('Submit')}</Button>
|
<Button onClick={this.shareToUser}>{gettext('Submit')}</Button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
|
||||||
<td colSpan={3}>
|
|
||||||
{this.state.errorMsg.length > 0 &&
|
{this.state.errorMsg.length > 0 &&
|
||||||
this.state.errorMsg.map((item, index = 0, arr) => {
|
this.state.errorMsg.map((item, index) => {
|
||||||
|
let errMessage = '';
|
||||||
|
if (item.email) {
|
||||||
|
errMessage = item.email + ': ' + item.error_msg;
|
||||||
|
} else {
|
||||||
|
errMessage = item;
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<p className="error" key={index}>{this.state.errorMsg[index].email}
|
<tr key={index}>
|
||||||
{': '}{this.state.errorMsg[index].error_msg}</p>
|
<td colSpan={3}><p className="error">{errMessage}</p></td>
|
||||||
|
</tr>
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
</thead>
|
||||||
<UserList items={sharedItems} deleteShareItem={this.deleteShareItem} />
|
<UserList items={sharedItems} deleteShareItem={this.deleteShareItem} />
|
||||||
</table>
|
</table>
|
||||||
|
Reference in New Issue
Block a user