43a44793c5
Also removed all hints of previous linters
88 lines
2.3 KiB
JavaScript
88 lines
2.3 KiB
JavaScript
/* global Whisper, _ */
|
|
|
|
/* eslint-disable more/no-then */
|
|
|
|
// eslint-disable-next-line func-names
|
|
(function() {
|
|
'use strict';
|
|
|
|
window.Whisper = window.Whisper || {};
|
|
|
|
Whisper.NewGroupUpdateView = Whisper.View.extend({
|
|
tagName: 'div',
|
|
className: 'new-group-update',
|
|
templateName: 'new-group-update',
|
|
initialize(options) {
|
|
this.render();
|
|
this.avatarInput = new Whisper.FileInputView({
|
|
el: this.$('.group-avatar'),
|
|
window: options.window,
|
|
});
|
|
|
|
this.recipients_view = new Whisper.RecipientsInputView();
|
|
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);
|
|
}
|
|
})
|
|
);
|
|
this.recipients_view.$el.insertBefore(this.$('.container'));
|
|
|
|
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',
|
|
},
|
|
hideResults() {
|
|
this.$('.results').hide();
|
|
},
|
|
showResults() {
|
|
this.$('.results').show();
|
|
},
|
|
goBack() {
|
|
this.trigger('back');
|
|
},
|
|
render_attributes() {
|
|
return {
|
|
name: this.model.getTitle(),
|
|
avatar: this.model.getAvatar(),
|
|
};
|
|
},
|
|
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();
|
|
|
|
if (groupUpdate.avatar) {
|
|
this.model.trigger('change:avatar');
|
|
}
|
|
|
|
this.model.updateGroup(groupUpdate);
|
|
this.goBack();
|
|
});
|
|
},
|
|
});
|
|
})();
|