Skip to content
Snippets Groups Projects
Commit d0cc8b39 authored by chris's avatar chris Committed by john
Browse files

modal warning for editors when unsaved changes

parent 0f57c5ef
No related branches found
No related tags found
No related merge requests found
......@@ -50,7 +50,7 @@ class ContainerEditor extends SubstanceContainerEditor {
this.props.history.listenBefore((location, callback) => {
const commandStates = this.getCommandStates()
if (commandStates['save'].disabled === false) {
if (this.editorSession.hasUnsavedChanges()) {
const editor = this.getEditor()
editor.send('changesNotSaved')
......@@ -63,18 +63,20 @@ class ContainerEditor extends SubstanceContainerEditor {
})
}
window.history.pushState(null, null, document.URL)
// window.history.pushState(null, null, document.URL)
window.addEventListener('popstate', this.controlBackButton)
}
// TODO -- review // messes up browser history
controlBackButton () {
const commandStates = this.getCommandStates()
if (!commandStates['save']) return
const url = '/books/' + this.props.book.id + '/book-builder'
window.removeEventListener('popstate', this.controlBackButton)
if (commandStates['save'].disabled === false) {
if (this.editorSession.hasUnsavedChanges()) {
const editor = this.getEditor()
window.history.pushState(null, null, document.URL)
......@@ -82,7 +84,7 @@ class ContainerEditor extends SubstanceContainerEditor {
editor.send('changesNotSaved')
editor.emit('send:route', {location: url, back: true})
} else {
this.props.history.goBack()
this.props.history.push(url)
}
}
onTextInput (event) {
......
......@@ -70,7 +70,7 @@ class ModalWarning extends Modal {
_saveExitWriter () {
this.context.editor.editorSession.save()
if (this.backButton) {
setTimeout(() => { this.context.editor.props.history.go(-2) }, 200)
setTimeout(() => { this.context.editor.props.history.go(-1) }, 200)
} else {
setTimeout(() => { this.context.editor.props.history.push(this.route) }, 200)
}
......@@ -86,7 +86,7 @@ class ModalWarning extends Modal {
this.context.editor.editorSession.save()
if (this.backButton) {
setTimeout(() => { this.context.editor.props.history.go(-2) }, 200)
setTimeout(() => { this.context.editor.props.history.go(-1) }, 200)
} else {
// TODO: Hack Check why cannot rerender editor so can push to url
setTimeout(() => { this.context.editor.props.history.push(this.route) }, 200)
......
......@@ -64,10 +64,12 @@ class MiniEditor extends ProseEditor {
_renderEditor ($$) {
return $$(ContainerEditor, {
book: this.props.book,
comments: this.props.comments,
containerId: this.props.containerId,
editorSession: this.editorSession,
disabled: this.props.disabled,
history: this.props.history,
fragment: this.props.fragment,
spellcheck: 'native',
trackChanges: this.props.trackChanges,
......
......@@ -44,22 +44,19 @@ class Notes extends Component {
const el = $$('div')
.addClass('notes-container').append(resizer)
const comments = this.getComments()
const fragment = this.getFragment()
const user = this.getUser()
const update = this.getUpdate()
const trackChanges = this.trackChanges()
const disabled = this.isInReadOnlyMode()
const miniEditorProps = this.getParentProps()
el.append($$(MiniEditor, {
comments: comments,
containerId: 'mini',
disabled: disabled,
book: miniEditorProps.book,
editorSession: miniEditorSession,
fragment: fragment,
trackChanges: trackChanges,
update: update,
user: user
comments: miniEditorProps.comments,
containerId: 'mini',
history: miniEditorProps.history,
disabled: miniEditorProps.disabled,
fragment: miniEditorProps.fragment,
trackChanges: miniEditorProps.trackChanges,
update: miniEditorProps.update,
user: miniEditorProps.user
}))
resizer.addEventListener('mousedown', this.initResize, false)
......@@ -118,29 +115,17 @@ class Notes extends Component {
getProvider () {
return this.context.notesProvider
}
getComments () {
return this.context.commentsProvider.config.comments
}
getUser () {
return this.context.editor.props.user
}
isInReadOnlyMode () {
return this.context.editor.props.disabled
}
getFragment () {
return this.context.editor.props.fragment
}
getUpdate () {
return this.context.editor.props.update
}
trackChanges () {
return this.context.editor.props.trackChanges
getParentProps () {
return {
comments: this.context.commentsProvider.config.comments,
disabled: this.context.editor.props.disabled,
book: this.context.editor.props.book,
fragment: this.context.editor.props.fragment,
history: this.context.editor.props.history,
trackChanges: this.context.editor.props.trackChanges,
update: this.context.editor.props.update,
user: this.context.editor.props.user
}
}
onNotesUpdated (change) {
......
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