FIX: Private message link on messages view did not work. Removed a lot of duplication.

This commit is contained in:
Robin Ward 2013-07-18 17:07:05 -04:00
parent 7d4b089cd1
commit 257ddf5fc9
6 changed files with 151 additions and 198 deletions

View File

@ -1,3 +1,11 @@
/**
The base route for showing an activity stream.
@class UserActivityRoute
@extends Discourse.Route
@namespace Discourse
@module Discourse
**/
Discourse.UserActivityRoute = Discourse.Route.extend({ Discourse.UserActivityRoute = Discourse.Route.extend({
renderTemplate: function() { renderTemplate: function() {
this.render('user_activity', {into: 'user', outlet: 'userOutlet' }); this.render('user_activity', {into: 'user', outlet: 'userOutlet' });
@ -5,19 +13,50 @@ Discourse.UserActivityRoute = Discourse.Route.extend({
model: function() { model: function() {
return this.modelFor('user'); return this.modelFor('user');
},
setupController: function(controller, user) {
this.controllerFor('userActivity').set('model', user);
var composerController = this.controllerFor('composer');
controller.set('model', user);
Discourse.Draft.get('new_private_message').then(function(data) {
if (data.draft) {
composerController.open({
draft: data.draft,
draftKey: 'new_private_message',
ignoreIfChanged: true,
draftSequence: data.draft_sequence
});
} }
}); });
}
});
/**
A route for showing a user's activity
@class UserIndexRoute
@extends Discourse.Route
@namespace Discourse
@module Discourse
**/
Discourse.UserActivityIndexRoute = Discourse.Route.extend({ Discourse.UserActivityIndexRoute = Discourse.Route.extend({
model: function() { model: function() {
return this.modelFor('user').findStream(); return this.modelFor('user').findStream();
}, },
setupController: function(controller, model) { setupController: function(controller, model) {
this.controllerFor('userActivity').set('stream', model); this.controllerFor('userActivity').setProperties({
model: this.modelFor('user'),
stream: model,
privateMessageView: this.get('privateMessageRoute')
});
} }
}); });
// Build all the filter routes
Object.keys(Discourse.UserAction.TYPES).forEach(function (userAction) { Object.keys(Discourse.UserAction.TYPES).forEach(function (userAction) {
Discourse["UserActivity" + userAction.classify() + "Route"] = Discourse.UserActivityIndexRoute.extend({ Discourse["UserActivity" + userAction.classify() + "Route"] = Discourse.UserActivityIndexRoute.extend({
model: function() { model: function() {
@ -26,6 +65,15 @@ Object.keys(Discourse.UserAction.TYPES).forEach(function (userAction) {
}); });
}); });
/**
Show the user's default route
@class UserIndexRoute
@extends Discourse.Route
@namespace Discourse
@module Discourse
**/
Discourse.UserIndexRoute = Discourse.Route.extend({ Discourse.UserIndexRoute = Discourse.Route.extend({
renderTemplate: function() { renderTemplate: function() {
this.render('user_activity', {into: 'user', outlet: 'userOutlet' }); this.render('user_activity', {into: 'user', outlet: 'userOutlet' });
@ -38,23 +86,65 @@ Discourse.UserIndexRoute = Discourse.Route.extend({
setupController: function(controller, stream) { setupController: function(controller, stream) {
var userActivity = this.controllerFor('userActivity'); var userActivity = this.controllerFor('userActivity');
userActivity.setProperties({ userActivity.setProperties({
stream: stream, model: this.modelFor('user'),
model: this.modelFor('user') stream: stream
}); });
} }
}); });
/** /**
This controller supports all actions on a user's activity stream Base route for showing private messages
@class UserActivityController @class UserPrivateMessagesRoute
@extends Discourse.ObjectController @extends Discourse.UserActivityRoute
@namespace Discourse @namespace Discourse
@module Discourse @module Discourse
**/ **/
Discourse.UserActivityController = Discourse.Controller.extend({ Discourse.UserPrivateMessagesRoute = Discourse.UserActivityRoute.extend({});
/**
Default private messages route
@class UserPrivateMessagesIndexRoute
@extends Discourse.UserActivityIndexRoute
@namespace Discourse
@module Discourse
**/
Discourse.UserPrivateMessagesIndexRoute = Discourse.UserActivityIndexRoute.extend({
privateMessageRoute: true,
model: function() {
return this.modelFor('user').findStream(Discourse.UserAction.TYPES.messages_received);
}
});
/**
Private messages sent route
@class UserPrivateMessagesSentRoute
@extends Discourse.UserActivityIndexRoute
@namespace Discourse
@module Discourse
**/
Discourse.UserPrivateMessagesSentRoute = Discourse.UserActivityIndexRoute.extend({
privateMessageRoute: true,
model: function() {
return this.modelFor('user').findStream(Discourse.UserAction.TYPES.messages_sent);
}
});
/**
This controller supports all actions on a user's activity stream
@class UserActivityController
@extends Discourse.Controller
@namespace Discourse
@module Discourse
**/
Discourse.UserActivityController = Discourse.ObjectController.extend({
needs: ['composer'], needs: ['composer'],
kickOffPrivateMessage: (function() { kickOffPrivateMessage: (function() {

View File

@ -1,85 +0,0 @@
/**
Base route for showing private messages
@class UserPrivateMessagesRoute
@extends Discourse.Route
@namespace Discourse
@module Discourse
**/
Discourse.UserPrivateMessagesRoute = Discourse.Route.extend({
renderTemplate: function() {
this.render('user_private_messages', {into: 'user', outlet: 'userOutlet' });
},
model: function() {
return this.modelFor('user');
},
setupController: function(controller, user) {
var composerController = this.controllerFor('composer');
controller.set('model', user);
Discourse.Draft.get('new_private_message').then(function(data) {
if (data.draft) {
composerController.open({
draft: data.draft,
draftKey: 'new_private_message',
ignoreIfChanged: true,
draftSequence: data.draft_sequence
});
}
});
}
});
/**
Default private messages route
@class UserPrivateMessagesIndexRoute
@extends Discourse.Route
@namespace Discourse
@module Discourse
**/
Discourse.UserPrivateMessagesIndexRoute = Discourse.Route.extend({
model: function() {
return this.modelFor('user').findStream(Discourse.UserAction.TYPES.messages_received);
},
setupController: function(controller, model) {
this.controllerFor('userPrivateMessages').set('stream', model);
}
});
/**
Private messages sent route
@class UserPrivateMessagesSentRoute
@extends Discourse.Route
@namespace Discourse
@module Discourse
**/
Discourse.UserPrivateMessagesSentRoute = Discourse.UserPrivateMessagesIndexRoute.extend({
model: function() {
return this.modelFor('user').findStream(Discourse.UserAction.TYPES.messages_sent);
}
});
/**
This controller handles actions related to a user's private messages.
@class UserPrivateMessagesController
@extends Discourse.ObjectController
@namespace Discourse
@module Discourse
**/
Discourse.UserPrivateMessagesController = Discourse.ObjectController.extend({
needs: ['composer'],
composePrivateMessage: function() {
this.get('controllers.composer').open({
action: Discourse.Composer.PRIVATE_MESSAGE,
archetypeId: 'private_message',
draftKey: 'new_private_message'
});
}
});

View File

@ -148,7 +148,7 @@ Discourse.Composer = Discourse.Model.extend({
hasMetaData: function() { hasMetaData: function() {
var metaData = this.get('metaData'); var metaData = this.get('metaData');
return metaData ? Em.empty(Em.keys(this.get('metaData'))) : false; return metaData ? Em.isEmpty(Em.keys(this.get('metaData'))) : false;
}.property('metaData'), }.property('metaData'),
/** /**

View File

@ -1,4 +1,3 @@
{{#with model}}
<div id='user-info'> <div id='user-info'>
<nav class='buttons'> <nav class='buttons'>
{{#if can_edit}} {{#if can_edit}}
@ -15,11 +14,18 @@
<div class='clearfix'></div> <div class='clearfix'></div>
<ul class='action-list nav-stacked side-nav'> <ul class='action-list nav-stacked side-nav'>
{{activityFilter count=statsCountNonPM user=this}} {{#if privateMessageView}}
{{#each stat in statsPmsOnly}}
{{activityFilter content=stat user=model}}
{{/each}}
{{else}}
{{activityFilter count=statsCountNonPM user=model}}
{{#each stat in statsExcludingPms}} {{#each stat in statsExcludingPms}}
{{activityFilter content=stat user=model}} {{activityFilter content=stat user=model}}
{{/each}} {{/each}}
{{/if}}
</ul> </ul>
<div class='show'> <div class='show'>
<dl> <dl>
{{#if websiteName}} {{#if websiteName}}
@ -49,8 +55,7 @@
<button class='btn' data-not-implemented='true' disabled title="{{i18n not_implemented}}">{{i18n user.download_archive}}</button> <button class='btn' data-not-implemented='true' disabled title="{{i18n not_implemented}}">{{i18n user.download_archive}}</button>
</div> </div>
{{/if}} {{/if}}
</div> </div>
{{/with}}
{{userStream stream=stream}} {{userStream stream=stream}}

View File

@ -1,26 +0,0 @@
<div id='user-info'>
{{#with model}}
<nav class='buttons'>
{{#if can_edit}}
{{#linkTo "preferences" class="btn"}}{{i18n user.edit}}{{/linkTo}}
{{/if}}
<br/>
{{#if can_send_private_message_to_user}}
<button class='btn create' {{action composePrivateMessage}}>
<i class='icon icon-plus'></i>
{{i18n user.private_message}}
</button>
{{/if}}
</nav>
<div class='clearfix'></div>
<ul class='action-list nav-stacked side-nav'>
{{#each stat in statsPmsOnly}}
{{activityFilter content=stat user=model}}
{{/each}}
</ul>
{{/with}}
</div>
{{userStream stream=stream}}

View File

@ -1,31 +0,0 @@
/**
This view handles rendering of a user's private messages
@class UserPrivateMessagesView
@extends Discourse.View
@namespace Discourse
@module Discourse
**/
Discourse.UserPrivateMessagesView = Discourse.View.extend({
templateName: 'user/private_messages',
selectCurrent: function(evt) {
var t;
t = $(evt.currentTarget);
t.closest('.action-list').find('li').removeClass('active');
return t.closest('li').addClass('active');
},
inbox: function(evt) {
this.selectCurrent(evt);
return this.set('controller.filter', Discourse.UserAction.TYPES.messages_received);
},
sentMessages: function(evt) {
this.selectCurrent(evt);
return this.set('controller.filter', Discourse.UserAction.TYPES.messages_sent);
}
});