2018-01-17 16:27:37 +03:00
import $ from 'jquery' ;
import AuthenticatedRoute from 'ghost-admin/routes/authenticated' ;
import ShortcutsRoute from 'ghost-admin/mixins/shortcuts-route' ;
import ctrlOrCmd from 'ghost-admin/utils/ctrl-or-cmd' ;
2018-07-10 16:14:08 +03:00
import { htmlSafe } from '@ember/string' ;
2018-01-17 16:27:37 +03:00
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
let generalShortcuts = { } ;
generalShortcuts [ ` ${ ctrlOrCmd } +shift+p ` ] = 'publish' ;
export default AuthenticatedRoute . extend ( ShortcutsRoute , {
2018-07-10 16:14:08 +03:00
feature : service ( ) ,
notifications : service ( ) ,
userAgent : 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' ] ,
shortcuts : generalShortcuts ,
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
} ,
2018-07-10 16:14:08 +03:00
setupController ( ) {
this . _super ( ... arguments ) ;
2018-08-08 19:31:38 +03:00
// edge has known issues
2019-06-25 16:52:09 +03:00
if ( this . userAgent . browser . isEdge && this . userAgent . parser . getEngine ( ) . name === 'EdgeHTML' ) {
2018-08-08 19:31:38 +03:00
this . notifications . showAlert (
2018-08-22 19:38:37 +03:00
htmlSafe ( 'Microsoft Edge is not currently supported. Please switch to <a href="https://ghost.org/downloads/" target="_blank" rel="noopener">Ghost Desktop</a> or a recent version of Chrome/Firefox/Safari.' ) ,
2018-08-08 19:31:38 +03:00
{ type : 'info' , key : 'koenig.browserSupport' }
) ;
}
2018-07-10 16:14:08 +03:00
2018-08-08 19:31:38 +03:00
// mobile browsers are not currently supported
if ( this . userAgent . device . isMobile || this . userAgent . device . isTablet ) {
this . notifications . showAlert (
2018-08-22 19:38:37 +03:00
htmlSafe ( 'Mobile editing is not currently supported. Please use a desktop browser or <a href="https://ghost.org/downloads/" target="_blank" rel="noopener">Ghost Desktop</a>.' ) ,
2018-08-08 19:31:38 +03:00
{ type : 'info' , key : 'koenig.browserSupport' }
) ;
2018-07-10 16:14:08 +03:00
}
} ,
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
} ) ;
} ,
publish ( ) {
this . _blurAndScheduleAction ( function ( ) {
2019-03-06 16:53:54 +03:00
this . controller . send ( 'setSaveType' , 'publish' ) ;
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
} ,
2020-02-27 18:19:31 +03:00
redirectToContentScreen ( displayName ) {
this . transitionTo ( displayName === 'page' ? 'pages' : 'posts' ) ;
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
} ,
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 ) ;
}
} ) ;