FIX: save drafts of new topics with titles but no body

This commit is contained in:
Neil Lalonde 2017-11-30 15:15:50 -05:00
parent dfd309c64f
commit bca90381cf
2 changed files with 26 additions and 5 deletions

View File

@ -740,7 +740,7 @@ export default Ember.Controller.extend({
},
shrink() {
if (this.get('model.replyDirty')) {
if (this.get('model.replyDirty') || (this.get('model.canEditTitle') && this.get('model.titleDirty'))) {
this.collapse();
} else {
this.close();

View File

@ -275,6 +275,16 @@ const Composer = RestModel.extend({
return this.get('reply') !== this.get('originalText');
}.property('reply', 'originalText'),
/**
Did the user make changes to the topic title?
@property titleDirty
**/
@computed('title', 'originalTitle')
titleDirty(title, originalTitle) {
return title !== originalTitle;
},
/**
Number of missing characters in the title until valid.
@ -519,6 +529,9 @@ const Composer = RestModel.extend({
}
if (opts.title) { this.set('title', opts.title); }
this.set('originalText', opts.draft ? '' : this.get('reply'));
if (this.get('editingFirstPost')) {
this.set('originalTitle', this.get('title'));
}
return false;
},
@ -741,10 +754,18 @@ const Composer = RestModel.extend({
saveDraft() {
// Do not save when drafts are disabled
if (this.get('disableDrafts')) return;
// Do not save when there is no reply
if (!this.get('reply')) return;
// Do not save when the reply's length is too small
if (this.get('replyLength') < this.siteSettings.min_post_length) return;
if (this.get('canEditTitle')) {
// Save title and/or post body
if (!this.get('title') && !this.get('reply')) return;
if (this.get('title') && this.get('titleLengthValid') &&
this.get('reply') && this.get('replyLength') < this.siteSettings.min_post_length) return;
} else {
// Do not save when there is no reply
if (!this.get('reply')) return;
// Do not save when the reply's length is too small
if (this.get('replyLength') < this.siteSettings.min_post_length) return;
}
const data = {
reply: this.get('reply'),