mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-26 20:34:02 +03:00
🐛 reduce likelihood of "untitled" slugs (#722)
refs https://github.com/TryGhost/Ghost/issues/8482 - removes "save on first change" behaviour of the post body - always trigger a background save when title loses focus if the post is a draft - renames `updateTitle` action to `saveTitle` action to better describe it's purpose and to avoid confusion with the `updateTitle` task
This commit is contained in:
parent
108cd94173
commit
aa02f0decd
@ -55,8 +55,6 @@ export default Mixin.create({
|
|||||||
|
|
||||||
navIsClosed: reads('application.autoNav'),
|
navIsClosed: reads('application.autoNav'),
|
||||||
|
|
||||||
_hasChanged: false,
|
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
this._super(...arguments);
|
this._super(...arguments);
|
||||||
window.onbeforeunload = () => {
|
window.onbeforeunload = () => {
|
||||||
@ -426,11 +424,13 @@ export default Mixin.create({
|
|||||||
},
|
},
|
||||||
|
|
||||||
updateTitle: task(function* (newTitle) {
|
updateTitle: task(function* (newTitle) {
|
||||||
this.set('model.titleScratch', newTitle);
|
let model = this.get('model');
|
||||||
|
|
||||||
|
model.set('titleScratch', newTitle);
|
||||||
|
|
||||||
// if model is not new and title is not '(Untitled)', or model is new and
|
// if model is not new and title is not '(Untitled)', or model is new and
|
||||||
// has a title, don't generate a slug
|
// has a title, don't generate a slug
|
||||||
if ((!this.get('model.isNew') || this.get('model.title')) && newTitle !== '(Untitled)') {
|
if ((!model.get('isNew') || model.get('title')) && newTitle !== '(Untitled)') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -468,15 +468,6 @@ export default Mixin.create({
|
|||||||
updateScratch(value) {
|
updateScratch(value) {
|
||||||
this.set('model.scratch', value);
|
this.set('model.scratch', value);
|
||||||
|
|
||||||
// save on first change to trigger the new->edit transition
|
|
||||||
if (!this._hasChanged && this.get('model.isNew')) {
|
|
||||||
this._hasChanged = true;
|
|
||||||
this.send('save', {silent: true, backgroundSave: true});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this._hasChanged = true;
|
|
||||||
|
|
||||||
// save 3 seconds after last edit
|
// save 3 seconds after last edit
|
||||||
this.get('_autosave').perform();
|
this.get('_autosave').perform();
|
||||||
// force save at 60 seconds
|
// force save at 60 seconds
|
||||||
@ -547,18 +538,15 @@ export default Mixin.create({
|
|||||||
return transition.retry();
|
return transition.retry();
|
||||||
},
|
},
|
||||||
|
|
||||||
updateTitle() {
|
saveTitle() {
|
||||||
let currentTitle = this.get('model.title');
|
let currentTitle = this.get('model.title');
|
||||||
let newTitle = this.get('model.titleScratch').trim();
|
let newTitle = this.get('model.titleScratch').trim();
|
||||||
|
|
||||||
if (currentTitle === newTitle) {
|
if (newTitle === currentTitle) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.get('model.isDraft') && !this.get('model.isNew')) {
|
if (this.get('model.isDraft')) {
|
||||||
// this is preferrable to setting hasDirtyAttributes to false manually
|
|
||||||
this.model.set('title', newTitle);
|
|
||||||
|
|
||||||
this.send('save', {
|
this.send('save', {
|
||||||
silent: true,
|
silent: true,
|
||||||
backgroundSave: true
|
backgroundSave: true
|
||||||
|
@ -56,7 +56,7 @@
|
|||||||
tabindex="1"
|
tabindex="1"
|
||||||
shouldFocus=shouldFocusTitle
|
shouldFocus=shouldFocusTitle
|
||||||
autoExpand=".gh-markdown-editor-pane"
|
autoExpand=".gh-markdown-editor-pane"
|
||||||
focus-out="updateTitle"
|
focusOut=(action "saveTitle")
|
||||||
update=(action (perform updateTitle))
|
update=(action (perform updateTitle))
|
||||||
keyEvents=(hash
|
keyEvents=(hash
|
||||||
9=(action markdown.focus 'bottom')
|
9=(action markdown.focus 'bottom')
|
||||||
|
Loading…
Reference in New Issue
Block a user