From a00632c7285e8f6d62d2e4729bbaa52c6f771c60 Mon Sep 17 00:00:00 2001 From: lilia Date: Wed, 28 Jan 2015 18:22:41 -1000 Subject: [PATCH] Hook up group creation flow UI Checkboxes add and remove members as well as exposing the group update ui. The conversation window is opened after saving the group. --- index.html | 2 +- js/views/conversation_list_item_view.js | 5 ++- js/views/inbox_view.js | 1 + js/views/new_conversation_view.js | 49 ++++++++++++++++++++++++- js/views/new_group_update_view.js | 12 +++--- 5 files changed, 60 insertions(+), 9 deletions(-) diff --git a/index.html b/index.html index aa96c46d..ca95b19c 100644 --- a/index.html +++ b/index.html @@ -59,7 +59,7 @@
- +
diff --git a/js/views/conversation_list_item_view.js b/js/views/conversation_list_item_view.js index 72db8975..cd0fa2d5 100644 --- a/js/views/conversation_list_item_view.js +++ b/js/views/conversation_list_item_view.js @@ -43,7 +43,10 @@ var Whisper = Whisper || {}; checkbox: function(e) { e.stopPropagation(); - this.$el.trigger('checkbox', {modelId: this.model.id}); + this.$el.trigger('checkbox', { + modelId: this.model.id, + checked: e.target.checked + }); }, render: function() { diff --git a/js/views/inbox_view.js b/js/views/inbox_view.js index 9cfb3585..caf6280e 100644 --- a/js/views/inbox_view.js +++ b/js/views/inbox_view.js @@ -52,6 +52,7 @@ 'click .fab': 'showCompose', 'open #contacts': 'openConversation', 'open .contacts': 'openConversation', + 'open .new-conversation': 'openConversation', 'open .new-contact': 'createConversation', }, openConversation: function(e, data) { diff --git a/js/views/new_conversation_view.js b/js/views/new_conversation_view.js index e4da52a6..39bbd889 100644 --- a/js/views/new_conversation_view.js +++ b/js/views/new_conversation_view.js @@ -30,7 +30,7 @@ var Whisper = Whisper || {}; return null; } - return s.toLowerCase().split(/[\s\-_+]+/) + return s.toLowerCase().split(/[\s\-_+]+/); } }); @@ -41,6 +41,7 @@ var Whisper = Whisper || {}; Mustache.parse(this.template); this.$el.html($(Mustache.render(this.template))); this.$input = this.$el.find('input.new-message'); + this.$group_update = this.$el.find('.new-group-update-form'); this.typeahead_collection = new typeahead(); this.typeahead_view = new Whisper.ConversationListView({ @@ -61,18 +62,62 @@ var Whisper = Whisper || {}; type: 'private' }) }).render(); + + this.newGroupUpdateView = new Whisper.NewGroupUpdateView({ + model: new Whisper.Conversation({ type: 'group' }), + el: this.$group_update + }); + this.group_members = new Whisper.ConversationCollection(); this.$el.find('.new-contact').append(this.new_contact.el); }, events: { 'change input.new-message': 'filterContacts', - 'keyup input.new-message': 'filterContacts' + 'keyup input.new-message': 'filterContacts', + 'checkbox .contact': 'updateGroup', + 'click .create-group': 'createGroup' + }, + + updateGroup: function(e, data) { + this.$input.focus(); + if (data.checked) { + this.group_members.add({id: data.modelId}); + } else { + this.group_members.remove({id: data.modelId}); + } + this.group_members + if (this.group_members.length) { + this.$group_update.show(); + } else { + this.$group_update.hide(); + } + }, + + createGroup: function() { + return this.newGroupUpdateView.avatarInput.getFiles().then(function(avatarFiles) { + var attributes = { + type: 'group', + name: this.$el.find('.new-group-update-form .name').val(), + avatar: avatarFiles[0], + members: this.group_members.pluck('id') + }; + return textsecure.messaging.createGroup( + attributes.members, attributes.name, attributes.avatar + ).then(function(groupId) { + var id = getString(groupId); + var group = new Whisper.Conversation(attributes); + group.save({ id: id, groupId: id }).then(function() { + this.$el.trigger('open', {modelId: id}); + }.bind(this)); + }.bind(this)); + }.bind(this)); }, reset: function() { this.new_contact.$el.hide(); this.$input.val('').focus(); this.typeahead_view.collection.reset(this.typeahead_collection.models); + this.group_members.reset([]); }, filterContacts: function() { diff --git a/js/views/new_group_update_view.js b/js/views/new_group_update_view.js index a8b332ed..40720c8d 100644 --- a/js/views/new_group_update_view.js +++ b/js/views/new_group_update_view.js @@ -22,11 +22,13 @@ tagName: "div", className: "new-group-update-form", initialize: function(options) { - this.template = $('#new-group-update-form').html(); - Mustache.parse(this.template); - this.$el.html( - Mustache.render(this.template, this.model.attributes) - ); + if (this.$el.html().length === 0) { + this.template = $('#new-group-update-form').html(); + Mustache.parse(this.template); + this.$el.html( + Mustache.render(this.template, this.model.attributes) + ); + } this.avatarInput = new Whisper.FileInputView({ el: this.$el.find('.group-avatar') });