Commit 9e940bf1 authored by Florent Chehab's avatar Florent Chehab
Browse files

Alert when closing with unsave data

parent 22a5c7fe
...@@ -172,6 +172,33 @@ class Editor extends MyComponent { ...@@ -172,6 +172,33 @@ class Editor extends MyComponent {
}) })
} }
handleCloseEditorRequest() {
console.log("close asked !")
const formData = this.getDataFromFields();
const { modelData } = this.props;
if (this.hasChangesToSave(formData, modelData)) {
this.setState({
alert: {
open: true,
info: false,
title: "Modifications non enregistrées !",
description: "Vous avez des modifications qui n'ont pas été sauvegardées. Voulez-vous les enregistrer ?",
agreeText: "Oui, je les enregistre",
disagreeText: "Non",
handleResponse: (agree) => {
if (agree) {
this.handleSaveEditor();
} else {
this.props.handleCloseEditor();
}
},
}
})
} else {
this.props.handleCloseEditor();
}
}
renderEditor() { renderEditor() {
return (<div>No editor set</div>) return (<div>No editor set</div>)
} }
...@@ -208,7 +235,6 @@ class Editor extends MyComponent { ...@@ -208,7 +235,6 @@ class Editor extends MyComponent {
<Dialog <Dialog
fullScreen fullScreen
open={this.props.open} open={this.props.open}
onClose={this.props.handleCloseEditor}
TransitionComponent={Transition} TransitionComponent={Transition}
> >
<Alert <Alert
...@@ -217,7 +243,7 @@ class Editor extends MyComponent { ...@@ -217,7 +243,7 @@ class Editor extends MyComponent {
/> />
<AppBar className={classes.appBar} > <AppBar className={classes.appBar} >
<Toolbar> <Toolbar>
<IconButton color="inherit" onClick={this.props.handleCloseEditor} aria-label="Close"> <IconButton color="inherit" onClick={() => this.handleCloseEditorRequest()} aria-label="Close">
<CloseIcon /> <CloseIcon />
</IconButton> </IconButton>
<Typography variant="title" color="inherit" className={classes.flex}> <Typography variant="title" color="inherit" className={classes.flex}>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment