(js) Fix handling of new contact categories

Fixes #175
pull/186/head
Francis Lachapelle 2016-01-14 15:52:04 -05:00
parent 667e6dff7c
commit 3d4311194c
2 changed files with 18 additions and 14 deletions

View File

@ -107,16 +107,16 @@
</div>
<!-- categories -->
<md-chips ng-model="editor.card.categories">
<md-chips ng-model="editor.card.categories"
md-transform-chip="{ value: $chip }">
<md-chip-template>{{$chip.value}}</md-chip-template>
<md-autocomplete
md-selected-item="editor.categories.selected"
md-selected-item-change="editor.card.$addCategory(category)"
md-search-text="editor.categories.searchText"
md-items="category in editor.card.constructor.filterCategories(editor.categories.searchText)"
md-min-length="0"
label:placeholder="Add a category">
<span md-highlight-text="editor.categories.searchText">{{category}}</span>
<span md-highlight-text="editor.categories.searchText">{{category.value}}</span>
</md-autocomplete>
</md-chips>

View File

@ -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});
}
};