2014-11-13 22:36:09 +00:00
|
|
|
/* vim: ts=4:sw=4:expandtab
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2014-09-01 00:58:36 +00:00
|
|
|
var Whisper = Whisper || {};
|
|
|
|
|
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
Whisper.NewConversationView = Backbone.View.extend({
|
|
|
|
className: 'conversation',
|
|
|
|
initialize: function() {
|
|
|
|
this.template = $('#new-message-form').html();
|
|
|
|
Mustache.parse(this.template);
|
2014-11-17 00:01:28 +00:00
|
|
|
this.$el.html($(Mustache.render(this.template)));
|
2015-01-14 23:59:40 +00:00
|
|
|
this.input = new Whisper.PhoneInputView({el: this.$el.find('div.phone-number-input')});
|
2014-11-04 01:51:49 +00:00
|
|
|
this.fileInput = new Whisper.FileInputView({el: this.$el.find('.attachments')});
|
2015-01-15 21:11:45 +00:00
|
|
|
this.$el.find('div.phone-number-input').append(this.input.render().el);
|
2014-09-01 00:58:36 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
events: {
|
|
|
|
'submit .send': 'send',
|
|
|
|
'close': 'remove'
|
|
|
|
},
|
|
|
|
|
|
|
|
send: function(e) {
|
|
|
|
e.preventDefault();
|
2015-01-14 23:59:40 +00:00
|
|
|
var number = this.input.validateNumber();
|
2014-10-22 18:57:12 +00:00
|
|
|
if (number) {
|
2014-11-17 00:01:28 +00:00
|
|
|
var convo = this.collection.findOrCreateForRecipient(number);
|
2014-10-22 18:57:12 +00:00
|
|
|
var message_input = this.$el.find('input.send-message');
|
2014-11-04 01:51:49 +00:00
|
|
|
var message = message_input.val();
|
|
|
|
if (message.length > 0 || this.fileInput.hasFiles()) {
|
|
|
|
this.fileInput.getFiles().then(function(attachments) {
|
2014-11-13 22:35:37 +00:00
|
|
|
convo.sendMessage(message, attachments);
|
2014-11-04 01:51:49 +00:00
|
|
|
});
|
|
|
|
message_input.val("");
|
|
|
|
}
|
2014-10-22 18:57:12 +00:00
|
|
|
this.remove();
|
2015-01-18 06:07:50 +00:00
|
|
|
convo.trigger('open');
|
2014-10-22 18:57:12 +00:00
|
|
|
}
|
2014-09-01 00:58:36 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
})();
|