this.draftDisplayIcon = this.$refs.draftDisplayIcon;
this.changelogInput = this.$refs.changelogInput;
this.changelogDisplay = this.$refs.changelogDisplay;
+ this.changeEditorButtons = this.$manyRefs.changeEditor;
+ this.switchDialogContainer = this.$refs.switchDialog;
// Translations
this.draftText = this.$opts.draftText;
// Draft Controls
onSelect(this.saveDraftButton, this.saveDraft.bind(this));
onSelect(this.discardDraftButton, this.discardDraft.bind(this));
+
+ // Change editor controls
+ onSelect(this.changeEditorButtons, this.changeEditor.bind(this));
}
setInitialFocus() {
data.markdown = this.editorMarkdown;
}
+ let didSave = false;
try {
const resp = await window.$http.put(`/ajax/page/${this.pageId}/save-draft`, data);
if (!this.isNewDraft) {
this.toggleDiscardDraftVisibility(true);
}
+
this.draftNotifyChange(`${resp.data.message} ${Dates.utcTimeStampToLocalTime(resp.data.timestamp)}`);
this.autoSave.last = Date.now();
if (resp.data.warning && !this.shownWarningsCache.has(resp.data.warning)) {
window.$events.emit('warning', resp.data.warning);
this.shownWarningsCache.add(resp.data.warning);
}
+
+ didSave = true;
} catch (err) {
// Save the editor content in LocalStorage as a last resort, just in case.
try {
window.$events.emit('error', this.autosaveFailText);
}
+ return didSave;
}
draftNotifyChange(text) {
this.discardDraftWrap.classList.toggle('hidden', !show);
}
+ async changeEditor(event) {
+ event.preventDefault();
+
+ const link = event.target.closest('a').href;
+ const dialog = this.switchDialogContainer.components['confirm-dialog'];
+ const [saved, confirmed] = await Promise.all([this.saveDraft(), dialog.show()]);
+
+ if (saved && confirmed) {
+ window.location = link;
+ }
+ }
+
}
export default PageEditor;
\ No newline at end of file