Improve typeahead contact selector experience
Store and match on various phone number formats. Still not perfect, as occasionally all the models are returned for a non-matching query.
This commit is contained in:
parent
acc2c6f536
commit
d435ff003b
3 changed files with 21 additions and 15 deletions
|
@ -33,6 +33,14 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
splitCountryCode: function(number) {
|
||||||
|
var parsedNumber = libphonenumber.parse(number);
|
||||||
|
return {
|
||||||
|
country_code: parsedNumber.values_[1],
|
||||||
|
national_number: parsedNumber.values_[2]
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
getCountryCode: function(regionCode) {
|
getCountryCode: function(regionCode) {
|
||||||
var cc = libphonenumber.getCountryCodeForRegion(regionCode);
|
var cc = libphonenumber.getCountryCodeForRegion(regionCode);
|
||||||
return (cc != 0) ? cc : "";
|
return (cc != 0) ? cc : "";
|
||||||
|
|
|
@ -39,13 +39,15 @@
|
||||||
var missing = _.filter(required, function(attr) { return !attributes[attr]; });
|
var missing = _.filter(required, function(attr) { return !attributes[attr]; });
|
||||||
if (missing.length) { return "Conversation must have " + missing; }
|
if (missing.length) { return "Conversation must have " + missing; }
|
||||||
|
|
||||||
|
// hack
|
||||||
if (this.get('type') === 'private') {
|
if (this.get('type') === 'private') {
|
||||||
var number = libphonenumber.util.verifyNumber(id);
|
this.id = libphonenumber.util.verifyNumber(this.id);
|
||||||
|
var number = libphonenumber.util.splitCountryCode(this.id);
|
||||||
|
|
||||||
this.set({
|
this.set({
|
||||||
id: number,
|
e164_number: this.id,
|
||||||
international_number: libphonenumber.format(number, libphonenumber.PhoneNumberFormat.INTERNATIONAL),
|
national_number: '' + number.national_number,
|
||||||
national_number: libphonenumber.format(number, libphonenumber.PhoneNumberFormat.NATIONAL)
|
international_number: '' + number.country_code + number.national_number
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,19 +19,15 @@ var Whisper = Whisper || {};
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var typeahead = Backbone.TypeaheadCollection.extend({
|
var typeahead = Backbone.TypeaheadCollection.extend({
|
||||||
typeaheadAttributes: ['name'],
|
typeaheadAttributes: [
|
||||||
|
'name',
|
||||||
|
'e164_number',
|
||||||
|
'national_number',
|
||||||
|
'international_number'
|
||||||
|
],
|
||||||
database: Whisper.Database,
|
database: Whisper.Database,
|
||||||
storeName: 'conversations',
|
storeName: 'conversations',
|
||||||
model: Whisper.Conversation,
|
model: Whisper.Conversation
|
||||||
|
|
||||||
_tokenize: function(s) {
|
|
||||||
s = $.trim(s);
|
|
||||||
if (s.length === 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return s.toLowerCase().split(/[\s\-_+]+/);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Whisper.NewConversationView = Backbone.View.extend({
|
Whisper.NewConversationView = Backbone.View.extend({
|
||||||
|
|
Loading…
Reference in a new issue