'use strict';
const remote = require('electron').remote;
const settings = require('../common/settings');
const React = require('react');
const ReactDOM = require('react-dom');
const ReactBootstrap = require('react-bootstrap');
const Grid = ReactBootstrap.Grid;
const Row = ReactBootstrap.Row;
const Col = ReactBootstrap.Col;
const Input = ReactBootstrap.Input;
const Button = ReactBootstrap.Button;
const ListGroup = ReactBootstrap.ListGroup;
const ListGroupItem = ReactBootstrap.ListGroupItem;
const Glyphicon = ReactBootstrap.Glyphicon;
function backToIndex() {
remote.getCurrentWindow().loadURL('file://' + __dirname + '/index.html');
}
var SettingsPage = React.createClass({
getInitialState: function() {
var config;
try {
config = settings.readFileSync(this.props.configFile);
} catch (e) {
config = settings.loadDefault();
}
this.setState({
showAddTeamForm: false
});
return config;
},
handleTeamsChange: function(teams) {
this.setState({
teams: teams
});
this.handleSave(false);
},
handleSave: function(backToIndex) {
var config = {
teams: this.state.teams,
hideMenuBar: this.state.hideMenuBar,
showTrayIcon: this.state.showTrayIcon,
trayIconTheme: this.state.trayIconTheme,
disablewebsecurity: this.state.disablewebsecurity,
version: settings.version
};
settings.writeFileSync(this.props.configFile, config);
if (process.platform === 'win32' || process.platform === 'linux') {
var currentWindow = remote.getCurrentWindow();
currentWindow.setAutoHideMenuBar(config.hideMenuBar);
currentWindow.setMenuBarVisibility(!config.hideMenuBar);
}
if (typeof backToIndex == 'undefined' || backToIndex) {
backToIndex();
}
},
handleCancel: function() {
backToIndex();
},
handleChangeDisableWebSecurity: function() {
this.setState({
disablewebsecurity: this.refs.disablewebsecurity.getChecked()
});
},
handleChangeHideMenuBar: function() {
this.setState({
hideMenuBar: this.refs.hideMenuBar.getChecked()
});
},
handleChangeShowTrayIcon: function() {
this.setState({
showTrayIcon: this.refs.showTrayIcon.getChecked()
});
},
handleChangeTrayIconTheme: function() {
this.setState({
trayIconTheme: this.refs.trayIconTheme.getValue()
});
},
handleShowTeamForm: function() {
if (!this.state.showAddTeamForm) {
this.setState({
showAddTeamForm: true
});
} else {
this.setState({
showAddTeamForm: false
});
}
},
render: function() {
var teams_row = (
Teams
);
var options = [];
if (process.platform === 'win32' || process.platform === 'linux') {
options.push();
}
if (process.platform === 'darwin' || process.platform === 'linux') {
options.push();
}
if (process.platform === 'linux') {
options.push(
);
}
options.push();
var options_row = (options.length > 0) ? (
Options
{ options }
) : null;
return (
{ teams_row }
{ options_row }
{ ' ' }
);
}
});
var TeamList = React.createClass({
getInitialState: function() {
return {
showTeamListItemNew: false,
team: {
url: '',
name: '',
index: false
}
};
},
handleTeamRemove: function(index) {
console.log(index);
var teams = this.props.teams;
teams.splice(index, 1);
this.props.onTeamsChange(teams);
},
handleTeamAdd: function(team) {
var teams = this.props.teams;
// check if team already exists and then change existing team or add new one
if (!team.index && teams[team.index]) {
teams[team.index].name = team.name;
teams[team.index].url = team.url;
} else {
teams.push(team);
}
this.setState({
showTeamListItemNew: false
});
this.props.onTeamsChange(teams);
},
handleTeamEditing: function(teamName, teamUrl, teamIndex) {
this.setState({
showTeamListItemNew: true,
team: {
url: teamUrl,
name: teamName,
index: teamIndex
}
})
},
render: function() {
var thisObj = this;
var teamNodes = this.props.teams.map(function(team, i) {
var handleTeamRemove = function() {
thisObj.handleTeamRemove(i);
};
var handleTeamEditing = function() {
thisObj.handleTeamEditing(team.name, team.url, i);
};
return (
);
});
var addTeamForm;
if (this.props.showAddTeamForm || this.state.showTeamListItemNew) {
addTeamForm = ;
} else {
addTeamForm = '';
}
return (
{ teamNodes }
{ addTeamForm }
);
}
});
var TeamListItem = React.createClass({
handleTeamRemove: function() {
this.props.onTeamRemove();
},
handleTeamEditing: function() {
this.props.onTeamEditing();
},
render: function() {
var style = {
left: {
"display": 'inline-block'
}
};
return (
{ this.props.name }
{ this.props.url }
{ ' ' }
);
}
});
var TeamListItemNew = React.createClass({
getInitialState: function() {
return {
name: this.props.teamName,
url: this.props.teamUrl,
index: this.props.teamIndex
};
},
handleSubmit: function(e) {
console.log('submit');
e.preventDefault();
this.props.onTeamAdd({
name: this.state.name.trim(),
url: this.state.url.trim(),
index: this.state.index,
});
this.setState(this.getInitialState());
},
handleNameChange: function(e) {
console.log('name');
this.setState({
name: e.target.value
});
},
handleURLChange: function(e) {
console.log('url');
this.setState({
url: e.target.value
});
},
shouldEnableAddButton: function() {
return (this.state.name.trim() !== '' || this.props.teamName !== '') && (this.state.url.trim() !== '' || this.props.teamUrl !== '');
},
render: function() {
var existingTeam = false;
if (this.state.name !== '' && this.state.url !== '') {
existingTeam = true;
}
var btnAddText;
if (existingTeam) {
btnAddText = 'Save';
} else {
btnAddText = 'Add';
}
return (
);
}
});
var configFile = remote.getGlobal('config-file');
var contextMenu = require('./menus/context');
var menu = contextMenu.createDefault();
window.addEventListener('contextmenu', function(e) {
menu.popup(remote.getCurrentWindow());
}, false);
ReactDOM.render(
,
document.getElementById('content')
);