2018-01-17 16:27:37 +03:00
|
|
|
import $ from 'jquery';
|
|
|
|
import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
|
|
|
|
import {run} from '@ember/runloop';
|
2018-07-10 16:14:08 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2018-01-17 16:27:37 +03:00
|
|
|
|
2022-01-16 16:48:58 +03:00
|
|
|
export default AuthenticatedRoute.extend({
|
2018-07-10 16:14:08 +03:00
|
|
|
feature: service(),
|
|
|
|
notifications: service(),
|
2018-07-26 14:53:23 +03:00
|
|
|
ui: service(),
|
2018-07-10 16:14:08 +03:00
|
|
|
|
2018-01-17 16:27:37 +03:00
|
|
|
classNames: ['editor'],
|
|
|
|
|
2018-07-26 14:53:23 +03:00
|
|
|
activate() {
|
|
|
|
this._super(...arguments);
|
2018-08-08 19:31:38 +03:00
|
|
|
this.ui.set('isFullScreen', true);
|
2018-07-26 14:53:23 +03:00
|
|
|
},
|
|
|
|
|
2022-09-29 15:34:01 +03:00
|
|
|
setupController(controller, model, transition) {
|
|
|
|
if (transition.from?.name === 'posts.analytics') {
|
|
|
|
controller.fromAnalytics = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
resetController(controller) {
|
|
|
|
controller.fromAnalytics = false;
|
|
|
|
},
|
|
|
|
|
2018-07-26 14:53:23 +03:00
|
|
|
deactivate() {
|
|
|
|
this._super(...arguments);
|
2018-07-26 15:28:02 +03:00
|
|
|
this.ui.set('isFullScreen', false);
|
2018-07-26 14:53:23 +03:00
|
|
|
},
|
|
|
|
|
2018-01-17 16:27:37 +03:00
|
|
|
actions: {
|
|
|
|
save() {
|
|
|
|
this._blurAndScheduleAction(function () {
|
2019-03-06 16:53:54 +03:00
|
|
|
this.controller.send('save');
|
2018-01-17 16:27:37 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
authorizationFailed() {
|
2019-03-06 16:53:54 +03:00
|
|
|
this.controller.send('toggleReAuthenticateModal');
|
2018-01-17 16:27:37 +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);
|
|
|
|
}
|
|
|
|
|
2019-03-06 16:53:54 +03:00
|
|
|
this.controller.willTransition(transition);
|
2018-01-17 16:27:37 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-05-20 18:16:19 +03:00
|
|
|
buildRouteInfoMetadata() {
|
|
|
|
return {
|
|
|
|
titleToken: () => {
|
|
|
|
return this.get('controller.post.title') || 'Editor';
|
2019-06-18 13:47:21 +03:00
|
|
|
},
|
2021-07-01 12:15:34 +03:00
|
|
|
bodyClasses: ['gh-body-fullscreen'],
|
2019-06-18 13:47:21 +03:00
|
|
|
mainClasses: ['gh-main-white']
|
2019-05-20 18:16:19 +03:00
|
|
|
};
|
2019-01-21 14:44:30 +03:00
|
|
|
},
|
|
|
|
|
2018-01-17 16:27:37 +03:00
|
|
|
_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);
|
|
|
|
}
|
|
|
|
});
|