Add hint for users with no groups or contacts

If you have no contacts or groups, display a hint about phone numbers.

// FREEBIE
This commit is contained in:
lilia 2015-11-27 17:34:02 -08:00
parent e9949152bb
commit 891a5e54ad
6 changed files with 96 additions and 6 deletions

View file

@ -35,6 +35,7 @@
if (this.maybeNumber(query)) {
this.new_contact_view.model.set('id', query);
this.new_contact_view.render().$el.show();
this.hideHints();
} else {
this.new_contact_view.$el.hide();
}
@ -82,11 +83,16 @@
},
resetTypeahead: function() {
this.hideHints();
this.new_contact_view.$el.hide();
this.$input.val('').focus();
if (this.showAllContacts) {
this.typeahead.fetchAlphabetical().then(function() {
this.typeahead_view.collection.reset(this.typeahead.models);
if (this.typeahead.length > 0) {
this.typeahead_view.collection.reset(this.typeahead.models);
} else {
this.showHints();
}
}.bind(this));
this.trigger('show');
} else {
@ -95,6 +101,24 @@
}
},
showHints: function() {
if (!this.hintView) {
this.hintView = new Whisper.HintView({
className: 'contact placeholder',
content: "Enter a phone number to add a contact."
}).render();
this.hintView.$el.insertAfter(this.$input);
}
this.hintView.$el.show();
},
hideHints: function() {
if (this.hintView) {
this.hintView.remove();
this.hintView = null;
}
},
maybeNumber: function(number) {
return number.match(/^\+?[0-9]*$/);
}

View file

@ -6,7 +6,12 @@
window.Whisper = window.Whisper || {};
Whisper.HintView = Whisper.View.extend({
className: 'conversation placeholder',
templateName: 'hint',
initialize: function(options) {
this.content = options.content;
},
render_attributes: function() {
return { content: this.content };
}
});
})();

View file

@ -102,7 +102,10 @@
this.inboxListView.$el.hide();
});
this.hintView = new Whisper.HintView();
this.hintView = new Whisper.HintView({
className: 'conversation placeholder',
content: "Select a contact or group to start chatting."
});
if (inboxCollection.length === 0) {
this.hintView.render();
this.hintView.$el.prependTo(this.$('.conversation-stack'));
@ -139,6 +142,7 @@
},
hideHints: function() {
this.hintView.remove();
this.searchView.hideHints();
},
openConversation: function(e, conversation) {
this.hideHints();