Replaced {{view Discourse.TextField}} with {{textfield}} helper.

This commit is contained in:
Robin Ward 2013-05-20 12:47:59 -04:00
parent b794830a25
commit 1097d51b33
18 changed files with 91 additions and 66 deletions

View file

@ -1,9 +1,9 @@
<div class='admin-controls'> <div class='admin-controls'>
<div class='span5 controls'> <div class='span5 controls'>
{{view Discourse.TextField valueBinding="controller.testEmailAddress" placeholderKey="admin.email_logs.test_email_address"}} {{textField value=testEmailAddress placeholderKey="admin.email_logs.test_email_address"}}
</div> </div>
<div class='span10 controls'> <div class='span10 controls'>
<button class='btn' {{action sendTestEmail target="controller"}} {{bindAttr disabled="sendTestEmailDisabled"}}>{{i18n admin.email_logs.send_test}}</button> <button class='btn' {{action sendTestEmail}} {{bindAttr disabled="sendTestEmailDisabled"}}>{{i18n admin.email_logs.send_test}}</button>
{{#if controller.sentTestEmail}}<span class='result-message'>{{i18n admin.email_logs.sent_test}}</span>{{/if}} {{#if controller.sentTestEmail}}<span class='result-message'>{{i18n admin.email_logs.sent_test}}</span>{{/if}}
</div> </div>
</div> </div>
@ -16,9 +16,9 @@
<th>{{i18n admin.email_logs.email_type}}</th> <th>{{i18n admin.email_logs.email_type}}</th>
</tr> </tr>
{{#if controller.content.length}} {{#if model.length}}
{{#group}} {{#group}}
{{#collection contentBinding="controller.content" tagName="tbody" itemTagName="tr"}} {{#collection contentBinding="model" tagName="tbody" itemTagName="tr"}}
<td>{{date view.content.created_at}}</td> <td>{{date view.content.created_at}}</td>
<td> <td>
{{#if view.content.user}} {{#if view.content.user}}

View file

@ -22,7 +22,7 @@
{{#if automatic}} {{#if automatic}}
<h3>{{name}}</h3> <h3>{{name}}</h3>
{{else}} {{else}}
{{view Discourse.TextField valueBinding="name" placeholderKey="admin.groups.name_placeholder"}} {{textField value=name placeholderKey="admin.groups.name_placeholder"}}
{{/if}} {{/if}}
{{view Discourse.UserSelector id="group-users" placeholderKey="admin.groups.selector_placeholder" tabindex="1" usernamesBinding="usernames"}} {{view Discourse.UserSelector id="group-users" placeholderKey="admin.groups.selector_placeholder" tabindex="1" usernamesBinding="usernames"}}

View file

@ -1,12 +1,12 @@
<div class='admin-controls'> <div class='admin-controls'>
<div class='search controls'> <div class='search controls'>
<label> <label>
{{view Ember.Checkbox checkedBinding="controller.onlyOverridden"}} {{input type="checkbox" checked=onlyOverridden}}
{{i18n admin.site_settings.show_overriden}} {{i18n admin.site_settings.show_overriden}}
</label> </label>
</div> </div>
<div class='search controls'> <div class='search controls'>
{{view Discourse.TextField valueBinding="controller.filter" placeholderKey="type_to_filter"}} {{textField value=filter placeHolderKey="type_to_filter"}}
</div> </div>
</div> </div>

View file

@ -9,13 +9,13 @@
</ul> </ul>
</div> </div>
<div class='span5 username controls'> <div class='span5 username controls'>
{{view Discourse.TextField valueBinding="controller.username" placeholderKey="username"}} {{textField value=username placeholderKey="username"}}
</div> </div>
</div> </div>
{{#if hasSelection}} {{#if hasSelection}}
<div id='selected-controls'> <div id='selected-controls'>
<button {{action approveUsers target="controller"}} class='btn'>{{countI18n admin.users.approved_selected countBinding="selectedCount"}}</button> <button {{action approveUsers}} class='btn'>{{countI18n admin.users.approved_selected countBinding="selectedCount"}}</button>
</div> </div>
{{/if}} {{/if}}
@ -49,7 +49,7 @@
{{#each content}} {{#each content}}
<tr {{bindAttr class="selected"}}> <tr {{bindAttr class="selected"}}>
{{#if controller.showApproval}} {{#if showApproval}}
<td> <td>
{{#if can_approve}} {{#if can_approve}}
{{view Ember.Checkbox checkedBinding="selected"}} {{view Ember.Checkbox checkedBinding="selected"}}
@ -67,7 +67,7 @@
<td>{{{unbound created_at_age}}}</td> <td>{{{unbound created_at_age}}}</td>
{{#if controller.showApproval}} {{#if showApproval}}
<td> <td>
{{#if approved}} {{#if approved}}
{{i18n yes_value}} {{i18n yes_value}}

View file

@ -9,7 +9,7 @@
Discourse.UserPrivateMessagesController = Discourse.ObjectController.extend({ Discourse.UserPrivateMessagesController = Discourse.ObjectController.extend({
editPreferences: function() { 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() { composePrivateMessage: function() {

View file

@ -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 Breaks up a long string
@ -66,16 +78,27 @@ Ember.Handlebars.registerHelper('textField', function(options) {
var hash = options.hash, var hash = options.hash,
types = options.hashTypes; types = options.hashTypes;
for (var prop in hash) { normalizeHash(hash, types);
if (types[prop] === 'ID') {
hash[prop + 'Binding'] = hash[prop];
delete hash[prop];
}
}
return Ember.Handlebars.helpers.view.call(this, Discourse.TextField, options); 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 Produces a bound link to a category

View file

@ -35,17 +35,19 @@ Ember.String.i18n = function(scope, options) {
@for Handlebars @for Handlebars
**/ **/
Ember.Handlebars.registerHelper('countI18n', function(key, options) { Ember.Handlebars.registerHelper('countI18n', function(key, options) {
var view; var view = Discourse.View.extend({
view = Discourse.View.extend({
tagName: 'span', tagName: 'span',
render: function(buffer) { render: function(buffer) {
return buffer.push(Ember.String.i18n(key, { buffer.push(Ember.String.i18n(key, {
count: this.get('count') count: this.get('count')
})); }));
}, },
countChanged: (function() {
return this.rerender(); countChanged: function() {
}).observes('count') this.rerender();
}.observes('count')
}); });
return Ember.Handlebars.helpers.view.call(this, view, options); return Ember.Handlebars.helpers.view.call(this, view, options);
}); });

View file

@ -1,6 +1,6 @@
<div class="auto-close-fields"> <div class="auto-close-fields">
<i class="icon icon-time"></i> <i class="icon icon-time"></i>
{{view.label}} {{view.label}}
{{view Discourse.TextField valueBinding="view.autoCloseDays" maxlength="3"}} {{textField value=view.autoCloseDays maxlength="3"}}
{{i18n composer.auto_close_units}} {{i18n composer.auto_close_units}}
</div> </div>

View file

@ -32,7 +32,7 @@
{{#if content.creatingPrivateMessage}} {{#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"}} {{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}} {{/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}} {{#unless content.creatingPrivateMessage}}
{{view Discourse.ComboboxViewCategory valueAttribute="name" contentBinding="Discourse.site.categories" valueBinding="content.categoryName"}} {{view Discourse.ComboboxViewCategory valueAttribute="name" contentBinding="Discourse.site.categories" valueBinding="content.categoryName"}}
{{#if content.archetype.hasOptions}} {{#if content.archetype.hasOptions}}

View file

@ -6,8 +6,8 @@
<tr> <tr>
<td style="width:80px"><label for='new-account-name'>{{i18n user.name.title}}</label></td> <td style="width:80px"><label for='new-account-name'>{{i18n user.name.title}}</label></td>
<td style="width:496px"> <td style="width:496px">
{{view Discourse.TextField valueBinding="view.accountName" elementId="new-account-name" autofocus="autofocus"}} {{textField value=view.accountName id="new-account-name" autofocus="autofocus"}}
&nbsp;{{view Discourse.InputTipView validationBinding="view.nameValidation"}} &nbsp;{{inputTip validation=nameValidation}}
</td> </td>
</tr> </tr>
<tr> <tr>
@ -18,8 +18,8 @@
<tr> <tr>
<td><label for='new-account-email'>{{i18n user.email.title}}</label></td> <td><label for='new-account-email'>{{i18n user.email.title}}</label></td>
<td> <td>
{{view Ember.TextField valueBinding="view.accountEmail" id="new-account-email"}} {{input value=view.accountEmail id="new-account-email"}}
&nbsp;{{view Discourse.InputTipView validationBinding="view.emailValidation"}} &nbsp;{{inputTip validation=view.emailValidation}}
</td> </td>
</tr> </tr>
<tr> <tr>
@ -30,8 +30,8 @@
<tr> <tr>
<td><label for='new-account-username'>{{i18n user.username.title}}</label></td> <td><label for='new-account-username'>{{i18n user.username.title}}</label></td>
<td> <td>
{{view Ember.TextField valueBinding="view.accountUsername" id="new-account-username" maxlength="15"}} {{input value=view.accountUsername id="new-account-username" maxlength="15"}}
&nbsp;{{view Discourse.InputTipView validationBinding="view.usernameValidation"}} &nbsp;{{inputTip validation=view.usernameValidation}}
</td> </td>
</tr> </tr>
<tr> <tr>
@ -43,8 +43,8 @@
<tr> <tr>
<td><label for='new-account-password'>{{i18n user.password.title}}</label></td> <td><label for='new-account-password'>{{i18n user.password.title}}</label></td>
<td> <td>
{{view Ember.TextField valueBinding="view.accountPassword" type="password" id="new-account-password"}} {{input type="password" value=view.accountPassword id="new-account-password"}}
&nbsp;{{view Discourse.InputTipView validationBinding="view.passwordValidation"}} &nbsp;{{inputTip validation=view.passwordValidation}}
</td> </td>
</tr> </tr>
{{/if}} {{/if}}
@ -52,8 +52,8 @@
<tr class="password-confirmation"> <tr class="password-confirmation">
<td><label for='new-account-password-confirmation'>{{i18n user.password_confirmation.title}}</label></td> <td><label for='new-account-password-confirmation'>{{i18n user.password_confirmation.title}}</label></td>
<td> <td>
{{view Ember.TextField valueBinding="view.accountPasswordConfirm" type="password" id="new-account-password-confirmation"}} {{input type="password" value=view.accountPasswordConfirm id="new-account-confirmation"}}
{{view Ember.TextField valueBinding="view.accountChallenge" id="new-account-challenge"}} {{input value=view.accountChallenge id="new-account-challenge"}}
</td> </td>
</tr> </tr>

View file

@ -20,7 +20,7 @@
<form> <form>
<section class='field'> <section class='field'>
<label>{{i18n category.name}}</label> <label>{{i18n category.name}}</label>
{{view Discourse.TextField valueBinding="name" placeholderKey="category.name_placeholder" maxlength="50"}} {{textField value=name placeholderKey="category.name_placeholder" maxlength="50"}}
</section> </section>
{{#unless is_uncategorized}} {{#unless is_uncategorized}}
@ -46,13 +46,13 @@
<div class='input-prepend input-append' style="margin-top: 10px;"> <div class='input-prepend input-append' style="margin-top: 10px;">
<span class='color-title'>{{i18n category.background_color}}:</span> <span class='color-title'>{{i18n category.background_color}}:</span>
<span class='add-on'>#</span>{{view Discourse.TextField valueBinding="color" placeholderKey="category.color_placeholder" maxlength="6"}} <span class='add-on'>#</span>{{textField value=color placeholderKey="category.color_placeholder" maxlength="6"}}
{{view Discourse.ColorsView colorsBinding="view.backgroundColors" usedColorsBinding="view.usedBackgroundColors" valueBinding="color"}} {{view Discourse.ColorsView colorsBinding="view.backgroundColors" usedColorsBinding="view.usedBackgroundColors" valueBinding="color"}}
</div> </div>
<div class='input-prepend input-append'> <div class='input-prepend input-append'>
<span class='color-title'>{{i18n category.foreground_color}}:</span> <span class='color-title'>{{i18n category.foreground_color}}:</span>
<span class='add-on'>#</span>{{view Discourse.TextField valueBinding="text_color" placeholderKey="category.color_placeholder" maxlength="6"}} <span class='add-on'>#</span>{{textField value=text_color placeholderKey="category.color_placeholder" maxlength="6"}}
{{view Discourse.ColorsView colorsBinding="view.foregroundColors" valueBinding="text_color"}} {{view Discourse.ColorsView colorsBinding="view.foregroundColors" valueBinding="text_color"}}
</div> </div>
</div> </div>
@ -63,7 +63,7 @@
<div {{bindAttr class=":modal-tab :options-tab view.securitySelected::invisible"}}> <div {{bindAttr class=":modal-tab :options-tab view.securitySelected::invisible"}}>
<section class='field'> <section class='field'>
<label> <label>
{{view Ember.Checkbox checkedBinding="secure"}} {{input type="checkbox" checked=secure}}
{{i18n category.is_secure}} {{i18n category.is_secure}}
</label> </label>
{{#if secure}} {{#if secure}}

View file

@ -1,8 +1,8 @@
<div class="modal-body"> <div class="modal-body">
<form> <form>
<label for='username-or-email'>{{i18n forgot_password.invite}}</label> <label for='username-or-email'>{{i18n forgot_password.invite}}</label>
{{view Discourse.TextField valueBinding="view.accountEmailOrUsername" placeholderKey="login.email_placeholder" elementId="username-or-email" autocorrect="off" autocapitalize="off"}} {{textField value=view.accountEmailOrUsername placeholderKey="login.email_placeholder" elementId="username-or-email" autocorrect="off" autocapitalize="off"}}
</form> </form>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button class='btn btn-large btn-primary' {{bindAttr disabled="view.submitDisabled"}} {{action submit target="view"}}>{{i18n forgot_password.reset}}</button> <button class='btn btn-large btn-primary' {{bindAttr disabled="view.submitDisabled"}} {{action submit target="view"}}>{{i18n forgot_password.reset}}</button>

View file

@ -1,4 +1,4 @@
<div class="modal-body"> <div class="modal-body">
{{#if view.error}} {{#if view.error}}
<div class="alert alert-error"> <div class="alert alert-error">
<button class="close" data-dismiss="alert">×</button> <button class="close" data-dismiss="alert">×</button>
@ -11,7 +11,7 @@
{{else}} {{else}}
<form> <form>
<label>{{i18n topic.invite_reply.email}}</label> <label>{{i18n topic.invite_reply.email}}</label>
{{view Discourse.TextField valueBinding="view.email" placeholderKey="topic.invite_reply.email_placeholder"}} {{textField value=view.email placeholderKey="topic.invite_reply.email_placeholder"}}
</form> </form>
{{/if}} {{/if}}
</div> </div>
@ -21,5 +21,5 @@
{{else}} {{else}}
<button class='btn btn-primary' {{bindAttr disabled="view.disabled"}} {{action createInvite target="view"}}>{{view.buttonTitle}}</button> <button class='btn btn-primary' {{bindAttr disabled="view.disabled"}} {{action createInvite target="view"}}>{{view.buttonTitle}}</button>
{{/if}} {{/if}}
</div> </div>

View file

@ -1,4 +1,4 @@
<div class="modal-body"> <div class="modal-body">
{{#if view.error}} {{#if view.error}}
<div class="alert alert-error"> <div class="alert alert-error">
<button class="close" data-dismiss="alert">×</button> <button class="close" data-dismiss="alert">×</button>
@ -11,7 +11,7 @@
{{else}} {{else}}
<form> <form>
<label>{{i18n topic.invite_private.email_or_username}}</label> <label>{{i18n topic.invite_private.email_or_username}}</label>
{{view Discourse.TextField valueBinding="view.emailOrUsername" placeholderKey="topic.invite_private.email_or_username_placeholder"}} {{textField value=view.emailOrUsername placeholderKey="topic.invite_private.email_or_username_placeholder"}}
</form> </form>
{{/if}} {{/if}}
</div> </div>
@ -21,5 +21,5 @@
{{else}} {{else}}
<button class='btn btn-primary' {{bindAttr disabled="view.disabled"}} {{action invite target="view"}}>{{view.buttonTitle}}</button> <button class='btn btn-primary' {{bindAttr disabled="view.disabled"}} {{action invite target="view"}}>{{view.buttonTitle}}</button>
{{/if}} {{/if}}
</div> </div>

View file

@ -30,7 +30,7 @@
<label for='login-account-name'>{{i18n login.username}}&nbsp;</label> <label for='login-account-name'>{{i18n login.username}}&nbsp;</label>
</td> </td>
<td> <td>
{{view Discourse.TextField valueBinding="view.loginName" placeholderKey="login.email_placeholder" elementId="login-account-name" autocorrect="off" autocapitalize="off" autofocus="autofocus"}} {{textField value=view.loginName placeholderKey="login.email_placeholder" elementId="login-account-name" autocorrect="off" autocapitalize="off" autofocus="autofocus"}}
</td> </td>
<tr> <tr>
<td> <td>

View file

@ -9,7 +9,7 @@
<form> <form>
<label>{{i18n topic.split_topic.topic_name}}</label> <label>{{i18n topic.split_topic.topic_name}}</label>
{{view Discourse.TextField valueBinding="view.topicName" placeholderKey="composer.title_placeholder"}} {{textField value=view.topicName placeholderKey="composer.title_placeholder"}}
</form> </form>
</div> </div>

View file

@ -11,19 +11,19 @@ Discourse.ButtonView = Discourse.View.extend({
classNameBindings: [':btn', ':standard', 'dropDownToggle'], classNameBindings: [':btn', ':standard', 'dropDownToggle'],
attributeBindings: ['data-not-implemented', 'title', 'data-toggle', 'data-share-url'], attributeBindings: ['data-not-implemented', 'title', 'data-toggle', 'data-share-url'],
title: (function() { title: function() {
return Em.String.i18n(this.get('helpKey') || this.get('textKey')); 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')); return Em.String.i18n(this.get('textKey'));
}).property('textKey'), }.property('textKey'),
render: function(buffer) { render: function(buffer) {
if (this.renderIcon) { if (this.renderIcon) {
this.renderIcon(buffer); this.renderIcon(buffer);
} }
return buffer.push(this.get('text')); buffer.push(this.get('text'));
} }
}); });

View file

@ -10,22 +10,22 @@ Discourse.InputTipView = Discourse.View.extend({
templateName: 'input_tip', templateName: 'input_tip',
classNameBindings: [':tip', 'good', 'bad'], classNameBindings: [':tip', 'good', 'bad'],
good: (function() { good: function() {
return !this.get('validation.failed'); return !this.get('validation.failed');
}).property('validation'), }.property('validation'),
bad: (function() { bad: function() {
return this.get('validation.failed'); return this.get('validation.failed');
}).property('validation'), }.property('validation'),
triggerRender: (function() { triggerRender: function() {
return this.rerender(); return this.rerender();
}).observes('validation'), }.observes('validation'),
render: function(buffer) { render: function(buffer) {
var icon, reason; var reason = this.get('validation.reason');
if (reason = this.get('validation.reason')) { if (reason) {
icon = this.get('good') ? 'icon-ok' : 'icon-remove'; var icon = this.get('good') ? 'icon-ok' : 'icon-remove';
return buffer.push("<i class=\"icon " + icon + "\"></i> " + reason); return buffer.push("<i class=\"icon " + icon + "\"></i> " + reason);
} }
} }