2014-08-11 08:34:29 +02:00
|
|
|
var Whisper = Whisper || {};
|
|
|
|
|
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
Whisper.GroupRecipientsInputView = Backbone.View.extend({
|
|
|
|
initialize: function() {
|
|
|
|
this.$el.tagsinput({ tagClass: this.tagClass });
|
|
|
|
},
|
|
|
|
|
|
|
|
tagClass: function(item) {
|
|
|
|
try {
|
2014-10-12 02:19:16 +02:00
|
|
|
if (libphonenumber.util.verifyNumber(item)) {
|
2014-08-11 08:34:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} catch(ex) {}
|
|
|
|
return 'error';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Whisper.NewGroupView = Backbone.View.extend({
|
2014-10-15 02:01:09 +02:00
|
|
|
className: 'conversation',
|
2014-08-11 08:34:29 +02:00
|
|
|
initialize: function() {
|
|
|
|
this.template = $('#new-group-form').html();
|
|
|
|
Mustache.parse(this.template);
|
2014-11-17 01:01:28 +01:00
|
|
|
this.$el.html($(Mustache.render(this.template)));
|
2014-10-15 00:24:50 +02:00
|
|
|
this.input = this.$el.find('input.number');
|
2014-08-11 08:34:29 +02:00
|
|
|
new Whisper.GroupRecipientsInputView({el: this.$el.find('input.numbers')}).$el.appendTo(this.$el);
|
2015-01-11 12:27:22 +01:00
|
|
|
this.fileInput = new Whisper.FileInputView({el: this.$el.find('.attachments')});
|
|
|
|
this.avatarInput = new Whisper.FileInputView({el: this.$el.find('.group-avatar')});
|
2014-08-11 08:34:29 +02:00
|
|
|
},
|
2015-01-11 12:27:22 +01:00
|
|
|
|
2014-08-11 08:34:29 +02:00
|
|
|
events: {
|
2014-10-15 02:01:09 +02:00
|
|
|
'submit .send': 'send',
|
|
|
|
'close': 'remove'
|
2014-08-11 08:34:29 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
send: function(e) {
|
2014-10-15 00:24:50 +02:00
|
|
|
e.preventDefault();
|
2014-08-11 08:34:29 +02:00
|
|
|
var numbers = this.$el.find('input.numbers').val().split(',');
|
|
|
|
var name = this.$el.find('input.name').val();
|
2015-01-11 12:27:22 +01:00
|
|
|
var message_input = this.$el.find('input.send-message');
|
|
|
|
var message = message_input.val();
|
2014-10-16 23:14:00 +02:00
|
|
|
var view = this;
|
2015-01-11 12:27:22 +01:00
|
|
|
if (message.length > 0 || this.fileInput.hasFiles()) {
|
|
|
|
this.avatarInput.getFiles().then(function(avatar_files) {
|
|
|
|
view.collection.createGroup(numbers, name, avatar_files[0]).then(function(convo){
|
|
|
|
view.fileInput.getFiles().then(function(attachments) {
|
|
|
|
convo.sendMessage(view.$el.find('input.send-message').val());
|
|
|
|
});
|
|
|
|
convo.trigger('render');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
this.remove();
|
2014-08-11 08:34:29 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
})();
|