Format phone numbers before saving conversations

Saving the national and internation versions of the number lets us use
those attributes in a typeahead collection.
This commit is contained in:
lilia 2015-01-28 02:19:58 -10:00
parent ed928aa4e3
commit e05405e832
1 changed files with 14 additions and 3 deletions

View File

@ -35,9 +35,20 @@
},
validate: function(attributes, options) {
var required = ['type', 'timestamp'];
var missing = _.filter(required, function(attr) { return !attributes[attr]; });
if (missing.length) { return "Conversation must have " + missing; }
var required = ['type', 'timestamp'];
var missing = _.filter(required, function(attr) { return !attributes[attr]; });
if (missing.length) { return "Conversation must have " + missing; }
if (this.get('type') === 'private') {
var number = libphonenumber.util.verifyNumber(id);
this.set({
id: number,
international_number: libphonenumber.format(number, libphonenumber.PhoneNumberFormat.INTERNATIONAL),
national_number: libphonenumber.format(number, libphonenumber.PhoneNumberFormat.NATIONAL)
});
}
},
sendMessage: function(body, attachments) {