import React, { Component, Fragment } from 'react'; import { Dropdown, DropdownToggle, DropdownMenu, DropdownItem } from 'reactstrap'; import { Button, Form, FormGroup, Input, Col } from 'reactstrap'; import { Utils } from '../../utils/utils'; import { seafileAPI } from '../../utils/seafile-api'; import { gettext, orgID, siteRoot } from '../../utils/constants'; import toaster from '../../components/toast'; import OrgGroupInfo from '../../models/org-group'; class GroupItem extends React.Component { constructor(props) { super(props); this.state = { highlight: false, showMenu: false, isItemMenuShow: false }; } onMouseEnter = () => { if (!this.props.isItemFreezed) { this.setState({ showMenu: true, highlight: true, }); } } onMouseLeave = () => { if (!this.props.isItemFreezed) { this.setState({ showMenu: false, highlight: false }); } } onDropdownToggleClick = (e) => { e.preventDefault(); this.toggleOperationMenu(e); } toggleOperationMenu = (e) => { e.stopPropagation(); this.setState( {isItemMenuShow: !this.state.isItemMenuShow }, () => { if (this.state.isItemMenuShow) { this.props.onFreezedItem(); } else { this.setState({ highlight: false, showMenu: false, }); this.props.onUnfreezedItem(); } } ); } toggleDelete = () => { this.props.deleteGroupItem(this.props.group); } renderGroupHref = (group) => { let groupInfoHref; if (group.creatorName == 'system admin') { groupInfoHref = siteRoot + 'org/departmentadmin/groups/' + group.id + '/'; } else { groupInfoHref = siteRoot + 'org/groupadmin/' + group.id + '/'; } return groupInfoHref; } renderGroupCreator = (group) => { let userInfoHref = siteRoot + 'org/useradmin/info/' + group.creatorEmail + '/'; if (group.creatorName == 'system admin') { return ( -- ); } else { return( {group.creatorName} ); } } render() { let { group } = this.props; let isOperationMenuShow = (group.creatorName != 'system admin') && this.state.showMenu; return ( {group.groupName} {this.renderGroupCreator(group)} {group.ctime} {isOperationMenuShow && {gettext('Delete')} } ); } } class OrgGroupsSearchGroupsResult extends React.Component { constructor(props) { super(props); this.state = { isItemFreezed: false }; } onFreezedItem = () => { this.setState({isItemFreezed: true}); } onUnfreezedItem = () => { this.setState({isItemFreezed: false}); } render() { let { orgGroups } = this.props; return (
{orgGroups.map(item => { return ( ); })}
{gettext('Name')} {gettext('Creator')} {gettext('Created At')} {gettext('Operations')}
); } } class OrgGroupsSearchGroups extends Component { constructor(props) { super(props); this.state = { query: '', orgGroups: [], isSubmitBtnActive: false, loading: true, errorMsg: '', }; } componentDidMount () { let params = (new URL(document.location)).searchParams; this.setState({ query: params.get('query') || '', }, () => {this.getItems();}); } getItems = () => { seafileAPI.orgAdminSearchGroup(orgID, this.state.query.trim()).then(res => { let groupList = res.data.group_list.map(item => { return new OrgGroupInfo(item); }); this.setState({ orgGroups: groupList, loading: false, }); }).catch((error) => { this.setState({ loading: false, errorMsg: Utils.getErrorMsg(error, true) // true: show login tip if 403 }); }); } deleteGroupItem = (group) => { seafileAPI.orgAdminDeleteOrgGroup(orgID, group.id).then(res => { this.setState({ orgGroups: this.state.orgGroups.filter(item => item.id != group.id) }); let msg = gettext('Successfully deleted {name}'); msg = msg.replace('{name}', group.groupName); toaster.success(msg); }).catch(error => { let errMessage = Utils.getErrorMsg(error); toaster.danger(errMessage); }); } handleInputChange = (e) => { this.setState({ query: e.target.value }, this.checkSubmitBtnActive); } checkSubmitBtnActive = () => { const { query } = this.state; this.setState({ isSubmitBtnActive: query.trim() }); } handleKeyDown = (e) => { if (e.keyCode === 13) { const { isSubmitBtnActive } = this.state; if (isSubmitBtnActive) { this.getItems(); } } } render() { const { query, isSubmitBtnActive } = this.state; return (

{gettext('Groups')}

{gettext('Search Groups')}

{gettext('Result')}

); } } export default OrgGroupsSearchGroups;