2016-12-22 01:14:46 +08:00
|
|
|
import React, { Component } from 'react';
|
2016-12-23 09:48:19 +08:00
|
|
|
import { createContainer } from 'meteor/react-meteor-data';
|
|
|
|
import Settings from './component';
|
|
|
|
import Service from './service';
|
2016-12-23 16:31:22 +08:00
|
|
|
import LocalStorage from '/imports/ui/services/storage/local.js';
|
|
|
|
|
2016-12-20 05:45:09 +08:00
|
|
|
const DEFAULT_FONTSIZE = 3;
|
|
|
|
const MAX_FONTSIZE = 5;
|
|
|
|
const MIN_FONTSIZE = 1;
|
2016-12-23 09:48:19 +08:00
|
|
|
|
|
|
|
class SettingsMenuContainer extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2016-12-20 05:45:09 +08:00
|
|
|
|
2016-12-23 16:31:22 +08:00
|
|
|
this.state = {
|
|
|
|
currentFontSize: LocalStorage.getItem('bbbSavedFontSize') || DEFAULT_FONTSIZE,
|
2016-12-20 05:45:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
this.fontControl = {
|
|
|
|
properties: {
|
|
|
|
1: { size: '12px', name: 'Extra Small' },
|
|
|
|
2: { size: '14px', name: 'Small' },
|
|
|
|
3: { size: '16px', name: 'Medium' },
|
|
|
|
4: { size: '18px', name: 'Large' },
|
|
|
|
5: { size: '20px', name: 'Extra Large' },
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
this.handleGetFontSizeName = this.handleGetFontSizeName.bind(this);
|
|
|
|
this.handleApplyFontSize = this.handleApplyFontSize.bind(this);
|
|
|
|
this.handleIncreaseFontSize = this.handleIncreaseFontSize.bind(this);
|
|
|
|
this.handleDecreaseFontSize = this.handleDecreaseFontSize.bind(this);
|
|
|
|
this.handleSaveFontState = this.handleSaveFontState.bind(this);
|
|
|
|
this.handleRevertFontState = this.handleRevertFontState.bind(this);
|
2016-12-23 09:48:19 +08:00
|
|
|
}
|
|
|
|
|
2016-12-23 16:31:22 +08:00
|
|
|
handleGetFontSizeName() {
|
|
|
|
return this.fontControl.properties[this.state.currentFontSize].name;
|
|
|
|
};
|
|
|
|
|
|
|
|
handleApplyFontSize() {
|
|
|
|
const size = this.fontControl.properties[this.state.currentFontSize].size;
|
|
|
|
document.getElementsByTagName('html')[0].style.fontSize = size;
|
|
|
|
};
|
|
|
|
|
|
|
|
handleIncreaseFontSize() {
|
|
|
|
let fs = ( this.state.currentFontSize < MAX_FONTSIZE) ? ++this.state.currentFontSize : MAX_FONTSIZE;
|
|
|
|
LocalStorage.setItem('bbbFontSize', fs);
|
|
|
|
this.setState({ currentFontSize: fs }, function () {
|
|
|
|
this.handleApplyFontSize();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
handleDecreaseFontSize() {
|
|
|
|
let fs = ( this.state.currentFontSize > MIN_FONTSIZE) ? --this.state.currentFontSize : MIN_FONTSIZE;
|
|
|
|
LocalStorage.setItem('bbbFontSize', fs);
|
|
|
|
this.setState({ currentFontSize: fs }, function () {
|
|
|
|
this.handleApplyFontSize();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
handleSaveFontState() {
|
|
|
|
let fs = LocalStorage.getItem('bbbFontSize') || DEFAULT_FONTSIZE;
|
|
|
|
LocalStorage.setItem('bbbSavedFontSize', fs);
|
|
|
|
LocalStorage.setItem('bbbSavedFontSizePixels', this.fontControl.properties[fs].size);
|
|
|
|
this.setState({ currentFontSize: fs }, function () {
|
|
|
|
this.handleApplyFontSize();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
handleRevertFontState(){
|
|
|
|
let fs = LocalStorage.getItem('bbbSavedFontSize') || DEFAULT_FONTSIZE;
|
|
|
|
this.setState({ currentFontSize: fs }, function () {
|
|
|
|
this.handleApplyFontSize();
|
|
|
|
});
|
2016-12-20 05:45:09 +08:00
|
|
|
};
|
2016-12-21 02:06:01 +08:00
|
|
|
|
2016-12-23 09:48:19 +08:00
|
|
|
render() {
|
2016-12-21 02:06:01 +08:00
|
|
|
|
2016-12-23 16:31:22 +08:00
|
|
|
const handleGetFontSizeName = () => this.handleGetFontSizeName();
|
|
|
|
const handleIncreaseFontSize = () => this.handleIncreaseFontSize();
|
|
|
|
const handleDecreaseFontSize = () => this.handleDecreaseFontSize();
|
|
|
|
const handleSaveFontState = () => this.handleSaveFontState();
|
2016-12-20 05:45:09 +08:00
|
|
|
const handleRevertFontState = () => this.handleRevertFontState();
|
2016-12-23 16:31:22 +08:00
|
|
|
|
2016-12-23 09:48:19 +08:00
|
|
|
return (
|
2016-12-20 05:45:09 +08:00
|
|
|
<Settings
|
|
|
|
handleGetFontSizeName={handleGetFontSizeName}
|
|
|
|
handleIncreaseFontSize={handleIncreaseFontSize}
|
|
|
|
handleDecreaseFontSize={handleDecreaseFontSize}
|
|
|
|
handleSaveFontState={handleSaveFontState}
|
|
|
|
handleRevertFontState={handleRevertFontState}
|
2016-12-23 16:31:22 +08:00
|
|
|
{...this.props}>
|
2016-12-23 09:48:19 +08:00
|
|
|
{this.props.children}
|
|
|
|
</Settings>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default createContainer(() => {
|
|
|
|
let data = Service.checkUserRoles();
|
|
|
|
return data;
|
|
|
|
}, SettingsMenuContainer);
|