mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-13 22:41:32 -05:00
eb949aafae
closes #2426, closes #2781, closes #2913 - Concatenate vendor files on change of js in core/shared/ - Add all the markerManager stuff to its own mixin - make markers a shared object for all that mix it in. makes it easier to use helper functions in different modules - add getMarkdown method, returns object with two keys holding the markdown: one with markers, the other without - Clear markers when codemirror is destroyed - make Editor subcomponents communicate through the Editor Controller - Set Codemirror and html preview shared scrolling - Set CodeMirror, html preview css scroll class with util - Create 'scratch' property in Editor controller; prevents a model save wiping image markers due to markdown bindings - Add editor and html preview actions to handle img upload start/finish - disable codemirror when an image is being uploaded, enables on success or failure - Fix editor wordcount when there are 0 words - Add modal dialog when transitioning out of the editor with an unsaved post - Add window.onbeforeunload handling with `.unloadDirtyMessage()` on editor controller - and various other things
76 lines
2.4 KiB
JavaScript
76 lines
2.4 KiB
JavaScript
import styleBody from 'ghost/mixins/style-body';
|
|
import AuthenticatedRoute from 'ghost/routes/authenticated';
|
|
|
|
var EditorEditRoute = AuthenticatedRoute.extend(styleBody, {
|
|
classNames: ['editor'],
|
|
|
|
model: function (params) {
|
|
var self = this,
|
|
post,
|
|
postId;
|
|
|
|
postId = Number(params.post_id);
|
|
|
|
if (!Number.isInteger(postId) || !Number.isFinite(postId) || postId <= 0) {
|
|
this.transitionTo('posts.index');
|
|
}
|
|
|
|
post = this.store.getById('post', postId);
|
|
|
|
if (post) {
|
|
return post;
|
|
}
|
|
|
|
return this.store.filter('post', { status: 'all', staticPages: 'all' }, function (post) {
|
|
//post.get('id') returns a string, so compare with params.post_id
|
|
return post.get('id') === params.post_id;
|
|
}).then(function (records) {
|
|
var post = records.get('firstObject');
|
|
|
|
if (post) {
|
|
return post;
|
|
}
|
|
|
|
return self.transitionTo('posts.index');
|
|
});
|
|
},
|
|
|
|
serialize: function (model) {
|
|
return {post_id: model.get('id')};
|
|
},
|
|
|
|
setupController: function (controller, model) {
|
|
this._super(controller, model);
|
|
controller.set('scratch', model.get('markdown'));
|
|
|
|
model.get('tags').then(function (tags) {
|
|
// used to check if anything has changed in the editor
|
|
controller.set('previousTagNames', tags.mapBy('name'));
|
|
});
|
|
},
|
|
|
|
actions: {
|
|
willTransition: function (transition) {
|
|
var controller = this.get('controller'),
|
|
isDirty = controller.get('isDirty'),
|
|
|
|
model = controller.get('model'),
|
|
isSaving = model.get('isSaving'),
|
|
isDeleted = model.get('isDeleted');
|
|
|
|
// when `isDeleted && isSaving`, model is in-flight, being saved
|
|
// to the server. in that case we can probably just transition
|
|
// now and have the server return the record, thereby updating it
|
|
if (!(isDeleted && isSaving) && isDirty) {
|
|
transition.abort();
|
|
this.send('openModal', 'leave-editor', [controller, transition]);
|
|
return;
|
|
}
|
|
|
|
// since the transition is now certain to complete..
|
|
window.onbeforeunload = null;
|
|
}
|
|
}
|
|
});
|
|
|
|
export default EditorEditRoute;
|