ES6: Convert all button views

This commit is contained in:
Robin Ward 2014-06-23 12:37:38 -04:00
parent d9fb5c4468
commit 07ae7435f2
17 changed files with 75 additions and 157 deletions

View File

@ -8,7 +8,7 @@
</ul>
{{#if canChangeCategoryNotificationLevel}}
{{view Discourse.CategoryNotificationsButton category=category}}
{{view 'category-notifications-button' category=category}}
{{/if}}
{{#if canCreateTopic}}

View File

@ -94,7 +94,7 @@
{{#if postStream.loadedAllPosts}}
{{view 'topic-closing' topic=model}}
{{view Discourse.TopicFooterButtonsView topicBinding="model"}}
{{view 'topic-footer-buttons' topic=model}}
{{#if details.suggested_topics.length}}
<div id='suggested-topics'>

View File

@ -1,12 +1,4 @@
/**
This view handles rendering of a button
@class ButtonView
@extends Discourse.View
@namespace Discourse
@module Discourse
**/
Discourse.ButtonView = Discourse.View.extend({
export default Discourse.View.extend({
tagName: 'button',
classNameBindings: [':btn', ':standard', 'dropDownToggle'],
attributeBindings: ['title', 'data-toggle', 'data-share-url'],
@ -25,7 +17,4 @@ Discourse.ButtonView = Discourse.View.extend({
}
buffer.push(this.get('text'));
}
});

View File

@ -1,12 +1,6 @@
/**
A button to display notification options for categories.
import NotificationsButton from 'discourse/views/notifications-button';
@class NotificationsButton
@extends Discourse.DropdownButtonView
@namespace Discourse
@module Discourse
**/
Discourse.CategoryNotificationsButton = Discourse.NotificationsButton.extend({
export default NotificationsButton.extend({
classNames: ['notification-options', 'category-notification-menu'],
buttonIncludesText: false,
longDescriptionBinding: null,

View File

@ -1,12 +1,4 @@
/**
This view handles rendering of a button with an associated drop down
@class DropdownButtonView
@extends Discourse.View
@namespace Discourse
@module Discourse
**/
Discourse.DropdownButtonView = Discourse.View.extend({
export default Discourse.View.extend({
classNameBindings: [':btn-group', 'hidden'],
shouldRerender: Discourse.View.renderIfChanged('text', 'longDescription'),

View File

@ -1,12 +1,6 @@
/**
A button for flagging a topic
import ButtonView from 'discourse/views/button';
@class FlagTopicButton
@extends Discourse.ButtonView
@namespace Discourse
@module Discourse
**/
Discourse.FlagTopicButton = Discourse.ButtonView.extend({
export default ButtonView.extend({
classNames: ['flag-topic'],
textKey: 'topic.flag_topic.title',
helpKey: 'topic.flag_topic.help',
@ -19,4 +13,3 @@ Discourse.FlagTopicButton = Discourse.ButtonView.extend({
buffer.push("<i class='fa fa-flag'></i>");
}
});

View File

@ -1,12 +1,6 @@
/**
A button for inviting users to reply to a topic
import ButtonView from 'discourse/views/button';
@class InviteReplyButton
@extends Discourse.ButtonView
@namespace Discourse
@module Discourse
**/
Discourse.InviteReplyButton = Discourse.ButtonView.extend({
export default ButtonView.extend({
textKey: 'topic.invite_reply.title',
helpKey: 'topic.invite_reply.help',
attributeBindings: ['disabled'],

View File

@ -1,12 +1,6 @@
/**
A button prompting users to login to reply to a topic
import ButtonView from 'discourse/views/button';
@class LoginReplyButton
@extends Discourse.ButtonView
@namespace Discourse
@module Discourse
**/
Discourse.LoginReplyButton = Discourse.ButtonView.extend({
export default ButtonView.extend({
textKey: 'topic.login_reply',
classNames: ['btn', 'btn-primary', 'create'],
click: function() {

View File

@ -1,12 +1,6 @@
/**
A button to display notification options.
import DropdownButtonView from 'discourse/views/dropdown-button';
@class NotificationsButton
@extends Discourse.DropdownButtonView
@namespace Discourse
@module Discourse
**/
Discourse.NotificationsButton = Discourse.DropdownButtonView.extend({
export default DropdownButtonView.extend({
classNames: ['notification-options'],
title: '',
buttonIncludesText: true,
@ -76,4 +70,3 @@ Discourse.NotificationsButton = Discourse.DropdownButtonView.extend({
}
});

View File

@ -1,12 +1,6 @@
/**
A button to display pinned options.
import DropdownButtonView from 'discourse/views/dropdown-button';
@class PinnedButton
@extends Discourse.DropdownButtonView
@namespace Discourse
@module Discourse
**/
Discourse.PinnedButton = Discourse.DropdownButtonView.extend({
export default DropdownButtonView.extend({
descriptionKey: 'help',
classNames: ['pinned-options'],
title: '',
@ -62,4 +56,3 @@ Discourse.PinnedButton = Discourse.DropdownButtonView.extend({
}
});

View File

@ -1,12 +1,6 @@
/**
A button for replying to a topic
import ButtonView from 'discourse/views/button';
@class ReplyButton
@extends Discourse.ButtonView
@namespace Discourse
@module Discourse
**/
Discourse.ReplyButton = Discourse.ButtonView.extend({
export default ButtonView.extend({
classNames: ['btn', 'btn-primary', 'create'],
helpKey: 'topic.reply.help',

View File

@ -1,12 +1,6 @@
/**
A button for sharing a link to a topic
import ButtonView from 'discourse/views/button';
@class ShareButton
@extends Discourse.ButtonView
@namespace Discourse
@module Discourse
**/
Discourse.ShareButton = Discourse.ButtonView.extend({
export default ButtonView.extend({
classNames: ['share'],
textKey: 'topic.share.title',
helpKey: 'topic.share.help',

View File

@ -1,12 +1,6 @@
/**
A button for starring a topic
import ButtonView from 'discourse/views/button';
@class StarButton
@extends Discourse.ButtonView
@namespace Discourse
@module Discourse
**/
Discourse.StarButton = Discourse.ButtonView.extend({
export default ButtonView.extend({
classNames: ['star'],
textKey: 'starred.title',
helpKeyBinding: 'controller.starTooltipKey',

View File

@ -0,0 +1,48 @@
import LoginReplyButton from 'discourse/views/login-reply-button';
import FlagTopicButton from 'discourse/views/flag-topic-button';
import StarButton from 'discourse/views/star-button';
import ShareButton from 'discourse/views/share-button';
import InviteReplyButton from 'discourse/views/invite-reply-button';
import ReplyButton from 'discourse/views/reply-button';
import PinnedButton from 'discourse/views/pinned-button';
import TopicNotificationsButton from 'discourse/views/topic-notifications-button';
export default Discourse.ContainerView.extend({
elementId: 'topic-footer-buttons',
topicBinding: 'controller.content',
init: function() {
this._super();
this.createButtons();
},
// Add the buttons below a topic
createButtons: function() {
var topic = this.get('topic');
if (Discourse.User.current()) {
if (!topic.get('isPrivateMessage')) {
// We hide some controls from private messages
if (this.get('topic.details.can_invite_to') && !this.get('topic.category.read_restricted')) {
this.attachViewClass(InviteReplyButton);
}
this.attachViewClass(StarButton);
this.attachViewClass(ShareButton);
if (this.get('topic.details.can_flag_topic')) {
this.attachViewClass(FlagTopicButton);
}
}
if (this.get('topic.details.can_create_post')) {
this.attachViewClass(ReplyButton);
}
this.attachViewClass(PinnedButton);
this.attachViewClass(TopicNotificationsButton);
this.trigger('additionalButtons', this);
} else {
// If not logged in give them a login control
this.attachViewClass(LoginReplyButton);
}
}
});

View File

@ -1,12 +1,6 @@
/**
A button to display topic notification options.
import NotificationsButton from 'discourse/views/notifications-button';
@class TopicNotificationsButton
@extends Discourse.NotificationsButton
@namespace Discourse
@module Discourse
**/
Discourse.TopicNotificationsButton = Discourse.NotificationsButton.extend({
export default NotificationsButton.extend({
longDescriptionBinding: 'topic.details.notificationReasonText',
topic: Em.computed.alias('controller.model'),
target: Em.computed.alias('topic'),
@ -24,4 +18,3 @@ Discourse.TopicNotificationsButton = Discourse.NotificationsButton.extend({
this.get('topic.details').updateNotifications(id);
}
});

View File

@ -1,47 +0,0 @@
/**
This view is used for rendering the buttons at the footer of the topic
@class TopicFooterButtonsView
@extends Discourse.ContainerView
@namespace Discourse
@module Discourse
**/
Discourse.TopicFooterButtonsView = Discourse.ContainerView.extend({
elementId: 'topic-footer-buttons',
topicBinding: 'controller.content',
init: function() {
this._super();
this.createButtons();
},
// Add the buttons below a topic
createButtons: function() {
var topic = this.get('topic');
if (Discourse.User.current()) {
if (!topic.get('isPrivateMessage')) {
// We hide some controls from private messages
if (this.get('topic.details.can_invite_to') && !this.get('topic.category.read_restricted')) {
this.attachViewClass(Discourse.InviteReplyButton);
}
this.attachViewClass(Discourse.StarButton);
this.attachViewClass(Discourse.ShareButton);
if (this.get('topic.details.can_flag_topic')) {
this.attachViewClass(Discourse.FlagTopicButton);
}
}
if (this.get('topic.details.can_create_post')) {
this.attachViewClass(Discourse.ReplyButton);
}
this.attachViewClass(Discourse.PinnedButton);
this.attachViewClass(Discourse.TopicNotificationsButton);
this.trigger('additionalButtons', this);
} else {
// If not logged in give them a login control
this.attachViewClass(Discourse.LoginReplyButton);
}
}
});

View File

@ -23,9 +23,9 @@
//= require ./discourse/views/modal/modal_body_view
//= require ./discourse/views/modal/flag_view
//= require ./discourse/views/combo-box
//= require ./discourse/views/buttons/button_view
//= require ./discourse/views/buttons/dropdown_button_view
//= require ./discourse/views/buttons/notifications_button
//= require ./discourse/views/button
//= require ./discourse/views/dropdown-button
//= require ./discourse/views/notifications-button
//= require ./discourse/views/pagedown-preview
//= require ./discourse/routes/discourse_route
//= require ./discourse/routes/discourse_restricted_user_route