import React from 'react'; import PropTypes from 'prop-types'; import FormGroup from 'react-bootstrap/es/FormGroup'; import FormControl from 'react-bootstrap/es/FormControl'; import ControlLabel from 'react-bootstrap/es/ControlLabel'; import Button from 'react-bootstrap/es/Button'; import Dropdown from 'react-bootstrap/es/Dropdown'; import MenuItem from 'react-bootstrap/es/MenuItem'; import Modal from 'react-bootstrap/es/Modal'; import OverlayTrigger from 'react-bootstrap/es/OverlayTrigger'; import Tooltip from 'react-bootstrap/es/Tooltip'; export default class GrantSelector extends React.Component { constructor(props) { super(props); const config = this.props.crowi.getConfig(); this.state = { pageGrant: this.props.pageGrant, isGroupModalShown: false, } this.availableGrants = [1, 2,/* 3,*/ 4, 5] this.availableGrantLabels = { 1: 'Public', 2: 'Anyone with the linc', // 3:'Specified users only', 4: 'Just me', 5: 'Only inside the group', } this.onChangeGrant = this.onChangeGrant.bind(this); // this.updateElementValue = this.updateElementValue.bind(this); } componentDidMount() { this.init(); } init() { this.grantSelectorInputEl.value = this.state.pageGrant.grant; } updateElementValue() { console.log(this.state.pageGrant); if (this.state.pageGrant != null) { document.getElementById("page-grant").value = this.state.pageGrant.grant; if (this.state.pageGrant.grantGroup != null) { document.getElementById("grant-group").value = this.state.pageGrant.grantGroup.grantGroupId; } } } onChangeGrant(grant) { const newValue = this.grantSelectorInputEl.value; const newGrant = Object.assign(this.state.pageGrant, {grant: newValue}); this.setState({ pageGrant: newGrant }); this.updateElementValue(); // dispatch event this.dispatchOnChange(); } onClickGrantGroup() { const newValue = this.groupSelectorInputEl.value; const newGrant = Object.assign(this.state.pageGrant, { grantGroup: newValue }); this.setState({ pageGrant: newGrant }); // dispatch event this.dispatchOnChange(); // close group select modal if (this.state.isModalShown) { this.setState({ isGroupModalShown: false }); } } /** * dispatch onChange event */ dispatchOnChange() { if (this.props.onChange != null) { this.props.onChange(this.state.pageGrant); } } renderGrantSelector() { const grantElems = this.availableGrants.map((grant) => { return ; }); const bsClassName = 'form-control-dummy'; // set form-control* to shrink width return ( Grant: this.grantSelectorInputEl=el }> {grantElems} ) } renderSelectGroupModal() { const userRelatedGroups = this.props.userRelatedGroups; const groupList = this.userRelatedGroups.map((group) => { return
  • }); return ( Select a Group ); } render() { return {this.renderGrantSelector()} } } export class PageGrant { constructor(props) { this.grant = ''; this.grantGroup = null; Object.assign(this, props); } } export class UserGroup { constructor(props) { this.userGroupId = ''; this.userGroup Object.assign(this, props); } } GrantSelector.propTypes = { crowi: PropTypes.object.isRequired, userRelatedGroups: PropTypes.object, pageGrant: PropTypes.instanceOf(PageGrant), onChange: PropTypes.func, };