From 619647fd539a72108fdcb85d829d85552c5f4d18 Mon Sep 17 00:00:00 2001 From: Jeff Jewiss Date: Sun, 10 Apr 2016 16:57:00 -0400 Subject: [PATCH] Saves post title on focus blur if status is draft Closes #6656 - adds an action to update the title - checks if the post title has changed and is a draft and sends a silent + background save action - includes the action on the focus-out event on the post title --- .../app/mixins/editor-base-controller.js | 19 +++++++++++++++++++ core/client/app/templates/editor/edit.hbs | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/core/client/app/mixins/editor-base-controller.js b/core/client/app/mixins/editor-base-controller.js index 2b18a4bc87..01086f057b 100644 --- a/core/client/app/mixins/editor-base-controller.js +++ b/core/client/app/mixins/editor-base-controller.js @@ -398,6 +398,25 @@ export default Mixin.create({ return transition.retry(); }, + updateTitle() { + let currentTitle = this.model.get('title'); + let newTitle = this.model.get('titleScratch').trim(); + + if (currentTitle === newTitle) { + return; + } + + if (this.get('model.isDraft') && !this.get('model.isNew')) { + // this is preferrable to setting hasDirtyAttributes to false manually + this.model.set('title', newTitle); + + this.send('save', { + silent: true, + backgroundSave: true + }); + } + }, + toggleReAuthenticateModal() { this.toggleProperty('showReAuthenticateModal'); } diff --git a/core/client/app/templates/editor/edit.hbs b/core/client/app/templates/editor/edit.hbs index 55411a4101..42f254ae6e 100644 --- a/core/client/app/templates/editor/edit.hbs +++ b/core/client/app/templates/editor/edit.hbs @@ -1,7 +1,7 @@
{{#gh-view-title classNames="gh-editor-title" openMobileMenu="openMobileMenu"}} - {{gh-trim-focus-input type="text" id="entry-title" placeholder="Your Post Title" value=model.titleScratch tabindex="1" focus=shouldFocusTitle}} + {{gh-trim-focus-input type="text" id="entry-title" placeholder="Your Post Title" value=model.titleScratch tabindex="1" focus=shouldFocusTitle focus-out="updateTitle" }} {{/gh-view-title}}