Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Rex Dri
Rex Dri
Commits
65260c06
Commit
65260c06
authored
Mar 01, 2019
by
Florent Chehab
Browse files
removed nasty save detection and make use of requestCallabck on save in editor
parent
302743c1
Changes
1
Hide whitespace changes
Inline
Side-by-side
frontend/src/components/university/shared/Editor.js
View file @
65260c06
...
...
@@ -72,20 +72,6 @@ class Editor extends Component {
////////////////////////
/**
* Function to save the `data` to the server.
*
* @param {Object} data
* @memberof Editor
*/
performSave
(
data
)
{
this
.
notifyIsSaving
();
this
.
props
.
saveData
(
Object
.
assign
({
__apiAttr
:
this
.
props
.
__apiAttr
},
data
)
);
}
/**
* Function to handle save editor events, eg when clicking on the save button
* This function is not trivial and checks are performed.
...
...
@@ -112,6 +98,46 @@ class Editor extends Component {
}
/**
* Function to save the `data` to the server.
*
* @param {Object} data
* @memberof Editor
*/
performSave
(
data
)
{
this
.
notifyIsSaving
();
this
.
props
.
saveData
(
Object
.
assign
({
__apiAttr
:
this
.
props
.
__apiAttr
},
data
),
(
newData
)
=>
this
.
handleSaveRequestWasSuccessful
(
newData
)
);
}
/**
* Function that is called as soon as we now that the save request to the server was successful
*
* This enables not to use weird save detection method.
*
* @param {object} newData object returned by the server
* @memberof Editor
*/
handleSaveRequestWasSuccessful
(
newData
)
{
// We check if data was moderated
let
message
,
lastUpdateTimeInModel
=
this
.
props
.
lastUpdateTimeInModel
;
// at this point it will be still the previously stored data
const
newUpdateTimeInModel
=
newData
.
updated_on
;
if
(
lastUpdateTimeInModel
==
newUpdateTimeInModel
)
{
message
=
"
Les données ont été enregistrées et sont en attentes de modération.
"
;
}
else
{
lastUpdateTimeInModel
=
newUpdateTimeInModel
;
message
=
"
Les données ont été enregistrées avec succès !
"
;
}
this
.
notifySaveSuccessful
(
message
);
this
.
closeEditor
(
true
);
}
/**
* Function to handle close editor request from the user.
* It checks if there is data to save or not.
...
...
@@ -147,7 +173,7 @@ class Editor extends Component {
*
* @memberof Editor
*/
componentDidUpdate
(
prevProps
)
{
componentDidUpdate
()
{
// Open the editor if needed
// don't check the if prevProps was false before, we need to rerender it anyway so that we can
...
...
@@ -172,25 +198,6 @@ class Editor extends Component {
if
(
savingHasError
.
failed
&&
!
this
.
state
.
alert
.
open
)
{
this
.
alertSaveFailed
(
savingHasError
.
error
.
content
.
toString
());
}
//saving data was successful
if
(
prevProps
.
lastSaveTime
<
this
.
props
.
lastSaveTime
)
{
// We check if data was moderated
let
message
,
lastUpdateTimeInModel
=
prevProps
.
lastUpdateTimeInModel
;
const
newUpdateTimeInModel
=
this
.
props
.
lastUpdateTimeInModel
;
if
(
lastUpdateTimeInModel
==
newUpdateTimeInModel
)
{
message
=
"
Les données ont été enregistrées et sont en attentes de modération.
"
;
}
else
{
lastUpdateTimeInModel
=
newUpdateTimeInModel
;
message
=
"
Les données ont été enregistrées avec succès !
"
;
}
this
.
setState
({
lastSaveTime
:
this
.
props
.
lastSaveTime
,
lastUpdateTimeInModel
});
this
.
notifySaveSuccessful
(
message
);
this
.
closeEditor
(
true
);
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment