3 const debug = require('debug-proxy')('app:chat-toolbar-input');
4 var context = require('gitter-web-client-context');
5 var appEvents = require('../../utils/appevents');
6 var ChatInputView = require('../chat/chatInputView');
7 var cocktail = require('backbone.cocktail');
8 var KeyboardEventsMixin = require('../keyboard-events-mixin');
9 var unreadItemsClient = require('../../components/unread-items-client');
10 var UnreadBannerView = require('../app/unreadBannerView');
11 var ChatToolbarLayout = require('./chat-toolbar');
12 var CollaboratorsView = require('../app/collaboratorsView');
13 var JoinRoomView = require('../chat/join-room-view');
15 require('../behaviors/isomorphic');
17 var ChatToolbarInputLayout = ChatToolbarLayout.extend({
18 monitorUnreadItems: true,
20 backspace: 'onKeyBackspace',
25 'change:roomMember': '_roomMemberChanged'
31 el: '#content-wrapper',
32 init: 'initChatRegion' // Declared in super
36 el: '#right-toolbar-layout',
37 init: 'initToolbarRegion' // Declared in super
42 init: 'initInputRegion'
46 el: '#header-wrapper',
47 init: 'initHeaderRegion' // Declared in super
50 // TODO Move to chat-toolbar layout and
51 // decide how are they gonna look like in mobile
54 init: 'initBannerTopRegion'
59 el: '#bottom-unread-banner',
60 init: 'initBannerBottomRegion'
64 el: '#collaborators-container',
65 init: 'initCollaboratorsView'
70 initInputRegion: function(optionsForRegion) {
71 if (this.model.get('roomMember')) {
72 debug('Already a room member so showing chat input');
73 return new ChatInputView(
75 model: context.troupe(),
76 collection: this.options.chatCollection
80 debug('Not a room member so showing join room button');
81 return new JoinRoomView(optionsForRegion({}, { rerender: true }));
85 initBannerTopRegion: function(optionsForRegion) {
86 return new UnreadBannerView.Top(
88 model: unreadItemsClient.acrossTheFold()
93 initBannerBottomRegion: function(optionsForRegion) {
94 return new UnreadBannerView.Bottom(
96 model: unreadItemsClient.acrossTheFold()
101 initCollaboratorsView: function(optionsForRegion) {
102 return new CollaboratorsView(optionsForRegion());
105 _roomMemberChanged: function() {
106 var inputRegion = this.regionManager.get('input');
108 if (this.model.get('roomMember')) {
111 model: context.troupe(),
112 collection: this.options.chatCollection
116 if (!this.model.get('aboutToLeave')) {
117 inputRegion.show(new JoinRoomView({}));
122 onKeyBackspace: function(e) {
127 onKeyQuote: function(e) {
133 getSelectionText: function() {
135 if (window.getSelection) {
136 text = window.getSelection().toString();
137 } else if (document.selection && document.selection.type != 'Control') {
138 text = document.selection.createRange().text;
143 quoteText: function() {
144 var selectedText = this.getSelectionText();
145 if (selectedText.length > 0) {
146 appEvents.trigger('input.append', '> ' + selectedText, { newLine: true });
151 cocktail.mixin(ChatToolbarInputLayout, KeyboardEventsMixin);
153 module.exports = ChatToolbarInputLayout;