From feecb1374a4f777c3e5bfa5174f19ec6feba74e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Tue, 19 Mar 2013 01:24:10 +0100 Subject: [PATCH] consistent behavior of the composer's create button --- .../javascripts/discourse/models/composer.js | 22 ++++++++++--------- .../templates/composer.js.handlebars | 8 +++---- .../discourse/templates/topic.js.handlebars | 2 +- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/discourse/models/composer.js b/app/assets/javascripts/discourse/models/composer.js index 7e3c94369ac..1484dd173aa 100644 --- a/app/assets/javascripts/discourse/models/composer.js +++ b/app/assets/javascripts/discourse/models/composer.js @@ -125,7 +125,6 @@ Discourse.Composer = Discourse.Model.extend({ Discourse.Utilities.tinyAvatar(replyUsername) + " " + replyUsername; } - } switch (this.get('action')) { @@ -155,14 +154,20 @@ Discourse.Composer = Discourse.Model.extend({ // Can't submit while loading if (this.get('loading')) return true; - // Title is required on new posts - if (this.get('creatingTopic') && this.get('titleLength') < Discourse.SiteSettings.min_topic_title_length) return true; + // Title is required when: + // - creating a new topic + // - editing the 1st post + // - creating a private message + if (this.get('editTitle') && this.get('titleLength') < Discourse.SiteSettings.min_topic_title_length) return true; - // Otherwise just reply is required + // Need at least one user when sending a private message + if (this.get('creatingPrivateMessage') && (this.get('targetUsernames').trim() + ',').indexOf(',') === 0) return true; + + // reply is always required if (this.get('replyLength') < Discourse.SiteSettings.min_post_length) return true; return false; - }).property('reply', 'title', 'creatingTopic', 'loading'), + }).property('loading', 'editTitle', 'titleLength', 'targetUsernames', 'replyLength'), // The text for the save button saveText: (function() { @@ -179,8 +184,7 @@ Discourse.Composer = Discourse.Model.extend({ }).property('action'), hasMetaData: (function() { - var metaData; - metaData = this.get('metaData'); + var metaData = this.get('metaData'); if (!this.get('metaData')) { return false; } @@ -430,8 +434,6 @@ Discourse.Composer = Discourse.Model.extend({ if (this.get('disableDrafts')) return; // Do not save when there is no reply if (!this.get('reply')) return; - // Do not save when the title's length is too small (only when creating a new post) - if (this.get('creatingTopic') && this.get('titleLength') < Discourse.SiteSettings.min_topic_title_length) return; // Do not save when the reply's length is too small if (this.get('replyLength') < Discourse.SiteSettings.min_post_length) return; @@ -473,7 +475,7 @@ Discourse.Composer = Discourse.Model.extend({ // hide the counters if the currently focused text field is OK this.set('draftStatus', null); - }).observes('reply', 'title'), + }).observes('replyLength', 'titleLength'), /** Computes the length of the title minus non-significant whitespaces diff --git a/app/assets/javascripts/discourse/templates/composer.js.handlebars b/app/assets/javascripts/discourse/templates/composer.js.handlebars index e9aece095c8..317b739f7d0 100644 --- a/app/assets/javascripts/discourse/templates/composer.js.handlebars +++ b/app/assets/javascripts/discourse/templates/composer.js.handlebars @@ -28,9 +28,9 @@ {{#if content.editTitle}}
{{#if content.creatingPrivateMessage}} - {{view Discourse.TextField id="private-message-users" class="span8" placeholderKey="composer.users_placeholder"}} + {{view Discourse.TextField id="private-message-users" class="span8" placeholderKey="composer.users_placeholder" tabindex="1"}} {{/if}} - {{view Discourse.TextField valueBinding="content.title" tabindex="1" id="reply-title" maxlength="255" class="span8" placeholderKey="composer.title_placeholder"}} + {{view Discourse.TextField valueBinding="content.title" tabindex="2" id="reply-title" maxlength="255" class="span8" placeholderKey="composer.title_placeholder"}} {{#unless content.creatingPrivateMessage}} {{view Discourse.ComboboxViewCategory valueAttribute="name" contentBinding="Discourse.site.categories" valueBinding="content.categoryName"}} {{#if content.archetype.hasOptions}} @@ -43,7 +43,7 @@
- {{view Discourse.NotifyingTextArea parentBinding="view" tabindex="2" valueBinding="content.reply" id="wmd-input" placeholderKey="composer.reply_placeholder"}} + {{view Discourse.NotifyingTextArea parentBinding="view" tabindex="3" valueBinding="content.reply" id="wmd-input" placeholderKey="composer.reply_placeholder"}}
@@ -56,7 +56,7 @@ {{#if Discourse.currentUser}}
- + {{i18n cancel}} {{#if view.loadingImage}}
diff --git a/app/assets/javascripts/discourse/templates/topic.js.handlebars b/app/assets/javascripts/discourse/templates/topic.js.handlebars index cc163274e52..de7bbb5f133 100644 --- a/app/assets/javascripts/discourse/templates/topic.js.handlebars +++ b/app/assets/javascripts/discourse/templates/topic.js.handlebars @@ -9,7 +9,7 @@ {{/if}} {{#if view.editingTopic}} - + {{view Discourse.ComboboxViewCategory valueAttribute="name" contentBinding="Discourse.site.categories" sourceBinding="view.topic.categoryName"}}