86 lines
2.1 KiB
JavaScript
86 lines
2.1 KiB
JavaScript
/* jhsint node:true, jsx: true */
|
|
var React = require('react');
|
|
var connect = require('react-redux').connect;
|
|
var actions = require('../../store/actions');
|
|
var dialog = require('remote').require('dialog');
|
|
|
|
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;
|
|
this.showOpenProfileDialog()
|
|
.then(function(profilePath) {
|
|
if(profilePath) dispatch(actions.common.loadProfile(profilePath));
|
|
})
|
|
;
|
|
},
|
|
|
|
handleSaveClick: function() {
|
|
|
|
var dispatch = this.props.dispatch;
|
|
var profile = this.props.profile;
|
|
var profilePath = this.props.profilePath;
|
|
|
|
this.showSaveProfileDialog(profilePath)
|
|
.then(function(profilePath) {
|
|
if(profilePath) dispatch(actions.edit.saveProfile(profilePath, profile));
|
|
});
|
|
|
|
},
|
|
|
|
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);
|
|
}
|
|
)
|
|
});
|
|
|
|
},
|
|
|
|
showSaveProfileDialog: function(defaultPath) {
|
|
|
|
return new Promise(function(resolve) {
|
|
dialog.showSaveDialog(
|
|
{
|
|
defaultPath: defaultPath,
|
|
title: 'Enregistrer un profil',
|
|
filters: [ {name: 'Profils Pitaya', extensions: ['json'] } ]
|
|
},
|
|
function(file) {
|
|
return resolve(file);
|
|
}
|
|
)
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
function select(state) {
|
|
return {
|
|
profile: state.profile,
|
|
profilePath: state.profilePath
|
|
};
|
|
}
|
|
|
|
module.exports = connect(select)(ProfileMenu);
|