Refactor: Removed the last of the references to Discourse.currentUser.

This commit is contained in:
Robin Ward
2013-05-28 11:52:31 -04:00
parent 57f97880e6
commit dd54736d06
23 changed files with 96 additions and 63 deletions

View File

@ -0,0 +1,9 @@
/**
A base admin controller that has access to the Discourse properties.
@class AdminController
@extends Discourse.Controller
@namespace Discourse
@module Discourse
**/
Discourse.AdminCustomizeController = Discourse.Controller.extend({});

View File

@ -0,0 +1,9 @@
/**
A controller related to viewing a user in the admin section
@class AdminUserController
@extends Discourse.ObjectController
@namespace Discourse
@module Discourse
**/
Discourse.AdminUserController = Discourse.ObjectController.extend({});

View File

@ -4,7 +4,7 @@
<ul class="nav nav-pills"> <ul class="nav nav-pills">
<li>{{#linkTo 'admin.dashboard'}}{{i18n admin.dashboard.title}}{{/linkTo}}</li> <li>{{#linkTo 'admin.dashboard'}}{{i18n admin.dashboard.title}}{{/linkTo}}</li>
{{#if Discourse.currentUser.admin}} {{#if currentUser.admin}}
<li>{{#linkTo 'admin.site_settings'}}{{i18n admin.site_settings.title}}{{/linkTo}}</li> <li>{{#linkTo 'admin.site_settings'}}{{i18n admin.site_settings.title}}{{/linkTo}}</li>
<li>{{#linkTo 'adminSiteContents'}}{{i18n admin.site_content.title}}{{/linkTo}}</li> <li>{{#linkTo 'adminSiteContents'}}{{i18n admin.site_content.title}}{{/linkTo}}</li>
{{/if}} {{/if}}
@ -12,7 +12,7 @@
<li>{{#linkTo 'admin.groups'}}{{i18n admin.groups.title}}{{/linkTo}}</li> <li>{{#linkTo 'admin.groups'}}{{i18n admin.groups.title}}{{/linkTo}}</li>
<li>{{#linkTo 'admin.email_logs'}}{{i18n admin.email_logs.title}}{{/linkTo}}</li> <li>{{#linkTo 'admin.email_logs'}}{{i18n admin.email_logs.title}}{{/linkTo}}</li>
<li>{{#linkTo 'adminFlags.active'}}{{i18n admin.flags.title}}{{/linkTo}}</li> <li>{{#linkTo 'adminFlags.active'}}{{i18n admin.flags.title}}{{/linkTo}}</li>
{{#if Discourse.currentUser.admin}} {{#if currentUser.admin}}
<li>{{#linkTo 'admin.customize'}}{{i18n admin.customize.title}}{{/linkTo}}</li> <li>{{#linkTo 'admin.customize'}}{{i18n admin.customize.title}}{{/linkTo}}</li>
<li>{{#linkTo 'admin.api'}}{{i18n admin.api.title}}{{/linkTo}}</li> <li>{{#linkTo 'admin.api'}}{{i18n admin.api.title}}{{/linkTo}}</li>
{{/if}} {{/if}}

View File

@ -31,7 +31,7 @@
<div class='field'>{{i18n user.ip_address.title}}</div> <div class='field'>{{i18n user.ip_address.title}}</div>
<div class='value'>{{ip_address}}</div> <div class='value'>{{ip_address}}</div>
<div class='controls'> <div class='controls'>
{{#if Discourse.currentUser.admin}} {{#if currentUser.admin}}
<button class='btn' {{action refreshBrowsers target="content"}}> <button class='btn' {{action refreshBrowsers target="content"}}>
{{i18n admin.user.refresh_browsers}} {{i18n admin.user.refresh_browsers}}
</button> </button>

View File

@ -93,10 +93,12 @@ Discourse.ComposerController = Discourse.Controller.extend({
}).then(function(opts) { }).then(function(opts) {
opts = opts || {}; opts = opts || {};
_this.close(); _this.close();
var currentUser = Discourse.User.current();
if (composer.get('creatingTopic')) { if (composer.get('creatingTopic')) {
Discourse.set('currentUser.topic_count', Discourse.User.current('topic_count') + 1); currentUser.set('topic_count', currentUser.get('topic_count') + 1);
} else { } else {
Discourse.set('currentUser.reply_count', Discourse.User.current('reply_count') + 1); currentUser.set('reply_count', currentUser.get('reply_count') + 1);
} }
Discourse.URL.routeTo(opts.post.get('url')); Discourse.URL.routeTo(opts.post.get('url'));
}, function(error) { }, function(error) {
@ -151,7 +153,8 @@ Discourse.ComposerController = Discourse.Controller.extend({
Discourse.ajax("/education/" + educationKey, {dataType: 'html'}).then(function(result) { Discourse.ajax("/education/" + educationKey, {dataType: 'html'}).then(function(result) {
composerController.set('educationContents', result); composerController.set('educationContents', result);
}); });
}.observes('typedReply', 'content.creatingTopic', 'Discourse.currentUser.reply_count'),
}.observes('typedReply', 'content.creatingTopic', 'currentUser.reply_count'),
checkReplyLength: function() { checkReplyLength: function() {
this.set('typedReply', this.present('content.reply')); this.set('typedReply', this.present('content.reply'));

View File

@ -7,6 +7,4 @@
@uses Discourse.Presence @uses Discourse.Presence
@module Discourse @module Discourse
**/ **/
Discourse.Controller = Ember.Controller.extend(Discourse.Presence); Discourse.Controller = Ember.Controller.extend(Discourse.Presence, Discourse.HasCurrentUser);

View File

@ -7,7 +7,6 @@
@module Discourse @module Discourse
**/ **/
Discourse.ListController = Discourse.Controller.extend({ Discourse.ListController = Discourse.Controller.extend({
currentUserBinding: 'Discourse.currentUser',
categoryBinding: 'topicList.category', categoryBinding: 'topicList.category',
canCreateCategory: false, canCreateCategory: false,
canCreateTopic: false, canCreateTopic: false,

View File

@ -7,6 +7,6 @@
@uses Discourse.Presence @uses Discourse.Presence
@module Discourse @module Discourse
**/ **/
Discourse.ObjectController = Ember.ObjectController.extend(Discourse.Presence); Discourse.ObjectController = Ember.ObjectController.extend(Discourse.Presence, Discourse.HasCurrentUser);

View File

@ -334,7 +334,7 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
}, },
/** /**
Clears the pin from a topic for the currentUser Clears the pin from a topic for the currently logged in user
@method clearPin @method clearPin
**/ **/

View File

@ -0,0 +1,31 @@
/**
This mixin provides a `currentUser` property that can be used to retrieve information
about the currently logged in user. It is mostly useful to controllers so it can be
exposted to templates.
Outside of templates, code should probably use `Discourse.User.current()` instead of
this property.
@class Discourse.HasCurrentUser
@extends Ember.Mixin
@namespace Discourse
@module HasCurrentUser
**/
Discourse.HasCurrentUser = Em.Mixin.create({
/**
Returns a reference to the currently logged in user.
@method currentUser
@return {Discourse.User} the currently logged in user if present.
*/
currentUser: function() {
return Discourse.User.current();
}.property().volatile()
});

View File

@ -338,7 +338,7 @@ Discourse.Topic = Discourse.Model.extend({
}, },
/** /**
Clears the pin from a topic for the currentUser Clears the pin from a topic for the currently logged in user
@method clearPin @method clearPin
**/ **/

View File

@ -160,8 +160,8 @@ Discourse.User = Discourse.Model.extend({
type: 'PUT' type: 'PUT'
}).then(function(data) { }).then(function(data) {
user.set('bio_excerpt',data.user.bio_excerpt); user.set('bio_excerpt',data.user.bio_excerpt);
Discourse.set('currentUser.enable_quoting', user.get('enable_quoting')); Discourse.User.current().set('enable_quoting', user.get('enable_quoting'));
Discourse.set('currentUser.external_links_in_new_tab', user.get('external_links_in_new_tab')); Discourse.User.current().set('external_links_in_new_tab', user.get('external_links_in_new_tab'));
}); });
}, },

View File

@ -1,13 +0,0 @@
/**
The base Application route
@class ApplicationRoute
@extends Discourse.Route
@namespace Discourse
@module Discourse
**/
Discourse.ApplicationRoute = Discourse.Route.extend({
setupController: function(controller) {
Discourse.set('currentUser', Discourse.User.current());
}
});

View File

@ -66,7 +66,7 @@
<div class='preview-wrapper'> <div class='preview-wrapper'>
<div id='wmd-preview' {{bindAttr class="hidePreview:hidden"}}></div> <div id='wmd-preview' {{bindAttr class="hidePreview:hidden"}}></div>
</div> </div>
{{#if Discourse.currentUser}} {{#if currentUser}}
<a href="#" {{action togglePreview}} class='toggle-preview'>{{{content.toggleText}}}</a> <a href="#" {{action togglePreview}} class='toggle-preview'>{{{content.toggleText}}}</a>
<div id='draft-status'></div> <div id='draft-status'></div>
{{#if view.loadingImage}} {{#if view.loadingImage}}
@ -77,7 +77,7 @@
{{/if}} {{/if}}
</div> </div>
{{#if Discourse.currentUser}} {{#if currentUser}}
<div class='submit-panel'> <div class='submit-panel'>
<button {{action save}} tabindex="4" {{bindAttr class=":btn :btn-primary :create content.cantSubmitPost:disabled"}}>{{view.content.saveText}}</button> <button {{action save}} tabindex="4" {{bindAttr class=":btn :btn-primary :create content.cantSubmitPost:disabled"}}>{{view.content.saveText}}</button>
<a href='#' {{action cancel}} class='cancel' tabindex="4">{{i18n cancel}}</a> <a href='#' {{action cancel}} class='cancel' tabindex="4">{{i18n cancel}}</a>

View File

@ -7,8 +7,8 @@
<div class='panel clearfix'> <div class='panel clearfix'>
{{#unless showExtraInfo}} {{#unless showExtraInfo}}
<div class='current-username'> <div class='current-username'>
{{#if view.currentUser}} {{#if currentUser}}
<span class='username'><a {{bindAttr href="view.currentUser.path"}}>{{view.currentUser.name}}</a></span> <span class='username'><a {{bindAttr href="currentUser.path"}}>{{currentUser.name}}</a></span>
{{else}} {{else}}
<button {{action showLogin}} class='btn btn-primary btn-small'>{{i18n log_in}}</button> <button {{action showLogin}} class='btn btn-primary btn-small'>{{i18n log_in}}</button>
{{/if}} {{/if}}
@ -16,13 +16,13 @@
{{/unless}} {{/unless}}
<ul class='icons clearfix'> <ul class='icons clearfix'>
<li class='notifications'> <li class='notifications'>
{{#if view.currentUser}} {{#if currentUser}}
<a class='icon' href="#" {{action showNotifications target="view"}} data-notifications="notifications-dropdown" id='user-notifications' title='{{i18n notifications.title}}'><i class='icon-comment'></i></a> <a class='icon' href="#" {{action showNotifications target="view"}} data-notifications="notifications-dropdown" id='user-notifications' title='{{i18n notifications.title}}'><i class='icon-comment'></i></a>
{{#if view.currentUser.unread_notifications}} {{#if currentUser.unread_notifications}}
<a href='#' class='badge-notification unread-notifications'>{{view.currentUser.unread_notifications}}</a> <a href='#' class='badge-notification unread-notifications'>{{currentUser.unread_notifications}}</a>
{{/if}} {{/if}}
{{#if view.currentUser.unread_private_messages}} {{#if currentUser.unread_private_messages}}
<a href='#' class='badge-notification unread-private-messages'>{{view.currentUser.unread_private_messages}}</a> <a href='#' class='badge-notification unread-private-messages'>{{currentUser.unread_private_messages}}</a>
{{/if}} {{/if}}
{{else}} {{else}}
<a class='icon' href="#" {{action showLogin}} title='{{i18n notifications.title}}'><i class='icon-comment'></i></a> <a class='icon' href="#" {{action showLogin}} title='{{i18n notifications.title}}'><i class='icon-comment'></i></a>
@ -33,13 +33,13 @@
</li> </li>
<li class='categories dropdown'> <li class='categories dropdown'>
<a class='icon' data-dropdown="site-map-dropdown" href="#" title='{{i18n site_map}}'><i class='icon-reorder'></i></a> <a class='icon' data-dropdown="site-map-dropdown" href="#" title='{{i18n site_map}}'><i class='icon-reorder'></i></a>
{{#if view.currentUser.site_flagged_posts_count}} {{#if currentUser.site_flagged_posts_count}}
<a href='/admin/flags/active' title='{{i18n notifications.total_flagged}}' class='badge-notification flagged-posts'>{{view.currentUser.site_flagged_posts_count}}</a> <a href='/admin/flags/active' title='{{i18n notifications.total_flagged}}' class='badge-notification flagged-posts'>{{currentUser.site_flagged_posts_count}}</a>
{{/if}} {{/if}}
</li> </li>
<li class='current-user'> <li class='current-user'>
{{#if view.currentUser}} {{#if currentUser}}
{{#titledLinkTo user.activity view.currentUser titleKey="current_user" class="icon"}}{{avatar Discourse.currentUser imageSize="medium" }}{{/titledLinkTo}} {{#titledLinkTo user.activity currentUser titleKey="current_user" class="icon"}}{{avatar currentUser imageSize="medium" }}{{/titledLinkTo}}
{{else}} {{else}}
<div class="icon not-logged-in-avatar" {{action showLogin}}><i class='icon-user'></i></div> <div class="icon not-logged-in-avatar" {{action showLogin}}><i class='icon-user'></i></div>
{{/if}} {{/if}}
@ -55,7 +55,7 @@
<li class="{{unbound readClass}}">{{{unbound rendered}}}</li> <li class="{{unbound readClass}}">{{{unbound rendered}}}</li>
{{/each}} {{/each}}
<li class='read last'> <li class='read last'>
<a {{bindAttr href="view.currentUser.path"}}>{{i18n notifications.more}} &hellip;</a> <a {{bindAttr href="currentUser.path"}}>{{i18n notifications.more}} &hellip;</a>
</li> </li>
</ul> </ul>
{{else}} {{else}}
@ -65,11 +65,11 @@
<section class='d-dropdown' id='site-map-dropdown'> <section class='d-dropdown' id='site-map-dropdown'>
<ul> <ul>
{{#if Discourse.currentUser.staff}} {{#if currentUser.staff}}
<li><a href="/admin"><i class='icon icon-cog'></i>{{i18n admin_title}}</a></li> <li><a href="/admin"><i class='icon icon-cog'></i>{{i18n admin_title}}</a></li>
<li><a href="/admin/flags/active"><i class='icon icon-flag'></i>{{i18n flags_title}}</a> <li><a href="/admin/flags/active"><i class='icon icon-flag'></i>{{i18n flags_title}}</a>
{{#if view.currentUser.site_flagged_posts_count}} {{#if currentUser.site_flagged_posts_count}}
<a href='/admin/flags/active' title='{{i18n notifications.total_flagged}}' class='badge-notification flagged-posts'>{{view.currentUser.site_flagged_posts_count}}</a> <a href='/admin/flags/active' title='{{i18n notifications.total_flagged}}' class='badge-notification flagged-posts'>{{currentUser.site_flagged_posts_count}}</a>
{{/if}} {{/if}}
</li> </li>
{{/if}} {{/if}}

View File

@ -1,5 +1,4 @@
{{#if controller.currentUser.id}}
{{#if Discourse.currentUser.id}}
<td class='star'> <td class='star'>
<a {{bindAttr class=":star :icon-star starred:starred"}} {{action toggleStar this}} href='#' {{bindAttr title="favoriteTooltip"}}></a> <a {{bindAttr class=":star :icon-star starred:starred"}} {{action toggleStar this}} href='#' {{bindAttr title="favoriteTooltip"}}></a>
</td> </td>

View File

@ -13,7 +13,7 @@
<table id='topic-list'> <table id='topic-list'>
<thead> <thead>
<tr> <tr>
{{#if Discourse.currentUser}} {{#if currentUser}}
<th>&nbsp;</th> <th>&nbsp;</th>
{{/if}} {{/if}}
<th> <th>

View File

@ -138,6 +138,6 @@
{{render share}} {{render share}}
{{render quoteButton}} {{render quoteButton}}
{{#if Discourse.currentUser.staff}} {{#if currentUser.staff}}
{{render topicAdminMenu content}} {{render topicAdminMenu content}}
{{/if}} {{/if}}

View File

@ -7,7 +7,7 @@
{{#if viewingSelf}} {{#if viewingSelf}}
<button {{action "logout" target="Discourse"}} class='btn'>{{i18n user.log_out}}</button> <button {{action "logout" target="Discourse"}} class='btn'>{{i18n user.log_out}}</button>
{{/if}} {{/if}}
{{#if Discourse.currentUser.staff}} {{#if currentUser.staff}}
<a href="{{unbound adminPath}}" class='btn'><i class="icon-wrench"></i>&nbsp;{{i18n admin.user.show_admin_profile}}</a> <a href="{{unbound adminPath}}" class='btn'><i class="icon-wrench"></i>&nbsp;{{i18n admin.user.show_admin_profile}}</a>
{{/if}} {{/if}}
<ul class="nav nav-pills"> <ul class="nav nav-pills">

View File

@ -11,7 +11,6 @@ Discourse.HeaderView = Discourse.View.extend({
classNames: ['d-header', 'clearfix'], classNames: ['d-header', 'clearfix'],
classNameBindings: ['editingTopic'], classNameBindings: ['editingTopic'],
templateName: 'header', templateName: 'header',
currentUserBinding: 'Discourse.currentUser',
topicBinding: 'Discourse.router.topicController.content', topicBinding: 'Discourse.router.topicController.content',
showDropdown: function($target) { showDropdown: function($target) {
@ -58,7 +57,7 @@ Discourse.HeaderView = Discourse.View.extend({
})); }));
// We've seen all the notifications now // We've seen all the notifications now
headerView.set('currentUser.unread_notifications', 0); Discourse.User.current.set('unread_notifications', 0);
headerView.showDropdown($('#user-notifications')); headerView.showDropdown($('#user-notifications'));
}); });
return false; return false;

View File

@ -14,9 +14,9 @@ Discourse.TopicExtraInfoView = Ember.ContainerView.extend({
templateName: 'topic_extra_info', templateName: 'topic_extra_info',
classNames: ['extra-info'], classNames: ['extra-info'],
topicBinding: 'controller.topic', topicBinding: 'controller.topic',
showFavoriteButton: (function() { showFavoriteButton: function() {
return Discourse.currentUser && !this.get('topic.isPrivateMessage'); return Discourse.User.current() && !this.get('topic.isPrivateMessage');
}).property('topic.isPrivateMessage') }.property('topic.isPrivateMessage')
}) })
}); });

View File

@ -339,9 +339,9 @@ Discourse.TopicView = Discourse.View.extend(Discourse.Scrolling, {
return false; return false;
}, },
showFavoriteButton: (function() { showFavoriteButton: function() {
return Discourse.currentUser && !this.get('topic.isPrivateMessage'); return Discourse.User.current() && !this.get('topic.isPrivateMessage');
}).property('topic.isPrivateMessage'), }.property('topic.isPrivateMessage'),
resetExamineDockCache: function() { resetExamineDockCache: function() {
this.docAt = null; this.docAt = null;

View File

@ -8,7 +8,6 @@
**/ **/
Discourse.UserActivityView = Discourse.View.extend({ Discourse.UserActivityView = Discourse.View.extend({
templateName: 'user/activity', templateName: 'user/activity',
currentUserBinding: 'Discourse.currentUser',
userBinding: 'controller.content', userBinding: 'controller.content',
didInsertElement: function() { didInsertElement: function() {