Skip to content

Commit feb34d5

Browse files
committed
tabs work to navigate between rooms, removed relational
1 parent cad019e commit feb34d5

23 files changed

+200
-215
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ develop-eggs
2525
*.swm
2626
*.swl
2727
*.swk
28+
2829
*.bak
2930

3031
pyvenv.cfg
@@ -81,3 +82,6 @@ npm-debug.log
8182
centrifuge.db
8283
config.json
8384
.centrc
85+
86+
#build files
87+
*.built.js

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ ws:
1818

1919
shell:
2020
bin/pshell -p bpython wwc/development.ini
21+
22+
build:
23+
node node_modules/requirejs/bin/r.js -o build.js

app/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
<!-- build:js scripts/main.js -->
2929
<script data-main="app/scripts/init" src="app/bower_components/requirejs/require.js"></script>
30+
<!--<script src="app/bower_components/requirejs/require.js"></script>
31+
<script src="app/main.built.js"></script>-->
3032
<!-- endbuild -->
3133

3234
</body>

app/scripts/chat/chat_app.js

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ define([
66
"scripts/chat/common/channel/channel_controller",
77
"scripts/chat/common/input/input_controller",
88
"scripts/chat/room/room_controller",
9-
"scripts/entities/relation/room_relation",
9+
"scripts/entities/model/room_model",
1010
"scripts/region_manager",
1111
],
1212
function (
@@ -17,13 +17,13 @@ function (
1717
ChannelController,
1818
InputController,
1919
RoomController,
20-
RoomRelationalModel,
20+
RoomModel,
2121
regionManager
2222
) {
2323

2424
var ChatRouter = Backbone.Marionette.AppRouter.extend({
2525
appRoutes: {
26-
"room/:room" : "showChat"
26+
"room/:room" : "showChatRoom"
2727
}
2828
});
2929

@@ -39,26 +39,33 @@ function (
3939

4040
var roomControllers = {};
4141

42-
var API = {
43-
createChatRoom: function (room) {
42+
var createChatRoom = function (room) {
4443

45-
/* called to create a room
46-
*/
44+
/* called to create a room
45+
*/
4746

48-
var roomRelationalModel = communicator.reqres.request('entities:room:add', room);
47+
var roomModel = communicator.reqres.request('entities:room:add', room);
4948

50-
roomControllers[room] = new RoomController({
51-
region: chatLayout.roomRegion,
52-
roomModel: roomRelationalModel,
53-
});
49+
roomControllers[room] = new RoomController({
50+
region: chatLayout.roomRegion,
51+
roomModel: roomModel,
52+
});
5453

55-
},
54+
communicator.vent.trigger("chat:create:room", room);
55+
56+
};
57+
58+
var API = {
5659
showChatRoom: function (room) {
5760

5861
/* called to show a specific room
5962
* i.e. to switch between rooms
6063
*/
6164

65+
if(!roomControllers.hasOwnProperty(room)){
66+
createChatRoom(room);
67+
}
68+
6269
roomControllers[room].showRoom();
6370

6471
},
@@ -86,8 +93,6 @@ function (
8693
communicator.vent.on("login:submit", function (room) {
8794
communicator.command.execute("ws:connect");
8895
communicator.vent.on("ws:connect", function () {
89-
API.createChatRoom(room);
90-
communicator.vent.trigger("chat:create:room", room);
9196
API.showChat();
9297
communicator.vent.trigger("chat:show:room", room);
9398
});

app/scripts/chat/common/channel/channel_collection_view.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@ function (Backbone, ChannelItemView) {
2222

2323
onTabChange: function (view) {
2424
//TODO don't do this if tab clicked is already active tab
25+
//TODO refactor duplicate function
26+
//TODO refactor duplicate comment
2527
this.$el.children().removeClass("active");
2628
view.$el.addClass("active");
2729
},
2830

2931
onAfterItemAdded: function(view){
32+
//TODO refactor duplicate function
33+
//TODO refactor duplicate comment
3034
this.$el.children().removeClass("active");
3135
view.$el.addClass("active");
3236
},

app/scripts/chat/common/channel/channel_controller.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@ function (Backbone, communicator, ChannelCollection, ChannelCollectionView) {
1616
collection: new ChannelCollection()
1717
});
1818

19+
//TODO shouldn't we just listen for room collection add events?
1920
communicator.vent.on("chat:create:room", function (room) {
2021
this.channelCollectionView.collection.add({channel: room});
2122
}, this);
23+
24+
this.listenTo(this.channelCollectionView, 'itemview:change', function (event, view) {
25+
communicator.vent.trigger('chat:show:room', view.model.get('channel'));
26+
});
2227
},
2328

2429
showChannels: function () {
2530
this.region.show(this.channelCollectionView);
26-
//move somewhere else
27-
//this.channelCollectionView.collection.add({channel: room});
2831
},
2932

3033
onClose: function () {

app/scripts/chat/room/message/message_collection_view.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ function (Backbone, MessageItemView) {
1212

1313
itemView: MessageItemView,
1414

15-
/* ui selector cache */
1615
ui: {},
1716

18-
/* Ui events hash */
1917
events: {},
2018

2119
collectionEvents: {
2220
},
2321

2422
/* on render callback */
25-
onRender: function() {}
23+
onRender: function() {
24+
console.log("rendering");
25+
}
2626
});
2727

2828
return MessageCollectionView;

app/scripts/chat/room/message/message_controller.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ function (Backbone, communicator, MessageCollection, MessageCollectionView) {
1919
},
2020

2121
showMessages: function () {
22+
this.region.reset();
2223
this.region.show(this.messageCollectionView);
2324
},
2425

2526
onClose: function () {
27+
console.log("close");
2628
},
2729

2830
});

app/scripts/chat/room/nick/nick_controller.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ function (Backbone, communicator, NickCollectionView) {
1818
},
1919

2020
showNicks: function () {
21+
this.region.reset();
2122
this.region.show(this.nickCollectionView);
2223
},
2324

app/scripts/entities/collection/channel_collection.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ function (Backbone, Communicator, ChannelModel) {
99
model: ChannelModel
1010
});
1111

12-
//Communicator.vent.on('ws:');
13-
1412
return ChannelCollection;
1513

1614
});

0 commit comments

Comments
 (0)