Destroy all globals

Well, not *all* globals..
This commit is contained in:
lilia 2014-11-16 16:01:28 -08:00
parent c0681beca7
commit fd3a72d435
7 changed files with 30 additions and 40 deletions

View file

@ -181,6 +181,4 @@
}));
}
});
Whisper.Conversations = new Whisper.ConversationCollection();
})();

View file

@ -28,10 +28,6 @@
if (missing.length) {
console.log("Message missing attributes: " + missing);
}
},
conversation: function() {
return Whisper.Conversations.get(this.get('conversationId'));
}
});

View file

@ -7,7 +7,6 @@ var Whisper = Whisper || {};
tagName: 'div',
id: 'contacts',
itemView: Whisper.ConversationListItemView,
collection: Whisper.Conversations,
events: {
'click .contact': 'select',

View file

@ -14,9 +14,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
(function () {
'use strict';
'use strict';
window.Whisper = window.Whisper || {};
window.Whisper = window.Whisper || {};
Whisper.InboxView = Backbone.View.extend({
initialize: function () {
@ -27,16 +27,21 @@
window.addEventListener('resize', this.resize.bind(this));
this.conversations = new Whisper.ConversationCollection();
new Whisper.ConversationListView({el: $('#contacts'), collection: Whisper.Conversations});
Whisper.Conversations.fetch({reset: true}).then(function() {
if (Whisper.Conversations.length) {
Whisper.Conversations.at(0).trigger('render');
}
new Whisper.ConversationListView({
el : $('#contacts'),
collection : this.conversations
});
this.conversations.fetch({reset: true}).then(function() {
if (this.conversations.length) {
this.conversations.at(0).trigger('render');
}
}.bind(this));
extension.onMessage('message', function(message) {
Whisper.Conversations.fetch({id: message.conversationId}).then(function() {
Whisper.Conversations.get(message.conversationId).fetchMessages();
});
this.conversations.fetch({id: message.conversationId}).then(function() {
this.conversations.get(message.conversationId).fetchMessages();
}.bind(this));
}.bind(this));
},
@ -44,18 +49,21 @@
'click #new-message': 'new_message',
'click #new-group': 'new_group'
},
new_message: function (e) {
e.preventDefault();
$('.conversation').hide().trigger('close'); // detach any existing conversation views
this.view = new Whisper.NewConversationView();
//todo: less new
this.view = new Whisper.NewConversationView({
collection: this.conversations
});
this.setContent(this.view.render().$el.show());
},
new_group: function (e) {
e.preventDefault();
$('.conversation').trigger('close'); // detach any existing conversation views
new Whisper.NewGroupView();
var view = new Whisper.NewGroupView({
collection: this.conversations
});
this.setContent(view.render().$el.show());
},
resize: function (e) {
var windowheight = window.innerHeight,

View file

@ -53,7 +53,7 @@ var Whisper = Whisper || {};
initialize: function() {
this.template = $('#new-message-form').html();
Mustache.parse(this.template);
this.render();
this.$el.html($(Mustache.render(this.template)));
this.input = new MessageRecipientInputView({el: this.$el.find('input.number')});
this.fileInput = new Whisper.FileInputView({el: this.$el.find('.attachments')});
},
@ -67,7 +67,7 @@ var Whisper = Whisper || {};
e.preventDefault();
var number = this.input.verifyNumber();
if (number) {
var convo = Whisper.Conversations.findOrCreateForRecipient(number);
var convo = this.collection.findOrCreateForRecipient(number);
var message_input = this.$el.find('input.send-message');
var message = message_input.val();
if (message.length > 0 || this.fileInput.hasFiles()) {
@ -79,12 +79,6 @@ var Whisper = Whisper || {};
this.remove();
convo.trigger('render');
}
},
render: function() {
this.$el.html(Mustache.render(this.template));
Whisper.Layout.setContent(this.$el.show());
return this;
}
});

View file

@ -23,7 +23,7 @@ var Whisper = Whisper || {};
initialize: function() {
this.template = $('#new-group-form').html();
Mustache.parse(this.template);
this.render();
this.$el.html($(Mustache.render(this.template)));
this.input = this.$el.find('input.number');
new Whisper.GroupRecipientsInputView({el: this.$el.find('input.numbers')}).$el.appendTo(this.$el);
},
@ -37,17 +37,11 @@ var Whisper = Whisper || {};
var numbers = this.$el.find('input.numbers').val().split(',');
var name = this.$el.find('input.name').val();
var view = this;
Whisper.Conversations.createGroup(numbers, name).then(function(convo){
this.collection.createGroup(numbers, name).then(function(convo){
convo.sendMessage(view.$el.find('input.send-message').val());
view.remove();
convo.trigger('render');
});
},
render: function() {
this.$el.prepend($(Mustache.render(this.template)));
Whisper.Layout.setContent(this.$el.show());
return this;
}
});

View file

@ -1,9 +1,10 @@
describe('MessageView', function() {
var conversations = new Whisper.ConversationCollection();
before(function(done) {
Whisper.Conversations.fetch().then(done);
conversations.fetch().then(done);
});
var convo = Whisper.Conversations.add({id: 'foo'});
var convo = conversations.add({id: 'foo'});
var message = convo.messages().add({
conversationId: convo.id,
body: 'hello world',