2018-07-07 00:48:14 +00:00
|
|
|
/* global Whisper, _ */
|
|
|
|
|
|
|
|
/* eslint-disable more/no-then */
|
|
|
|
|
|
|
|
// eslint-disable-next-line func-names
|
2018-04-27 21:25:04 +00:00
|
|
|
(function() {
|
|
|
|
'use strict';
|
2018-07-07 00:48:14 +00:00
|
|
|
|
2018-04-27 21:25:04 +00:00
|
|
|
window.Whisper = window.Whisper || {};
|
2015-01-13 23:27:18 +00:00
|
|
|
|
2018-04-27 21:25:04 +00:00
|
|
|
Whisper.NewGroupUpdateView = Whisper.View.extend({
|
|
|
|
tagName: 'div',
|
|
|
|
className: 'new-group-update',
|
|
|
|
templateName: 'new-group-update',
|
2018-07-07 00:48:14 +00:00
|
|
|
initialize(options) {
|
2018-04-27 21:25:04 +00:00
|
|
|
this.render();
|
|
|
|
this.avatarInput = new Whisper.FileInputView({
|
|
|
|
el: this.$('.group-avatar'),
|
|
|
|
window: options.window,
|
|
|
|
});
|
2015-01-13 23:27:18 +00:00
|
|
|
|
2018-04-27 21:25:04 +00:00
|
|
|
this.recipients_view = new Whisper.RecipientsInputView();
|
2018-07-07 00:48:14 +00:00
|
|
|
this.listenTo(this.recipients_view.typeahead, 'sync', () =>
|
|
|
|
this.model.contactCollection.models.forEach(model => {
|
|
|
|
if (this.recipients_view.typeahead.get(model)) {
|
|
|
|
this.recipients_view.typeahead.remove(model);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
2018-04-27 21:25:04 +00:00
|
|
|
this.recipients_view.$el.insertBefore(this.$('.container'));
|
2015-06-09 23:10:39 +00:00
|
|
|
|
2018-04-27 21:25:04 +00:00
|
|
|
this.member_list_view = new Whisper.ContactListView({
|
|
|
|
collection: this.model.contactCollection,
|
|
|
|
className: 'members',
|
|
|
|
});
|
|
|
|
this.member_list_view.render();
|
|
|
|
this.$('.scrollable').append(this.member_list_view.el);
|
|
|
|
},
|
|
|
|
events: {
|
|
|
|
'click .back': 'goBack',
|
|
|
|
'click .send': 'send',
|
|
|
|
'focusin input.search': 'showResults',
|
|
|
|
'focusout input.search': 'hideResults',
|
|
|
|
},
|
2018-07-07 00:48:14 +00:00
|
|
|
hideResults() {
|
2018-04-27 21:25:04 +00:00
|
|
|
this.$('.results').hide();
|
|
|
|
},
|
2018-07-07 00:48:14 +00:00
|
|
|
showResults() {
|
2018-04-27 21:25:04 +00:00
|
|
|
this.$('.results').show();
|
|
|
|
},
|
2018-07-07 00:48:14 +00:00
|
|
|
goBack() {
|
2018-04-27 21:25:04 +00:00
|
|
|
this.trigger('back');
|
|
|
|
},
|
2018-07-07 00:48:14 +00:00
|
|
|
render_attributes() {
|
2018-04-27 21:25:04 +00:00
|
|
|
return {
|
|
|
|
name: this.model.getTitle(),
|
|
|
|
avatar: this.model.getAvatar(),
|
|
|
|
};
|
|
|
|
},
|
2018-07-07 00:48:14 +00:00
|
|
|
send() {
|
|
|
|
return this.avatarInput.getThumbnail().then(avatarFile => {
|
|
|
|
const now = Date.now();
|
|
|
|
const attrs = {
|
|
|
|
timestamp: now,
|
|
|
|
active_at: now,
|
|
|
|
name: this.$('.name').val(),
|
|
|
|
members: _.union(
|
|
|
|
this.model.get('members'),
|
|
|
|
this.recipients_view.recipients.pluck('id')
|
|
|
|
),
|
|
|
|
};
|
|
|
|
if (avatarFile) {
|
|
|
|
attrs.avatar = avatarFile;
|
|
|
|
}
|
|
|
|
this.model.set(attrs);
|
|
|
|
const groupUpdate = this.model.changed;
|
|
|
|
this.model.save();
|
2015-07-14 20:39:24 +00:00
|
|
|
|
2018-07-07 00:48:14 +00:00
|
|
|
if (groupUpdate.avatar) {
|
|
|
|
this.model.trigger('change:avatar');
|
|
|
|
}
|
2015-07-14 20:39:24 +00:00
|
|
|
|
2018-07-07 00:48:14 +00:00
|
|
|
this.model.updateGroup(groupUpdate);
|
|
|
|
this.goBack();
|
|
|
|
});
|
2018-04-27 21:25:04 +00:00
|
|
|
},
|
|
|
|
});
|
2015-01-13 23:27:18 +00:00
|
|
|
})();
|