Move new convo stuff to its own file

This commit is contained in:
lilia 2014-08-31 17:58:36 -07:00
parent 9af18ce6ae
commit b9640a54bd
3 changed files with 62 additions and 56 deletions

View file

@ -153,6 +153,7 @@
<script type="text/javascript" src="js/views/conversation_list_item_view.js"></script>
<script type="text/javascript" src="js/views/conversation_list_view.js"></script>
<script type="text/javascript" src="js/views/conversation_view.js"></script>
<script type="text/javascript" src="js/views/new_conversation_view.js"></script>
<script type="text/javascript" src="js/views/new_message_button.js"></script>
<script type="text/javascript" src="js/popup.js"></script>
</body>

View file

@ -0,0 +1,61 @@
var Whisper = Whisper || {};
(function () {
'use strict';
var MessageRecipientInputView = Backbone.View.extend({
events: {
'change': 'verifyNumber',
'focus' : 'removeError'
},
removeError: function() {
this.$el.removeClass('error');
},
verifyNumber: function(item) {
try {
if (textsecure.utils.verifyNumber(this.$el.val())) {
this.removeError();
return;
}
} catch(ex) { console.log(ex); }
this.$el.addClass('error');
}
});
Whisper.NewConversationView = Backbone.View.extend({
className: 'conversation',
initialize: function() {
this.template = $('#new-message-form').html();
Mustache.parse(this.template);
this.render();
this.input = this.$el.find('input.number');
new MessageRecipientInputView({el: this.input});
},
events: {
'submit .send': 'send',
'close': 'remove'
},
send: function(e) {
e.preventDefault();
var number = this.input.val();
try {
if (textsecure.utils.verifyNumber(number)) {
var thread = Whisper.Threads.findOrCreateForRecipient(number);
var message_input = this.$el.find('input.send-message');
thread.sendMessage(message_input.val());
this.remove();
}
} catch(ex) {}
},
render: function() {
this.$el.html(Mustache.render(this.template));
Whisper.Layout.setContent(this.$el.show());
return this;
}
});
})();

View file

@ -43,62 +43,6 @@ var Whisper = Whisper || {};
}
});
Whisper.MessageRecipientInputView = Backbone.View.extend({
events: {
'change': 'verifyNumber',
'focus' : 'removeError'
},
removeError: function() {
this.$el.removeClass('error');
},
verifyNumber: function(item) {
try {
if (textsecure.utils.verifyNumber(this.$el.val())) {
this.removeError();
return;
}
} catch(ex) { console.log(ex); }
this.$el.addClass('error');
}
});
Whisper.NewConversationView = Backbone.View.extend({
className: 'conversation',
initialize: function() {
this.template = $('#new-message-form').html();
Mustache.parse(this.template);
this.render();
this.input = this.$el.find('input.number');
new Whisper.MessageRecipientInputView({el: this.input});
},
events: {
'submit .send': 'send',
'close': 'remove'
},
send: function(e) {
e.preventDefault();
var number = this.input.val();
try {
if (textsecure.utils.verifyNumber(number)) {
var thread = Whisper.Threads.findOrCreateForRecipient(number);
var message_input = this.$el.find('input.send-message');
thread.sendMessage(message_input.val());
this.remove();
}
} catch(ex) {}
},
render: function() {
this.$el.html(Mustache.render(this.template));
Whisper.Layout.setContent(this.$el.show());
return this;
}
});
Whisper.Header = Backbone.View.extend({
events: {
'click #new-message': 'new_message',