2022-08-23 13:45:50 +03:00
|
|
|
import $ from 'jquery';
|
|
|
|
import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
|
|
|
|
import {run} from '@ember/runloop';
|
|
|
|
import {inject as service} from '@ember/service';
|
|
|
|
|
|
|
|
export default AuthenticatedRoute.extend({
|
|
|
|
feature: service(),
|
|
|
|
notifications: service(),
|
|
|
|
router: service(),
|
|
|
|
ui: service(),
|
|
|
|
|
|
|
|
classNames: ['editor'],
|
|
|
|
|
|
|
|
activate() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this.ui.set('isFullScreen', true);
|
|
|
|
},
|
|
|
|
|
2022-11-11 12:48:07 +03:00
|
|
|
setupController(controller, model, transition) {
|
|
|
|
if (transition.from?.name === 'posts.analytics') {
|
|
|
|
controller.fromAnalytics = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
resetController(controller) {
|
|
|
|
controller.fromAnalytics = false;
|
|
|
|
},
|
|
|
|
|
2022-08-23 13:45:50 +03:00
|
|
|
deactivate() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this.ui.set('isFullScreen', false);
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
save() {
|
|
|
|
this._blurAndScheduleAction(function () {
|
|
|
|
this.controller.send('save');
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
authorizationFailed() {
|
2023-10-13 12:13:52 +03:00
|
|
|
// noop - re-auth is handled by controller save
|
|
|
|
return;
|
2022-08-23 13:45:50 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
willTransition(transition) {
|
|
|
|
// exit early if an upgrade is required because our extended route
|
|
|
|
// class will abort the transition and show an error
|
|
|
|
if (this.get('upgradeStatus.isRequired')) {
|
|
|
|
return this._super(...arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.controller.willTransition(transition);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
buildRouteInfoMetadata() {
|
|
|
|
return {
|
|
|
|
titleToken: () => {
|
|
|
|
return this.get('controller.post.title') || 'Editor';
|
|
|
|
},
|
|
|
|
bodyClasses: ['gh-body-fullscreen'],
|
|
|
|
mainClasses: ['gh-main-white']
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
_blurAndScheduleAction(func) {
|
|
|
|
let selectedElement = $(document.activeElement);
|
|
|
|
|
|
|
|
// TODO: we should trigger a blur for textareas as well as text inputs
|
|
|
|
if (selectedElement.is('input[type="text"]')) {
|
|
|
|
selectedElement.trigger('focusout');
|
|
|
|
}
|
|
|
|
|
|
|
|
// wait for actions triggered by the focusout to finish before saving
|
|
|
|
run.scheduleOnce('actions', this, func);
|
|
|
|
}
|
|
|
|
});
|