2014-03-09 22:44:08 -05:00
|
|
|
import AuthenticatedRoute from 'ghost/routes/authenticated';
|
2014-05-21 08:53:00 -05:00
|
|
|
import styleBody from 'ghost/mixins/style-body';
|
2014-03-09 22:44:08 -05:00
|
|
|
|
2014-06-09 23:44:29 -05:00
|
|
|
var EditorNewRoute = AuthenticatedRoute.extend(styleBody, {
|
2014-03-09 22:44:08 -05:00
|
|
|
classNames: ['editor'],
|
|
|
|
|
2014-05-21 08:53:00 -05:00
|
|
|
model: function () {
|
2014-06-05 20:18:03 -05:00
|
|
|
return this.store.createRecord('post');
|
|
|
|
},
|
|
|
|
|
|
|
|
setupController: function (controller, model) {
|
|
|
|
this._super(controller, model);
|
|
|
|
controller.set('scratch', '');
|
|
|
|
|
|
|
|
// used to check if anything has changed in the editor
|
|
|
|
controller.set('previousTagNames', Ember.A());
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
willTransition: function (transition) {
|
|
|
|
var controller = this.get('controller'),
|
|
|
|
isDirty = controller.get('isDirty'),
|
|
|
|
|
|
|
|
model = controller.get('model'),
|
|
|
|
isNew = model.get('isNew'),
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isNew) {
|
|
|
|
model.deleteRecord();
|
|
|
|
}
|
|
|
|
|
|
|
|
// since the transition is now certain to complete..
|
|
|
|
window.onbeforeunload = null;
|
|
|
|
}
|
2014-03-09 22:44:08 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-06-09 23:44:29 -05:00
|
|
|
export default EditorNewRoute;
|