onItemSelected: function(gistItem) { var self = this; self.loading(true); this.selectedRoomName = gistItem.id; var chatItem = new ChatItem({ 'gistId': gistItem.id }); chatItem.fetch() .done(function(res) { self.getChatHistory(res.data.content); }) .always(function() { self.loading(false); $('#conversation-content').scrollTop($( "#conversation-content")[0].scrollHeight); }); },
$.each(self.rooms, function(key, value) { var chatItem = new ChatItem({ 'gistId': key }); chatItem.fetch() .done(function(res) { var isUpdated = false; for (var index = self.collection.models.length - 1; index >= 0; index--) { if (self.collection.models[index].id === key) { res.data['room'] = self.rooms[key]; var childView = self.children.findByModel(self.collection .models[index]); childView.modelChanged(key, self.rooms[key]); isUpdated = true; } } if (isUpdated == false) { res.data['room'] = self.rooms[key]; self.collection.add(res.data); } }) .always(function() { self.loading(false); for (var index = self.collection.models.length - 1; index >= 0; index--) { if (self.collection.models[index].id === self.selectedRoomName) { var childView = self.children.findByModel(self.collection .models[index]); childView.onAddClassSelected(); break; } } }) });
addChatList: function(gist, callback) { var self = this; self.selectedRoomName = gist.id; self.loading(true); var chatItem = new ChatItem({ 'gistId': gist.id }); chatItem.fetch() .done(function(res) { res.data['room'] = self.rooms[gist.id]; self.collection.add(res.data); self.getChatHistory(res.data.content); }) .always(function() { self.loading(false); $('#conversation-content').scrollTop($( "#conversation-content")[0].scrollHeight); }); },