2016-05-06 05:14:39 +08:00
|
|
|
import React from 'react';
|
|
|
|
import Modal from 'react-modal';
|
2016-05-20 21:37:19 +08:00
|
|
|
import Icon from '/imports/ui/components/icon/component';
|
|
|
|
import Button from '/imports/ui/components/button/component';
|
2016-05-20 21:46:30 +08:00
|
|
|
import BaseModal from '../BaseModal';
|
|
|
|
import AudioMenu from './submenus/AudioMenu';
|
|
|
|
import VideoMenu from './submenus/VideoMenu';
|
|
|
|
import ApplicationMenu from './submenus/ApplicationMenu';
|
|
|
|
import UsersMenu from './submenus/UsersMenu';
|
|
|
|
import SessionMenu from './submenus/SessionMenu';
|
2016-05-06 05:14:39 +08:00
|
|
|
import classNames from 'classnames';
|
2016-05-07 01:46:14 +08:00
|
|
|
import ReactDOM from 'react-dom';
|
|
|
|
import styles from './styles';
|
2016-05-06 05:14:39 +08:00
|
|
|
|
|
|
|
export default class SettingsModal extends BaseModal {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.submenus = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillMount() {
|
|
|
|
this.setState({ activeSubmenu: 0 });
|
2016-07-28 06:33:32 +08:00
|
|
|
this.setState({ focusSubmenu: 0 });
|
2016-05-06 05:14:39 +08:00
|
|
|
this.submenus.push({ className: AudioMenu,
|
2016-07-12 01:01:09 +08:00
|
|
|
props: { title: 'Audio', prependIconName: 'icon-', icon: 'bbb-audio', }, tabIndex: 3, });
|
2016-05-06 05:14:39 +08:00
|
|
|
this.submenus.push({ className: VideoMenu,
|
2016-07-12 01:01:09 +08:00
|
|
|
props: { title: 'Video', prependIconName: 'icon-', icon: 'bbb-video', }, tabIndex: 4, });
|
2016-05-06 05:14:39 +08:00
|
|
|
this.submenus.push({ className: ApplicationMenu,
|
2016-07-12 01:01:09 +08:00
|
|
|
props: { title: 'Application', prependIconName: 'icon-', icon: 'bbb-application', }, tabIndex: 5, });
|
2016-05-06 05:14:39 +08:00
|
|
|
this.submenus.push({ className: UsersMenu,
|
2016-07-12 01:01:09 +08:00
|
|
|
props: { title: 'Participants', prependIconName: 'icon-', icon: 'bbb-user', }, tabIndex: 6, });
|
2016-05-06 05:14:39 +08:00
|
|
|
this.submenus.push({ className: SessionMenu,
|
2016-07-12 01:01:09 +08:00
|
|
|
props: { title: 'Leave session', prependIconName: 'icon-', icon: 'bbb-logout', }, tabIndex: 7, });
|
2016-05-06 05:14:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
ReactDOM.render(
|
2016-06-07 03:52:03 +08:00
|
|
|
<Button style={{ transform: 'rotate(90deg)' }}
|
|
|
|
onClick={this.openModal}
|
|
|
|
icon={'more'}
|
|
|
|
ghost={true}
|
|
|
|
circle={true}
|
2016-07-12 01:01:09 +08:00
|
|
|
hideLabel={true}
|
|
|
|
label={'Settings'}
|
|
|
|
aria-haspopup={'true'}
|
|
|
|
aria-labelledby={'settingsLabel'}
|
|
|
|
aria-describedby={'settingsDesc'}
|
|
|
|
/>
|
|
|
|
, document.getElementById('settingsButtonPlaceHolder'));
|
2016-05-06 05:14:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
createMenu() {
|
|
|
|
const curr = this.state.activeSubmenu === undefined ? 0 : this.state.activeSubmenu;
|
|
|
|
|
|
|
|
let props = {
|
|
|
|
title: this.submenus[curr].props.title,
|
|
|
|
prependIconName: this.submenus[curr].props.prependIconName,
|
|
|
|
icon: this.submenus[curr].props.icon,
|
|
|
|
};
|
|
|
|
|
|
|
|
const Submenu = this.submenus[curr].className;
|
|
|
|
return <Submenu {...props}/>;
|
|
|
|
}
|
|
|
|
|
|
|
|
clickSubmenu(i) {
|
2016-07-12 01:01:09 +08:00
|
|
|
if (i <= 0) {
|
2016-08-06 00:01:32 +08:00
|
|
|
this.setState({ activeSubmenu: 0, focusSubmenu: 0, });
|
2016-07-28 06:33:32 +08:00
|
|
|
return;
|
2016-07-12 01:01:09 +08:00
|
|
|
}
|
|
|
|
if (i >= this.submenus.length) {
|
2016-08-06 00:01:32 +08:00
|
|
|
this.setState({ activeSubmenu: this.submenus.length - 1,
|
|
|
|
focusSubmenu: this.submenus.length - 1, });
|
2016-07-28 06:33:32 +08:00
|
|
|
return;
|
2016-07-12 01:01:09 +08:00
|
|
|
} else {
|
2016-08-06 00:01:32 +08:00
|
|
|
this.setState({ activeSubmenu: i, focusSubmenu: i, });
|
2016-07-28 06:33:32 +08:00
|
|
|
}
|
2016-06-24 22:48:09 +08:00
|
|
|
}
|
|
|
|
|
2016-08-06 00:01:32 +08:00
|
|
|
handleKeyDown(event) {
|
2016-07-28 06:33:32 +08:00
|
|
|
// tab
|
2016-08-06 00:01:32 +08:00
|
|
|
if (event.keyCode === 9) {
|
|
|
|
let newIndex = 0;
|
|
|
|
if (this.state.focusSubmenu >= this.submenus.length - 1) {
|
|
|
|
newIndex = this.submenus.length - 1;
|
|
|
|
} else {
|
|
|
|
newIndex = this.state.focusSubmenu + 1;
|
2016-07-28 06:33:32 +08:00
|
|
|
}
|
2016-08-06 00:01:32 +08:00
|
|
|
this.setState({ focusSubmenu: newIndex });
|
|
|
|
return;
|
2016-06-24 22:48:09 +08:00
|
|
|
}
|
2016-05-06 05:14:39 +08:00
|
|
|
|
2016-08-06 00:01:32 +08:00
|
|
|
// shift+tab
|
|
|
|
if (event.shiftKey && event.keyCode === 9) {
|
|
|
|
let newIndex = 0;
|
|
|
|
if (this.state.focusSubmenu <= 0) {
|
|
|
|
newIndex = 0;
|
|
|
|
} else {
|
|
|
|
newIndex = this.state.focusSubmenu - 1;
|
|
|
|
}
|
|
|
|
this.setState({ focusSubmenu: newIndex });
|
|
|
|
return;
|
|
|
|
}
|
2016-07-28 06:33:32 +08:00
|
|
|
|
|
|
|
// up arrow
|
2016-08-06 00:01:32 +08:00
|
|
|
if (event.keyCode === 38) {
|
|
|
|
if (this.state.focusSubmenu <= 0) {
|
2016-07-28 06:33:32 +08:00
|
|
|
this.setState({ focusSubmenu: this.submenus.length - 1 }, function() {
|
|
|
|
ReactDOM.findDOMNode(this.refs[`submenu${this.state.focusSubmenu}`]).focus();
|
2016-08-06 00:01:32 +08:00
|
|
|
});
|
2016-07-12 01:43:42 +08:00
|
|
|
} else {
|
2016-07-28 06:33:32 +08:00
|
|
|
this.setState({ focusSubmenu: this.state.focusSubmenu - 1 }, function() {
|
|
|
|
ReactDOM.findDOMNode(this.refs[`submenu${this.state.focusSubmenu}`]).focus();
|
|
|
|
});
|
2016-07-12 01:43:42 +08:00
|
|
|
}
|
2016-08-06 00:01:32 +08:00
|
|
|
return;
|
2016-07-12 01:43:42 +08:00
|
|
|
}
|
2016-07-28 06:33:32 +08:00
|
|
|
|
|
|
|
// down arrow
|
2016-08-06 00:01:32 +08:00
|
|
|
if (event.keyCode === 40) {
|
|
|
|
if (this.state.focusSubmenu >= this.submenus.length - 1) {
|
2016-07-28 06:33:32 +08:00
|
|
|
this.setState({ focusSubmenu: 0 }, function() {
|
|
|
|
ReactDOM.findDOMNode(this.refs[`submenu${this.state.focusSubmenu}`]).focus();
|
2016-08-06 00:01:32 +08:00
|
|
|
});
|
2016-07-12 01:43:42 +08:00
|
|
|
} else {
|
2016-07-28 06:33:32 +08:00
|
|
|
this.setState({ focusSubmenu: this.state.focusSubmenu + 1 }, function() {
|
|
|
|
ReactDOM.findDOMNode(this.refs[`submenu${this.state.focusSubmenu}`]).focus();
|
|
|
|
});
|
2016-07-12 01:43:42 +08:00
|
|
|
}
|
2016-08-06 00:01:32 +08:00
|
|
|
return;
|
2016-07-12 01:43:42 +08:00
|
|
|
}
|
2016-07-28 06:33:32 +08:00
|
|
|
|
2016-08-06 00:01:32 +08:00
|
|
|
// spacebar or enter
|
|
|
|
if (event.keyCode === 32 || event.keyCode === 13) {
|
2016-07-28 06:33:32 +08:00
|
|
|
this.setState({ activeSubmenu: this.state.focusSubmenu });
|
2016-08-06 00:01:32 +08:00
|
|
|
return;
|
2016-07-12 01:43:42 +08:00
|
|
|
}
|
2016-08-06 00:01:32 +08:00
|
|
|
}
|
2016-07-28 06:33:32 +08:00
|
|
|
|
2016-08-06 00:01:32 +08:00
|
|
|
handleFocus(index) {
|
|
|
|
this.setState({ focusSubmenu: index });
|
2016-07-12 01:43:42 +08:00
|
|
|
}
|
|
|
|
|
2016-05-06 05:14:39 +08:00
|
|
|
getContent() {
|
|
|
|
return (
|
2016-07-12 01:01:09 +08:00
|
|
|
<div style={{ clear: 'both', height: '100%' }} role='presentation'>
|
2016-05-07 01:46:14 +08:00
|
|
|
<div className={styles.settingsMenuLeft}>
|
2016-07-12 01:01:09 +08:00
|
|
|
<ul style={{ listStyleType: 'none', paddingLeft: '0px' }} role='menu'>
|
2016-05-06 05:14:39 +08:00
|
|
|
{this.submenus.map((value, index) => (
|
2016-08-06 00:01:32 +08:00
|
|
|
<li key={index} ref={"submenu" + index} role='menuitem' tabIndex={value.tabIndex}
|
|
|
|
onClick={this.clickSubmenu.bind(this, index)}
|
|
|
|
onKeyDown={this.handleKeyDown.bind(this)}
|
|
|
|
onFocus={this.handleFocus.bind(this, index)}
|
2016-05-07 01:46:14 +08:00
|
|
|
className={classNames(styles.settingsSubmenuItem,
|
2016-05-13 00:10:43 +08:00
|
|
|
index == this.state.activeSubmenu ? styles.settingsSubmenuItemActive : null)}>
|
2016-05-06 05:14:39 +08:00
|
|
|
<Icon key={index} prependIconName={value.props.prependIconName}
|
|
|
|
iconName={value.props.icon} title={value.props.title}/>
|
2016-06-07 03:52:03 +08:00
|
|
|
<span className={styles.settingsSubmenuItemText}>{value.props.title}</span>
|
2016-05-06 05:14:39 +08:00
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
</div>
|
2016-07-12 01:01:09 +08:00
|
|
|
<div className={styles.settingsMenuRight} role='presentation'>
|
|
|
|
{this.createMenu()}
|
|
|
|
</div>
|
2016-05-06 05:14:39 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
2016-05-07 01:46:14 +08:00
|
|
|
|
|
|
|
SettingsModal.defaultProps = { title: 'Settings' };
|