Refactor: Convert repeated {{view Discourse.xyz}} to registered view helpers

This commit is contained in:
Robin Ward 2013-05-29 15:14:31 -04:00
parent 57d5355ce8
commit 5ae7707000
20 changed files with 55 additions and 43 deletions

View File

@ -58,4 +58,4 @@ Discourse.AceEditorView = Discourse.View.extend({
});
Discourse.Utilities.registerViewHelper('aceEditor', Discourse.AceEditorView);
Discourse.View.registerHelper('aceEditor', Discourse.AceEditorView);

View File

@ -29,19 +29,6 @@ Discourse.Utilities = {
}
},
/*
Register a view class as a helper
*/
registerViewHelper: function(helperName, helperClass) {
Ember.Handlebars.registerHelper(helperName, function(options) {
var hash = options.hash,
types = options.hashTypes;
Discourse.Utilities.normalizeHash(hash, types);
return Ember.Handlebars.helpers.view.call(this, helperClass, options);
});
},
// Create a badge like category link
categoryLink: function(category) {
if (!category) return "";

View File

@ -42,7 +42,7 @@
</li>
{{#if view.topic.fewParticipants}}
<li class='avatars'>
{{#each view.topic.fewParticipants}}{{view Discourse.ParticipantView participantBinding="this"}}{{/each}}
{{#each view.topic.fewParticipants}}{{participant participant=this}}{{/each}}
</li>
{{/if}}
</ul>
@ -74,7 +74,7 @@
{{#if view.topic.participants}}
<section class='avatars clearfix'>
{{#each view.topic.participants}}{{view Discourse.ParticipantView participantBinding="this"}}{{/each}}
{{#each view.topic.participants}}{{participant participant=this}}{{/each}}
</section>
{{/if}}

View File

@ -15,9 +15,9 @@
<div class='clearfix'></div>
<ul class='action-list nav-stacked side-nav'>
{{view Discourse.ActivityFilterView countBinding="statsCountNonPM"}}
{{activityFilter count=statsCountNonPM}}
{{#each statsExcludingPms}}
{{view Discourse.ActivityFilterView contentBinding="this"}}
{{activityFilter content=this}}
{{/each}}
</ul>
<div class='show'>
@ -51,4 +51,4 @@
</div>
{{/with}}
{{view Discourse.UserStreamView streamBinding="model"}}
{{userStream stream=model}}

View File

@ -71,7 +71,7 @@
{{#if email_digests}}
<div class='control-indent'>
{{view Discourse.ComboboxView valueAttribute="value" contentBinding="digestFrequencies" valueBinding="digest_after_days"}}
{{combobox valueAttribute="value" content=digestFrequencies value="digest_after_days"}}
</div>
{{/if}}
<label>{{view Ember.Checkbox checkedBinding="email_private_messages"}}
@ -88,12 +88,12 @@
<label class="control-label">{{i18n user.other_settings}}</label>
<div class="controls">
<label>{{i18n user.auto_track_topics}}</label>
{{view Discourse.ComboboxView valueAttribute="value" contentBinding="autoTrackDurations" valueBinding="auto_track_topics_after_msecs"}}
{{combobox valueAttribute="value" content=autoTrackDurations value="auto_track_topics_after_msecs"}}
</div>
<div class="controls">
<label>{{i18n user.new_topic_duration.label}}</label>
{{view Discourse.ComboboxView valueAttribute="value" contentBinding="considerNewTopicOptions" valueBinding="new_topic_duration_minutes"}}
{{combobox valueAttribute="value" content=considerNewTopicOptions value="new_topic_duration_minutes"}}
</div>
<div class="controls">

View File

@ -16,9 +16,10 @@
<ul class='action-list nav-stacked side-nav'>
{{#each statsPmsOnly}}
{{view Discourse.ActivityFilterView contentBinding="this"}}
{{activityFilter content=this}}
{{/each}}
</ul>
{{/with}}
</div>
{{view Discourse.UserStreamView streamBinding="model"}}
{{userStream stream=model}}

View File

@ -20,4 +20,4 @@ Discourse.AutoCloseFormView = Ember.View.extend({
}.observes('autoCloseDays')
});
Discourse.Utilities.registerViewHelper('autoCloseForm', Discourse.AutoCloseFormView);
Discourse.View.registerHelper('autoCloseForm', Discourse.AutoCloseFormView);

View File

@ -34,4 +34,4 @@ Discourse.CategoryChooserView = Discourse.ComboboxView.extend({
});
Discourse.Utilities.registerViewHelper('categoryChooser', Discourse.CategoryChooserView);
Discourse.View.registerHelper('categoryChooser', Discourse.CategoryChooserView);

View File

@ -75,4 +75,4 @@ Discourse.ComboboxView = Discourse.View.extend({
});
Discourse.View.registerHelper('combobox', Discourse.ComboboxView);

View File

@ -19,4 +19,4 @@ Discourse.TextField = Ember.TextField.extend({
});
Discourse.Utilities.registerViewHelper('textField', Discourse.TextField);
Discourse.View.registerHelper('textField', Discourse.TextField);

View File

@ -30,4 +30,4 @@ Discourse.InputTipView = Discourse.View.extend({
}
});
Discourse.Utilities.registerViewHelper('inputTip', Discourse.InputTipView);
Discourse.View.registerHelper('inputTip', Discourse.InputTipView);

View File

@ -36,4 +36,4 @@ Discourse.ColorPickerView = Ember.ContainerView.extend({
}
});
Discourse.Utilities.registerViewHelper('colorPicker', Discourse.ColorPickerView);
Discourse.View.registerHelper('colorPicker', Discourse.ColorPickerView);

View File

@ -44,4 +44,4 @@ Discourse.PagedownEditor = Ember.ContainerView.extend({
});
Discourse.Utilities.registerViewHelper('pagedown', Discourse.PagedownEditor);
Discourse.View.registerHelper('pagedown', Discourse.PagedownEditor);

View File

@ -16,3 +16,4 @@ Discourse.ParticipantView = Discourse.View.extend({
});
Discourse.View.registerHelper('participant', Discourse.ParticipantView);

View File

@ -56,4 +56,4 @@ Discourse.PopupInputTipView = Discourse.View.extend({
}
});
Discourse.Utilities.registerViewHelper('popupInputTip', Discourse.PopupInputTipView);
Discourse.View.registerHelper('popupInputTip', Discourse.PopupInputTipView);

View File

@ -48,4 +48,4 @@ Discourse.TopicStatusView = Discourse.View.extend({
});
Discourse.Utilities.registerViewHelper('topicStatus', Discourse.TopicStatusView);
Discourse.View.registerHelper('topicStatus', Discourse.TopicStatusView);

View File

@ -47,4 +47,4 @@ Discourse.ActivityFilterView = Discourse.View.extend({
}
});
Discourse.View.registerHelper('activityFilter', Discourse.ActivityFilterView);

View File

@ -50,3 +50,4 @@ Discourse.UserStreamView = Discourse.View.extend(Discourse.Scrolling, {
});
Discourse.View.registerHelper('userStream', Discourse.UserStreamView);

View File

@ -64,4 +64,4 @@ Discourse.UserSelector.reopenClass({
}
});
Discourse.Utilities.registerViewHelper('userSelector', Discourse.UserSelector);
Discourse.View.registerHelper('userSelector', Discourse.UserSelector);

View File

@ -1,4 +1,4 @@
/**
/**
A base view that gives us common functionality, for example `present` and `blank`
@class View
@ -6,5 +6,27 @@
@uses Discourse.Presence
@namespace Discourse
@module Discourse
**/
Discourse.View = Ember.View.extend(Discourse.Presence, {});
Discourse.View.reopenClass({
/**
Register a view helper for ease of use
@method registerHElper
@param {String} helperName the name of the helper
@param {Ember.View} helperClass the view that will be inserted by the helper
**/
Discourse.View = Ember.View.extend(Discourse.Presence, {});
registerHelper: function(helperName, helperClass) {
Ember.Handlebars.registerHelper(helperName, function(options) {
var hash = options.hash,
types = options.hashTypes;
Discourse.Utilities.normalizeHash(hash, types);
return Ember.Handlebars.helpers.view.call(this, helperClass, options);
});
}
})