pitaya-launcher/js/components/edit/profile-menu.js

86 lines
2.1 KiB
JavaScript
Raw Normal View History

2015-10-10 18:44:31 +02:00
/* jhsint node:true, jsx: true */
2015-09-18 12:13:24 +02:00
var React = require('react');
var connect = require('react-redux').connect;
var actions = require('../../store/actions');
2015-10-10 14:34:14 +02:00
var dialog = require('remote').require('dialog');
2015-09-18 12:13:24 +02:00
var ProfileMenu = React.createClass({
render: function() {
return (
<div className="profile-menu">
<button className="btn btn-default" onClick={this.handleOpenClick}>Ouvrir</button>
<button className="btn btn-primary" onClick={this.handleSaveClick}>Enregistrer</button>
</div>
);
},
handleOpenClick: function() {
var dispatch = this.props.dispatch;
2015-10-10 14:34:14 +02:00
this.showOpenProfileDialog()
2015-09-18 12:13:24 +02:00
.then(function(profilePath) {
2015-10-10 14:34:14 +02:00
if(profilePath) dispatch(actions.common.loadProfile(profilePath));
2015-09-18 12:13:24 +02:00
})
;
},
handleSaveClick: function() {
var dispatch = this.props.dispatch;
var profile = this.props.profile;
var profilePath = this.props.profilePath;
2015-10-10 18:44:31 +02:00
this.showSaveProfileDialog(profilePath)
.then(function(profilePath) {
if(profilePath) dispatch(actions.edit.saveProfile(profilePath, profile));
});
2015-09-18 12:13:24 +02:00
},
2015-10-10 14:34:14 +02:00
showOpenProfileDialog: function() {
return new Promise(function(resolve) {
dialog.showOpenDialog(
{
title: 'Éditer un profil',
filters: [ {name: 'Profils Pitaya', extensions: ['json'] } ],
properties: ['openFile']
},
function(files) {
return resolve(files ? files[0] : null);
}
)
});
2015-09-18 12:13:24 +02:00
2015-10-10 14:34:14 +02:00
},
2015-09-18 12:13:24 +02:00
2015-10-10 18:44:31 +02:00
showSaveProfileDialog: function(defaultPath) {
2015-10-10 14:34:14 +02:00
return new Promise(function(resolve) {
dialog.showSaveDialog(
{
2015-10-10 18:44:31 +02:00
defaultPath: defaultPath,
title: 'Enregistrer un profil',
2015-10-10 14:34:14 +02:00
filters: [ {name: 'Profils Pitaya', extensions: ['json'] } ]
},
function(file) {
return resolve(file);
}
)
2015-09-18 12:13:24 +02:00
});
}
});
function select(state) {
return {
profile: state.profile,
profilePath: state.profilePath
};
}
module.exports = connect(select)(ProfileMenu);