components/TeacherMenu/TeacherMenu.jsx

/**
 * Контейнер меню учителя
 * @module TeacherMenu
 * @author Ihor Bielchenko
 * @requires react
 * @requires react#Component
 * @requires redux#bindActionCreators
 * @requires react-redux#connect
 * @requires Base.js
 * @requires actions/StateConfigAction.js
 * @requires actions/StateUserAction.js
 * @requires components/TeacherMenu/TeacherMenuItem/TeacherMenuItem.jsx
 * @requires img/menu-icon1.png
 * @requires img/menu-icon2.png
 * @requires img/menu-icon3.png
 * @requires img/menu-icon4.png
 */

import React, { Component } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import Base from '../../Base.js';
import * as StateConfigAction from '../../actions/StateConfigAction.js';
import * as StateUserAction from '../../actions/StateUserAction.js';
import TeacherMenuItem from './TeacherMenuItem/TeacherMenuItem.jsx';
import Icon1 from '../../img/menu-icon1.png';
import Icon2 from '../../img/menu-icon2.png';
import Icon3 from '../../img/menu-icon3.png';
import Icon4 from '../../img/menu-icon4.png';

/**
 * Компонент меню учителя
 * @extends Component
 */
class TeacherMenu extends Component {

	/**
	 * Открыть окно с кодом регистрации
	 * @fires click
	 * @param {Object} e
	 */
	registratonCode(e) {
		Base.serverSEND(JSON.stringify({
			action: 'teacher/group/code',
			properties: {
				group_id: this.props.user.current_group
			}
		}), (r) => {
			if(r.success === 1) {
				this.props.user.registartion_code = '123';
				this.props.StateUserAction.update(this.props.user, () => {
					this.props.StateConfigAction.showElement(this.props.config, 'registration_code');
				});
			}
		})
	}

	/**
	 * Отправка сообщения
	 * @fires click
	 * @param {Object} e
	 */
	messageArea(e) {
		this.props.StateConfigAction.showElement(this.props.config, 'message_area');
	}

	/**
	 * Добавление нового таска
	 * @fires click
	 * @param {Object} e
	 */
	newTask(e) {
		this.props.StateConfigAction.showElement(this.props.config, 'add_task');
	}

	/**
	 * Статистика по заданиям
	 * @fires click
	 * @param {Object} e
	 */
	taskHistory(e) {
		this.props.StateConfigAction.showElement(this.props.config, 'task_history');
	}

	/**
	 * Render component
	 * @return {Object} jsx object
	 */
	render() {
		return <div className="menu">
				<div className="wrap">
					<div className="content">
						<TeacherMenuItem 
							href=""
							icon={Icon1}
							title={this.props.lang.new_task_title}
							onClick={this.newTask.bind(this)} />

						<TeacherMenuItem 
							href=""
							icon={Icon2}
							title={this.props.lang.new_message_title}
							onClick={this.messageArea.bind(this)} />

						<TeacherMenuItem 
							href=""
							icon={Icon3}
							title={this.props.lang.registraton_code_title}
							onClick={this.registratonCode.bind(this)} />

						<TeacherMenuItem 
							href=""
							icon={Icon4}
							title={this.props.lang.tasks_history_title}
							onClick={this.taskHistory.bind(this)} />
					</div>
				</div>
			</div>
	}
}

/**
 * Init redux states
 * @param {Object} state
 * @return {Object}
 */
function mapStateToProps(state) {
	return {
		lang: state.lang,
		user: state.user,
		config: state.config
	}
}

/**
 * Init redux actions
 * @param {Function} dispatch
 * @return {Object}
 */
function mapDispatchToProps(dispatch) {
	return {
		StateConfigAction: bindActionCreators(StateConfigAction, dispatch),
		StateUserAction: bindActionCreators(StateUserAction, dispatch),
	}
}

export default connect(mapStateToProps, mapDispatchToProps)(TeacherMenu);