From 3d4311194c423d3e90483fbb418727b2fc6aa173 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Thu, 14 Jan 2016 15:52:04 -0500 Subject: [PATCH] (js) Fix handling of new contact categories Fixes #175 --- .../ContactsUI/UIxContactEditorTemplate.wox | 6 ++--- .../js/Contacts/Card.service.js | 26 +++++++++++-------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/UI/Templates/ContactsUI/UIxContactEditorTemplate.wox b/UI/Templates/ContactsUI/UIxContactEditorTemplate.wox index b2919a9be..f162036d8 100644 --- a/UI/Templates/ContactsUI/UIxContactEditorTemplate.wox +++ b/UI/Templates/ContactsUI/UIxContactEditorTemplate.wox @@ -107,16 +107,16 @@ - + {{$chip.value}} - {{category}} + {{category.value}} diff --git a/UI/WebServerResources/js/Contacts/Card.service.js b/UI/WebServerResources/js/Contacts/Card.service.js index 5a8d67d37..053c63e77 100644 --- a/UI/WebServerResources/js/Contacts/Card.service.js +++ b/UI/WebServerResources/js/Contacts/Card.service.js @@ -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}); } };