(js) Fix handling of contact categories

pull/188/head
Francis Lachapelle 2016-01-18 14:46:23 -05:00
parent 3787296fd6
commit 5c4da276bf
3 changed files with 25 additions and 17 deletions

View File

@ -108,7 +108,7 @@
<!-- categories -->
<md-chips ng-model="editor.card.categories"
md-transform-chip="{ value: $chip }">
md-transform-chip="editor.transformCategory($chip)">
<md-chip-template>{{$chip.value}}</md-chip-template>
<md-autocomplete
md-selected-item="editor.categories.selected"

View File

@ -129,6 +129,7 @@
*/
Card.prototype.init = function(data, partial) {
this.refs = [];
this.categories = [];
angular.extend(this, data);
if (!this.$$fullname)
this.$$fullname = this.$fullname();
@ -316,22 +317,22 @@
return this.orgUnits.length - 1;
};
Card.prototype.$addCategory = function(category) {
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});
}
}
};
// Card.prototype.$addCategory = function(category) {
// 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});
// }
// }
// };
Card.prototype.$addEmail = function(type) {
if (angular.isUndefined(this.emails)) {

View File

@ -20,6 +20,7 @@
vm.allAddressTypes = Card.$ADDRESS_TYPES;
vm.categories = {};
vm.userFilterResults = [];
vm.transformCategory = transformCategory;
vm.addOrgUnit = addOrgUnit;
vm.addBirthday = addBirthday;
vm.addScreenName = addScreenName;
@ -38,6 +39,12 @@
vm.toggleRawSource = toggleRawSource;
vm.showRawSource = false;
function transformCategory(input) {
if (angular.isString(input))
return { value: input };
else
return input;
}
function addOrgUnit() {
var i = vm.card.$addOrgUnit('');
focus('orgUnit_' + i);