Clean up inbox/compose view rendering and swapping

Templatize the inbox view and use the same pattern for in-window view
switching as is now used with the conversation/message detail views.
This means doing more with markup and less jquery manipulation of
individual subelements of the inbox view.
pull/749/head
lilia 10 years ago
parent fd6e2954f7
commit a72ea7966d

@ -13,21 +13,15 @@
<link href="/stylesheets/manifest.css" rel="stylesheet" type="text/css" /> <link href="/stylesheets/manifest.css" rel="stylesheet" type="text/css" />
</head> </head>
<body class='signal index'> <body class='signal index'>
<script type="text/x-tmpl-mustache" id="inbox">
<div class='title-bar' id='header'> <div class='title-bar' id='header'>
<div class='new-conversation-title hide'>
<button class='back'></button>
<span class='title-text'>New Message</span>
</div>
<div class='socket-status'></div> <div class='socket-status'></div>
</div> </div>
<div class='notifications'>
<div class='notification info'>
</div>
</div>
<div id='gutter' class='gutter'> <div id='gutter' class='gutter'>
<div id='contacts'></div> <div id='contacts'></div>
<span class='fab'></span> <span class='fab'></span>
</div> </div>
</script>
<script type="text/x-tmpl-mustache" id="phone-number"> <script type="text/x-tmpl-mustache" id="phone-number">
<div class="phone-input-form"> <div class="phone-input-form">
<div class="number-container"> <div class="number-container">
@ -54,6 +48,11 @@
</div> </div>
</script> </script>
<script type='text/x-tmpl-mustache' id='new-conversation'> <script type='text/x-tmpl-mustache' id='new-conversation'>
<div class='title-bar' id='header'>
<button class='back'></button>
<span class='title-text'>New Message</span>
</div>
<div id='gutter' class='gutter'>
<div class='new-group-update-form clearfix'> <div class='new-group-update-form clearfix'>
<div class='group-avatar'> <div class='group-avatar'>
<div class='paperclip'></div> <div class='paperclip'></div>
@ -72,6 +71,7 @@
<div class='new-contact contact'></div> <div class='new-contact contact'></div>
<div class='contacts'></div> <div class='contacts'></div>
</div> </div>
</div>
</script> </script>
<script type='text/x-tmpl-mustache' id='attachment-preview'> <script type='text/x-tmpl-mustache' id='attachment-preview'>
<img src="{{ source }}" class="preview" /> <img src="{{ source }}" class="preview" />

@ -22,7 +22,7 @@
if (textsecure.storage.getUnencrypted("number_id") === undefined) { if (textsecure.storage.getUnencrypted("number_id") === undefined) {
window.location = '/options.html'; window.location = '/options.html';
} else { } else {
new Whisper.InboxView({el: $('body')}); new Whisper.InboxView().$el.prependTo($('body'));
textsecure.storage.putUnencrypted("unreadCount", 0); textsecure.storage.putUnencrypted("unreadCount", 0);
extension.navigator.setBadgeText(""); extension.navigator.setBadgeText("");
} }

@ -53,18 +53,18 @@
} }
}); });
Whisper.InboxView = Backbone.View.extend({ Whisper.InboxView = Whisper.View.extend({
template: $('#inbox').html(),
initialize: function () { initialize: function () {
this.$gutter = $('#gutter'); this.render();
this.$contacts = $('#contacts');
this.$fab = this.$el.find('.fab');
this.$back = this.$el.find('.new-conversation-title');
this.newConversationView = new Whisper.NewConversationView(); this.newConversationView = new Whisper.NewConversationView();
this.newConversationView.$el.hide().appendTo(this.$gutter); this.newConversationView.$el.hide();
this.listenTo(this.newConversationView, 'open',
this.openConversation.bind(this, null));
this.inbox = new Whisper.ConversationListView({ this.inbox = new Whisper.ConversationListView({
el : this.$contacts, el : this.$el.find('#contacts'),
collection : bg.inbox collection : bg.inbox
}).render(); }).render();
@ -75,34 +75,24 @@
}.bind(this)); }.bind(this));
}, },
events: { events: {
'keyup': 'keyup',
'click .back': 'hideCompose',
'click .fab': 'showCompose', 'click .fab': 'showCompose',
'select #contacts .contact': 'openConversation', 'select .contact': 'openConversation',
'open .new-conversation': 'openConversation'
}, },
openConversation: function(e, data) { openConversation: function(e, data) {
bg.openConversation(data.modelId); bg.openConversation(data.modelId);
this.hideCompose(); this.hideCompose();
}, },
showCompose: function() { showCompose: function() {
this.$fab.hide();
this.$contacts.hide();
this.newConversationView.reset(); this.newConversationView.reset();
this.$el.hide();
this.newConversationView.$el.insertAfter(this.$el);
this.newConversationView.$el.show(); this.newConversationView.$el.show();
this.newConversationView.$input.focus(); this.newConversationView.$input.focus();
this.$back.show(); this.listenToOnce(this.newConversationView, 'back', this.hideCompose);
}, },
hideCompose: function() { hideCompose: function() {
this.newConversationView.$el.hide(); this.newConversationView.$el.hide();
this.$contacts.show(); this.$el.show();
this.$fab.show();
this.$back.hide();
},
keyup: function(e) {
if (e.keyCode === 27) {
this.hideCompose();
}
} }
}); });

@ -101,7 +101,19 @@
'select .new-contact': 'addNewRecipient', 'select .new-contact': 'addNewRecipient',
'select .contacts': 'addRecipient', 'select .contacts': 'addRecipient',
'remove .recipient': 'removeRecipient', 'remove .recipient': 'removeRecipient',
'click .create': 'create' 'click .create': 'create',
'click .back': 'goBack',
'keyup': 'keyup'
},
keyup: function(e) {
if (e.keyCode === 27) {
this.goBack();
}
},
goBack: function() {
this.trigger('back');
}, },
initNewContact: function() { initNewContact: function() {
@ -180,12 +192,12 @@
type: 'private' type: 'private'
}); });
conversation.fetch().then(function() { conversation.fetch().then(function() {
this.$el.trigger('open', { modelId: conversation.id }); this.trigger('open', { modelId: conversation.id });
}.bind(this)).fail(function() { }.bind(this)).fail(function() {
var saved = conversation.save(); // false or indexedDBRequest var saved = conversation.save(); // false or indexedDBRequest
if (saved) { if (saved) {
saved.then(function() { saved.then(function() {
this.$el.trigger('open', { modelId: conversation.id }); this.trigger('open', { modelId: conversation.id });
}.bind(this)); }.bind(this));
} }
}.bind(this)); }.bind(this));
@ -210,7 +222,7 @@
var id = getString(groupId); var id = getString(groupId);
var group = new Whisper.Conversation(attributes); var group = new Whisper.Conversation(attributes);
group.save({ id: id, groupId: id }).then(function() { group.save({ id: id, groupId: id }).then(function() {
this.$el.trigger('open', {modelId: id}); this.trigger('open', {modelId: id});
}.bind(this)); }.bind(this));
}.bind(this)); }.bind(this));
}.bind(this)); }.bind(this));

Loading…
Cancel
Save