From 1097d51b33c4a4e37d3d873a39acee57b57a41f8 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 20 May 2013 12:47:59 -0400 Subject: [PATCH] Replaced {{view Discourse.TextField}} with {{textfield}} helper. --- .../admin/templates/email_logs.js.handlebars | 8 ++--- .../admin/templates/groups.js.handlebars | 2 +- .../templates/site_settings.js.handlebars | 4 +-- .../admin/templates/users_list.js.handlebars | 8 ++--- .../user_private_messages_controller.js | 2 +- .../discourse/helpers/application_helpers.js | 35 +++++++++++++++---- .../discourse/helpers/i18n_helpers.js | 14 ++++---- .../templates/auto_close_form.js.handlebars | 2 +- .../templates/composer.js.handlebars | 2 +- .../modal/create_account.js.handlebars | 20 +++++------ .../modal/edit_category.js.handlebars | 8 ++--- .../modal/forgot_password.js.handlebars | 4 +-- .../templates/modal/invite.js.handlebars | 8 ++--- .../modal/invite_private.js.handlebars | 8 ++--- .../templates/modal/login.js.handlebars | 2 +- .../templates/modal/split_topic.js.handlebars | 2 +- .../discourse/views/button_view.js | 10 +++--- .../discourse/views/input_tip_view.js | 18 +++++----- 18 files changed, 91 insertions(+), 66 deletions(-) diff --git a/app/assets/javascripts/admin/templates/email_logs.js.handlebars b/app/assets/javascripts/admin/templates/email_logs.js.handlebars index a05c63639..ee549c155 100644 --- a/app/assets/javascripts/admin/templates/email_logs.js.handlebars +++ b/app/assets/javascripts/admin/templates/email_logs.js.handlebars @@ -1,9 +1,9 @@
- {{view Discourse.TextField valueBinding="controller.testEmailAddress" placeholderKey="admin.email_logs.test_email_address"}} + {{textField value=testEmailAddress placeholderKey="admin.email_logs.test_email_address"}}
- + {{#if controller.sentTestEmail}}{{i18n admin.email_logs.sent_test}}{{/if}}
@@ -16,9 +16,9 @@ {{i18n admin.email_logs.email_type}} - {{#if controller.content.length}} + {{#if model.length}} {{#group}} - {{#collection contentBinding="controller.content" tagName="tbody" itemTagName="tr"}} + {{#collection contentBinding="model" tagName="tbody" itemTagName="tr"}} {{date view.content.created_at}} {{#if view.content.user}} diff --git a/app/assets/javascripts/admin/templates/groups.js.handlebars b/app/assets/javascripts/admin/templates/groups.js.handlebars index 89038c43e..ea5070ef1 100644 --- a/app/assets/javascripts/admin/templates/groups.js.handlebars +++ b/app/assets/javascripts/admin/templates/groups.js.handlebars @@ -22,7 +22,7 @@ {{#if automatic}}

{{name}}

{{else}} - {{view Discourse.TextField valueBinding="name" placeholderKey="admin.groups.name_placeholder"}} + {{textField value=name placeholderKey="admin.groups.name_placeholder"}} {{/if}} {{view Discourse.UserSelector id="group-users" placeholderKey="admin.groups.selector_placeholder" tabindex="1" usernamesBinding="usernames"}} diff --git a/app/assets/javascripts/admin/templates/site_settings.js.handlebars b/app/assets/javascripts/admin/templates/site_settings.js.handlebars index dfc10a508..f8e2ceb3e 100644 --- a/app/assets/javascripts/admin/templates/site_settings.js.handlebars +++ b/app/assets/javascripts/admin/templates/site_settings.js.handlebars @@ -1,12 +1,12 @@
diff --git a/app/assets/javascripts/admin/templates/users_list.js.handlebars b/app/assets/javascripts/admin/templates/users_list.js.handlebars index f38da4df6..d7e25942b 100644 --- a/app/assets/javascripts/admin/templates/users_list.js.handlebars +++ b/app/assets/javascripts/admin/templates/users_list.js.handlebars @@ -9,13 +9,13 @@
- {{view Discourse.TextField valueBinding="controller.username" placeholderKey="username"}} + {{textField value=username placeholderKey="username"}}
{{#if hasSelection}}
- +
{{/if}} @@ -49,7 +49,7 @@ {{#each content}} - {{#if controller.showApproval}} + {{#if showApproval}} {{#if can_approve}} {{view Ember.Checkbox checkedBinding="selected"}} @@ -67,7 +67,7 @@ {{{unbound created_at_age}}} - {{#if controller.showApproval}} + {{#if showApproval}} {{#if approved}} {{i18n yes_value}} diff --git a/app/assets/javascripts/discourse/controllers/user_private_messages_controller.js b/app/assets/javascripts/discourse/controllers/user_private_messages_controller.js index eea4d849b..83d44e1e6 100644 --- a/app/assets/javascripts/discourse/controllers/user_private_messages_controller.js +++ b/app/assets/javascripts/discourse/controllers/user_private_messages_controller.js @@ -9,7 +9,7 @@ Discourse.UserPrivateMessagesController = Discourse.ObjectController.extend({ editPreferences: function() { - return Discourse.URL.routeTo("/users/" + (this.get('content.username_lower')) + "/preferences"); + Discourse.URL.routeTo("/users/" + (this.get('content.username_lower')) + "/preferences"); }, composePrivateMessage: function() { diff --git a/app/assets/javascripts/discourse/helpers/application_helpers.js b/app/assets/javascripts/discourse/helpers/application_helpers.js index 2054034e6..44d86537e 100644 --- a/app/assets/javascripts/discourse/helpers/application_helpers.js +++ b/app/assets/javascripts/discourse/helpers/application_helpers.js @@ -1,3 +1,15 @@ +/** + Allows us to supply bindings without "binding" to a helper. +**/ +function normalizeHash(hash, hashTypes) { + for (var prop in hash) { + if (hashTypes[prop] === 'ID') { + hash[prop + 'Binding'] = hash[prop]; + delete hash[prop]; + } + } +} + /** Breaks up a long string @@ -66,16 +78,27 @@ Ember.Handlebars.registerHelper('textField', function(options) { var hash = options.hash, types = options.hashTypes; - for (var prop in hash) { - if (types[prop] === 'ID') { - hash[prop + 'Binding'] = hash[prop]; - delete hash[prop]; - } - } + normalizeHash(hash, types); return Ember.Handlebars.helpers.view.call(this, Discourse.TextField, options); }); +/** + Inserts a Discourse.InputTipView + + @method inputTip + @for Handlebars +**/ +Ember.Handlebars.registerHelper('inputTip', function(options) { + var hash = options.hash, + types = options.hashTypes; + + normalizeHash(hash, types); + + return Ember.Handlebars.helpers.view.call(this, Discourse.InputTipView, options); +}); + + /** Produces a bound link to a category diff --git a/app/assets/javascripts/discourse/helpers/i18n_helpers.js b/app/assets/javascripts/discourse/helpers/i18n_helpers.js index 12506cb96..2e3eb8c19 100644 --- a/app/assets/javascripts/discourse/helpers/i18n_helpers.js +++ b/app/assets/javascripts/discourse/helpers/i18n_helpers.js @@ -35,17 +35,19 @@ Ember.String.i18n = function(scope, options) { @for Handlebars **/ Ember.Handlebars.registerHelper('countI18n', function(key, options) { - var view; - view = Discourse.View.extend({ + var view = Discourse.View.extend({ tagName: 'span', + render: function(buffer) { - return buffer.push(Ember.String.i18n(key, { + buffer.push(Ember.String.i18n(key, { count: this.get('count') })); }, - countChanged: (function() { - return this.rerender(); - }).observes('count') + + countChanged: function() { + this.rerender(); + }.observes('count') + }); return Ember.Handlebars.helpers.view.call(this, view, options); }); diff --git a/app/assets/javascripts/discourse/templates/auto_close_form.js.handlebars b/app/assets/javascripts/discourse/templates/auto_close_form.js.handlebars index eff55b4f0..ce93f2e90 100644 --- a/app/assets/javascripts/discourse/templates/auto_close_form.js.handlebars +++ b/app/assets/javascripts/discourse/templates/auto_close_form.js.handlebars @@ -1,6 +1,6 @@
{{view.label}} - {{view Discourse.TextField valueBinding="view.autoCloseDays" maxlength="3"}} + {{textField value=view.autoCloseDays maxlength="3"}} {{i18n composer.auto_close_units}}
diff --git a/app/assets/javascripts/discourse/templates/composer.js.handlebars b/app/assets/javascripts/discourse/templates/composer.js.handlebars index 4150619b4..0805489ae 100644 --- a/app/assets/javascripts/discourse/templates/composer.js.handlebars +++ b/app/assets/javascripts/discourse/templates/composer.js.handlebars @@ -32,7 +32,7 @@ {{#if content.creatingPrivateMessage}} {{view Discourse.UserSelector topicIdBinding="controller.controllers.topic.content.id" excludeCurrentUser="true" id="private-message-users" class="span8" placeholderKey="composer.users_placeholder" tabindex="1" usernamesBinding="content.targetUsernames"}} {{/if}} - {{view Discourse.TextField valueBinding="content.title" tabindex="2" id="reply-title" maxlength="255" class="span8" placeholderKey="composer.title_placeholder"}} + {{textField value=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}} diff --git a/app/assets/javascripts/discourse/templates/modal/create_account.js.handlebars b/app/assets/javascripts/discourse/templates/modal/create_account.js.handlebars index 1c8b34d58..5c004a348 100644 --- a/app/assets/javascripts/discourse/templates/modal/create_account.js.handlebars +++ b/app/assets/javascripts/discourse/templates/modal/create_account.js.handlebars @@ -6,8 +6,8 @@ - {{view Discourse.TextField valueBinding="view.accountName" elementId="new-account-name" autofocus="autofocus"}} -  {{view Discourse.InputTipView validationBinding="view.nameValidation"}} + {{textField value=view.accountName id="new-account-name" autofocus="autofocus"}} +  {{inputTip validation=nameValidation}} @@ -18,8 +18,8 @@ - {{view Ember.TextField valueBinding="view.accountEmail" id="new-account-email"}} -  {{view Discourse.InputTipView validationBinding="view.emailValidation"}} + {{input value=view.accountEmail id="new-account-email"}} +  {{inputTip validation=view.emailValidation}} @@ -30,8 +30,8 @@ - {{view Ember.TextField valueBinding="view.accountUsername" id="new-account-username" maxlength="15"}} -  {{view Discourse.InputTipView validationBinding="view.usernameValidation"}} + {{input value=view.accountUsername id="new-account-username" maxlength="15"}} +  {{inputTip validation=view.usernameValidation}} @@ -43,8 +43,8 @@ - {{view Ember.TextField valueBinding="view.accountPassword" type="password" id="new-account-password"}} -  {{view Discourse.InputTipView validationBinding="view.passwordValidation"}} + {{input type="password" value=view.accountPassword id="new-account-password"}} +  {{inputTip validation=view.passwordValidation}} {{/if}} @@ -52,8 +52,8 @@ - {{view Ember.TextField valueBinding="view.accountPasswordConfirm" type="password" id="new-account-password-confirmation"}} - {{view Ember.TextField valueBinding="view.accountChallenge" id="new-account-challenge"}} + {{input type="password" value=view.accountPasswordConfirm id="new-account-confirmation"}} + {{input value=view.accountChallenge id="new-account-challenge"}} diff --git a/app/assets/javascripts/discourse/templates/modal/edit_category.js.handlebars b/app/assets/javascripts/discourse/templates/modal/edit_category.js.handlebars index e8c5a58a6..b63548fbd 100644 --- a/app/assets/javascripts/discourse/templates/modal/edit_category.js.handlebars +++ b/app/assets/javascripts/discourse/templates/modal/edit_category.js.handlebars @@ -20,7 +20,7 @@
- {{view Discourse.TextField valueBinding="name" placeholderKey="category.name_placeholder" maxlength="50"}} + {{textField value=name placeholderKey="category.name_placeholder" maxlength="50"}}
{{#unless is_uncategorized}} @@ -46,13 +46,13 @@
{{i18n category.background_color}}: - #{{view Discourse.TextField valueBinding="color" placeholderKey="category.color_placeholder" maxlength="6"}} + #{{textField value=color placeholderKey="category.color_placeholder" maxlength="6"}} {{view Discourse.ColorsView colorsBinding="view.backgroundColors" usedColorsBinding="view.usedBackgroundColors" valueBinding="color"}}
{{i18n category.foreground_color}}: - #{{view Discourse.TextField valueBinding="text_color" placeholderKey="category.color_placeholder" maxlength="6"}} + #{{textField value=text_color placeholderKey="category.color_placeholder" maxlength="6"}} {{view Discourse.ColorsView colorsBinding="view.foregroundColors" valueBinding="text_color"}}
@@ -63,7 +63,7 @@
{{#if secure}} diff --git a/app/assets/javascripts/discourse/templates/modal/forgot_password.js.handlebars b/app/assets/javascripts/discourse/templates/modal/forgot_password.js.handlebars index a3ad51b8f..af964b8b1 100644 --- a/app/assets/javascripts/discourse/templates/modal/forgot_password.js.handlebars +++ b/app/assets/javascripts/discourse/templates/modal/forgot_password.js.handlebars @@ -1,8 +1,8 @@ diff --git a/app/assets/javascripts/discourse/views/button_view.js b/app/assets/javascripts/discourse/views/button_view.js index 1642af961..4f06bafd4 100644 --- a/app/assets/javascripts/discourse/views/button_view.js +++ b/app/assets/javascripts/discourse/views/button_view.js @@ -11,19 +11,19 @@ Discourse.ButtonView = Discourse.View.extend({ classNameBindings: [':btn', ':standard', 'dropDownToggle'], attributeBindings: ['data-not-implemented', 'title', 'data-toggle', 'data-share-url'], - title: (function() { + title: function() { return Em.String.i18n(this.get('helpKey') || this.get('textKey')); - }).property('helpKey'), + }.property('helpKey'), - text: (function() { + text: function() { return Em.String.i18n(this.get('textKey')); - }).property('textKey'), + }.property('textKey'), render: function(buffer) { if (this.renderIcon) { this.renderIcon(buffer); } - return buffer.push(this.get('text')); + buffer.push(this.get('text')); } }); diff --git a/app/assets/javascripts/discourse/views/input_tip_view.js b/app/assets/javascripts/discourse/views/input_tip_view.js index 22337922e..108cf0c1d 100644 --- a/app/assets/javascripts/discourse/views/input_tip_view.js +++ b/app/assets/javascripts/discourse/views/input_tip_view.js @@ -10,22 +10,22 @@ Discourse.InputTipView = Discourse.View.extend({ templateName: 'input_tip', classNameBindings: [':tip', 'good', 'bad'], - good: (function() { + good: function() { return !this.get('validation.failed'); - }).property('validation'), + }.property('validation'), - bad: (function() { + bad: function() { return this.get('validation.failed'); - }).property('validation'), + }.property('validation'), - triggerRender: (function() { + triggerRender: function() { return this.rerender(); - }).observes('validation'), + }.observes('validation'), render: function(buffer) { - var icon, reason; - if (reason = this.get('validation.reason')) { - icon = this.get('good') ? 'icon-ok' : 'icon-remove'; + var reason = this.get('validation.reason'); + if (reason) { + var icon = this.get('good') ? 'icon-ok' : 'icon-remove'; return buffer.push(" " + reason); } }