3 var $ = require('jquery');
4 var Marionette = require('backbone.marionette');
5 var urlParse = require('url-parse');
6 var appEvents = require('../../utils/appevents');
7 var context = require('gitter-web-client-context');
8 var modalRegion = require('../../components/modal-region');
9 var LoginView = require('../modals/login-view');
10 var ProfileMenu = require('../profile-menu/profile-menu-view');
11 var template = require('./tmpl/explore-view.hbs');
12 var itemTemplate = require('../../../templates/partials/room_card.hbs');
13 var clientEnv = require('gitter-client-env');
15 require('../behaviors/isomorphic');
17 var TagPillView = Marionette.ItemView.extend({
18 template: itemTemplate,
23 initialize: function() {
24 //console.log('tagPillView init');
28 //console.log('click tag pill');
32 var TagPillListView = Marionette.CollectionView.extend({
33 childView: TagPillView,
34 initialize: function() {
35 //console.log('tagPillListView init');
39 var RoomCardView = Marionette.ItemView.extend({
40 template: itemTemplate,
43 popEditTagsModal: function() {
44 require.ensure(['../modals/edit-tags-view'], function(require) {
45 var EditTagsView = require('../modals/edit-tags-view');
46 var editTagsModal = new EditTagsView({
47 roomId: 0 // FIXME: the room id
54 var RoomCardListView = Marionette.CollectionView.extend({
55 childView: RoomCardView,
56 initialize: function() {
57 //console.log('roomCardListView init');
61 var ExploreView = Marionette.LayoutView.extend({
66 el: '.js-explore-tag-pill-list',
67 init: 'initTagPillListView'
70 el: '.js-room-card-list',
71 init: 'initRoomCardListView'
79 leftMenuToggle: '.js-header-view-left-menu-toggle',
80 signInButton: '.js-sign-in',
81 createRoomButton: '.js-explore-create-button'
84 'click @ui.leftMenuToggle': 'onLeftMenuToggleClick',
85 'click @ui.signInButton': 'popSignInModal',
86 'click @ui.createRoomButton': 'popCreate'
89 initRoomCardListView: function(optionsForRegion) {
90 return new RoomCardListView(optionsForRegion({}));
92 initTagPillListView: function(optionsForRegion) {
93 return new TagPillListView(optionsForRegion({}));
96 initialize: function() {
97 // TODO: Once we re-render on the client with a snapshot, this stuff can be removed
98 $('.js-explore-tag-pill[data-needs-authentication]').on('click', this.popSignInModal);
99 this.setupProfileMenu();
102 serializeData: function() {
103 var headlineNumbers = clientEnv.headlineNumbers || {};
106 isLoggedIn: context.isLoggedIn(),
107 headlineGitterUsers: headlineNumbers.gitterUsers,
108 headlineGitterRooms: headlineNumbers.gitterRooms,
109 headlineGitterGroups: headlineNumbers.gitterGroups,
110 headlineGitterCountries: headlineNumbers.gitterCountries
114 onRender: function() {
115 this.setupProfileMenu();
118 setupProfileMenu: function() {
119 if (context.isLoggedIn()) {
120 //If an instance of the profile menu exists destroy it to remove listeners etc
121 if (this.profileMenu) {
122 this.profileMenu.destroy();
124 //Make a new profile menu
125 this.profileMenu = new ProfileMenu({ el: '#profile-menu' });
127 this.profileMenu.render();
131 onLeftMenuToggleClick() {
132 appEvents.trigger('dispatchVueAction', 'toggleLeftMenu', true);
135 popSignInModal: function(e) {
136 var href = $(e.currentTarget).attr('href');
137 var parsedUrl = urlParse(href, true);
139 var modal = new LoginView(parsedUrl.query);
140 modalRegion.show(modal);
141 // hack this modal because we're not using history or routing here
142 modal.navigable = false;
147 popCreate: function() {
148 appEvents.trigger('route', 'createcommunity');
152 module.exports = ExploreView;