Merge branch 'master' of github.com:discourse/discourse

This commit is contained in:
Neil Lalonde 2013-09-11 10:20:27 -04:00
commit fe3693cdef
20 changed files with 77 additions and 57 deletions

View File

@ -229,21 +229,3 @@ Discourse = Ember.Application.createWithMixins(Discourse.Ajax, {
Discourse.Router = Discourse.Router.reopen({ location: 'discourse_location' }); Discourse.Router = Discourse.Router.reopen({ location: 'discourse_location' });
Discourse.initializer({
name: 'currentUser',
initialize: function(container) {
container.register('user:current', Discourse.User.current(), { instantiate: false });
}
});
Discourse.initializer({
name: 'injectCurrentUser',
initialize: function(container) {
if (container.lookup('user:current')) {
container.injection('controller', 'currentUser', 'user:current');
container.injection('route', 'currentUser', 'user:current');
}
}
});

View File

@ -103,7 +103,7 @@ Discourse.ComposerController = Discourse.Controller.extend({
opts = opts || {}; opts = opts || {};
composerController.close(); composerController.close();
var currentUser = this.get('currentUser'); var currentUser = Discourse.User.current();
if (composer.get('creatingTopic')) { if (composer.get('creatingTopic')) {
currentUser.set('topic_count', currentUser.get('topic_count') + 1); currentUser.set('topic_count', currentUser.get('topic_count') + 1);
} else { } else {
@ -198,6 +198,9 @@ Discourse.ComposerController = Discourse.Controller.extend({
open: function(opts) { open: function(opts) {
if (!opts) opts = {}; if (!opts) opts = {};
var composerMessages = this.get('controllers.composerMessages');
composerMessages.reset();
var promise = opts.promise || Ember.Deferred.create(); var promise = opts.promise || Ember.Deferred.create();
opts.promise = promise; opts.promise = promise;
this.set('typedReply', false); this.set('typedReply', false);

View File

@ -26,6 +26,11 @@ Discourse.ComposerMessagesController = Ember.ArrayController.extend({
closeMessage: function(message) { closeMessage: function(message) {
this.removeObject(message); this.removeObject(message);
},
reset: function() {
this.clear();
this.set('messagesByTemplate', {});
} }
}); });

View File

@ -7,4 +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

@ -21,8 +21,8 @@ Discourse.HeaderController = Discourse.Controller.extend({
}.property(), }.property(),
showFavoriteButton: function() { showFavoriteButton: function() {
return this.get('currentUser') && !this.get('topic.isPrivateMessage'); return Discourse.User.current() && !this.get('topic.isPrivateMessage');
}.property('currentUser', 'topic.isPrivateMessage'), }.property('topic.isPrivateMessage'),
mobileDevice: function() { mobileDevice: function() {
return Discourse.Mobile.isMobileDevice; return Discourse.Mobile.isMobileDevice;

View File

@ -13,7 +13,7 @@ Discourse.ListController = Discourse.Controller.extend({
needs: ['composer', 'modal', 'listTopics'], needs: ['composer', 'modal', 'listTopics'],
availableNavItems: function() { availableNavItems: function() {
var loggedOn = !!this.get('currentUser'); var loggedOn = !!Discourse.User.current();
return Discourse.SiteSettings.top_menu.split("|").map(function(i) { return Discourse.SiteSettings.top_menu.split("|").map(function(i) {
return Discourse.NavItem.fromText(i, { return Discourse.NavItem.fromText(i, {
@ -22,7 +22,7 @@ Discourse.ListController = Discourse.Controller.extend({
}).filter(function(i) { }).filter(function(i) {
return i !== null; return i !== null;
}); });
}.property('currentUser'), }.property(),
createTopicText: function() { createTopicText: function() {
if (this.get('category.name')) { if (this.get('category.name')) {
@ -125,12 +125,12 @@ Discourse.ListController = Discourse.Controller.extend({
canEditCategory: function() { canEditCategory: function() {
if( this.present('category') ) { if( this.present('category') ) {
var u = this.get('currentUser'); var u = Discourse.User.current();
return u && u.staff; return u && u.staff;
} else { } else {
return false; return false;
} }
}.property('currentUser', 'category') }.property('category')
}); });

View File

@ -7,4 +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

@ -31,7 +31,7 @@ Discourse.QuoteButtonController = Discourse.Controller.extend({
**/ **/
selectText: function(postId) { selectText: function(postId) {
// anonymous users cannot "quote-reply" // anonymous users cannot "quote-reply"
if (!this.get('currentUser')) return; if (!Discourse.User.current()) return;
// don't display the "quote-reply" button if we can't create a post // don't display the "quote-reply" button if we can't create a post
if (!this.get('controllers.topic.model.details.can_create_post')) return; if (!this.get('controllers.topic.model.details.can_create_post')) return;

View File

@ -260,8 +260,8 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
}, },
showFavoriteButton: function() { showFavoriteButton: function() {
return this.get('currentUser') && !this.get('isPrivateMessage'); return Discourse.User.current() && !this.get('isPrivateMessage');
}.property('currentUser', 'isPrivateMessage'), }.property('isPrivateMessage'),
recoverTopic: function() { recoverTopic: function() {
this.get('content').recover(); this.get('content').recover();
@ -269,7 +269,7 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
deleteTopic: function() { deleteTopic: function() {
this.unsubscribe(); this.unsubscribe();
this.get('content').destroy(this.get('currentUser')); this.get('content').destroy(Discourse.User.current());
}, },
resetRead: function() { resetRead: function() {
@ -417,7 +417,7 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
}, },
toggleBookmark: function(post) { toggleBookmark: function(post) {
if (!this.get('currentUser')) { if (!Discourse.User.current()) {
alert(I18n.t("bookmarks.not_bookmarked")); alert(I18n.t("bookmarks.not_bookmarked"));
return; return;
} }
@ -439,7 +439,7 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
}, },
deletePost: function(post) { deletePost: function(post) {
var user = this.get('currentUser'), var user = Discourse.User.current(),
replyCount = post.get('reply_count'), replyCount = post.get('reply_count'),
self = this; self = this;

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

@ -12,7 +12,7 @@ Discourse.UserRoute = Discourse.Route.extend({
// If we're viewing the currently logged in user, return that object // If we're viewing the currently logged in user, return that object
// instead. // instead.
var currentUser = this.get('currentUser'); var currentUser = Discourse.User.current();
if (currentUser && (params.username.toLowerCase() === currentUser.get('username_lower'))) { if (currentUser && (params.username.toLowerCase() === currentUser.get('username_lower'))) {
return currentUser; return currentUser;
} }
@ -95,7 +95,7 @@ Discourse.UserActivityRoute = Discourse.Route.extend({
var composerController = this.controllerFor('composer'); var composerController = this.controllerFor('composer');
controller.set('model', user); controller.set('model', user);
if (this.get('currentUser')) { if (Discourse.User.current()) {
Discourse.Draft.get('new_private_message').then(function(data) { Discourse.Draft.get('new_private_message').then(function(data) {
if (data.draft) { if (data.draft) {
composerController.open({ composerController.open({

View File

@ -125,7 +125,9 @@
</div> </div>
{{render share}} {{render share}}
{{#if currentUser.enable_quoting}}
{{render quoteButton}} {{render quoteButton}}
{{/if}}
{{#if currentUser.staff}} {{#if currentUser.staff}}
{{render topicAdminMenu content}} {{render topicAdminMenu content}}

View File

@ -47,8 +47,6 @@ Discourse.QuoteButtonView = Discourse.View.extend({
.on("mousedown.quote-button", function(e) { .on("mousedown.quote-button", function(e) {
view.set('isMouseDown', true); view.set('isMouseDown', true);
if ($(e.target).hasClass('quote-button') || $(e.target).hasClass('create')) return; if ($(e.target).hasClass('quote-button') || $(e.target).hasClass('create')) return;
// do *not* deselect when quoting has been disabled by the user
if (!Discourse.User.currentProp('enable_quoting')) return;
// deselects only when the user left click // deselects only when the user left click
// (allows anyone to `extend` their selection using shift+click) // (allows anyone to `extend` their selection using shift+click)
if (e.which === 1 && !e.shiftKey) controller.deselectText(); if (e.which === 1 && !e.shiftKey) controller.deselectText();

View File

@ -381,8 +381,8 @@ div.ac-wrap {
} }
} }
.wmd-controls { .wmd-controls {
left: 30px; left: 10px;
right: 30px; right: 10px;
position: absolute; position: absolute;
top: 60px; top: 60px;
bottom: 54px; bottom: 54px;
@ -455,8 +455,7 @@ div.ac-wrap {
} }
.control-row.reply-area { .control-row.reply-area {
padding-left: 20px;
padding-right: 20px;
} }
@media screen and (min-width: 1550px) { @media screen and (min-width: 1550px) {

View File

@ -83,7 +83,7 @@ body {
height: 100%; height: 100%;
@include border-radius-all(5px); @include border-radius-all(5px);
.contents { .contents {
padding: 10px 20px 10px 20px; padding: 10px 10px 10px 10px;
} }
&.white { &.white {
background-color: $white; background-color: $white;

View File

@ -6,8 +6,8 @@
// -------------------------------------------------- // --------------------------------------------------
.d-header { .d-header {
padding-left: 20px !important; padding-left: 10px !important;
padding-right: 40px; padding-right: 10px !important;
min-width: 100%; min-width: 100%;
position: absolute; position: absolute;
top: 0; top: 0;
@ -43,7 +43,7 @@ box-shadow: 0 0 3px #aaa;
.panel { .panel {
float: right; float: right;
position: relative; position: relative;
margin-right: 30px; margin-right: 20px;
} }
.current-username { .current-username {
float: left; float: left;

View File

@ -99,7 +99,7 @@ button {
} }
.post-actions { .post-actions {
margin-left: 20px; margin-left: 10px;
margin-top: 2px; margin-top: 2px;
} }
@ -133,7 +133,7 @@ a.star {
} }
border-radius: 5px; border-radius: 5px;
margin: 15px 20px 20px 20px; margin: 15px 10px 20px 10px;
border: 1px solid #ddd; border: 1px solid #ddd;
h3 { h3 {
@ -246,16 +246,16 @@ a.star {
#topic-footer-buttons { #topic-footer-buttons {
border-top: 1px solid #ddd; border-top: 1px solid #ddd;
padding: 20px 20px 0 20px; padding: 20px 10px 0 10px;
} }
#suggested-topics { #suggested-topics {
float: left; float: left;
clear: left; clear: left;
margin-top: 10px; margin-top: 10px;
padding: 0 20px 0 20px; padding: 0 10px 0 10px;
th.views, td.views, td.activity, th.activity { th.views, td.views, td.activity, th.activity, th.likes, td.likes {
display: none; display: none;
} }
@ -289,7 +289,7 @@ span.post-count {
z-index: 1000; z-index: 1000;
background: #eee; background: #eee;
margin: 0 0 0 0 !important; margin: 0 0 0 0 !important;
padding: 15px 20px 15px 20px; padding: 15px 10px 15px 10px;
} }
.topic-post article.boxed img { .topic-post article.boxed img {

View File

@ -9,12 +9,12 @@ class DraftController < ApplicationController
def update def update
Draft.set(current_user, params[:draft_key], params[:sequence].to_i, params[:data]) Draft.set(current_user, params[:draft_key], params[:sequence].to_i, params[:data])
render text: 'ok' render json: success_json
end end
def destroy def destroy
Draft.clear(current_user, params[:draft_key], params[:sequence].to_i) Draft.clear(current_user, params[:draft_key], params[:sequence].to_i)
render text: 'ok' render json: success_json
end end
end end

View File

@ -329,8 +329,6 @@ class TopicsController < ApplicationController
end end
end end
private
def move_posts_to_destination(topic) def move_posts_to_destination(topic)
args = {} args = {}
args[:title] = params[:title] if params[:title].present? args[:title] = params[:title] if params[:title].present?

View File

@ -14,7 +14,7 @@ class PostActionUserSerializer < BasicUserSerializer
end end
def post_url def post_url
object.related_post.url if object.related_post.id object.related_post.url if object.related_post_id && object.related_post
end end
end end