(js) Fix handling of new contact categories

Fixes #175
This commit is contained in:
Francis Lachapelle
2016-01-14 15:52:04 -05:00
parent 667e6dff7c
commit 3d4311194c
2 changed files with 17 additions and 13 deletions
@@ -93,8 +93,10 @@
*/
Card.filterCategories = function(query) {
var re = new RegExp(query, 'i');
return _.filter(Card.$categories, function(category) {
return _.map(_.filter(Card.$categories, function(category) {
return category.search(re) != -1;
}), function(category) {
return { value: category };
});
};
@@ -315,17 +317,19 @@
};
Card.prototype.$addCategory = function(category) {
if (angular.isUndefined(this.categories)) {
this.categories = [{value: category}];
}
else {
for (var i = 0; i < this.categories.length; i++) {
if (this.categories[i].value == category) {
break;
if (category) {
if (angular.isUndefined(this.categories)) {
this.categories = [{value: category}];
}
else {
for (var i = 0; i < this.categories.length; i++) {
if (this.categories[i].value == category) {
break;
}
}
if (i == this.categories.length)
this.categories.push({value: category});
}
if (i == this.categories.length)
this.categories.push({value: category});
}
};