summaryrefslogtreecommitdiffstats
path: root/js/models/contact_model.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/models/contact_model.js')
-rw-r--r--js/models/contact_model.js35
1 files changed, 33 insertions, 2 deletions
diff --git a/js/models/contact_model.js b/js/models/contact_model.js
index 02e1c2f3..ca31cb39 100644
--- a/js/models/contact_model.js
+++ b/js/models/contact_model.js
@@ -5,6 +5,7 @@ angular.module('contactsApp')
data: {},
props: {},
+ failedProps: [],
dateProperties: ['bday', 'anniversary', 'deathdate'],
@@ -155,7 +156,7 @@ angular.module('contactsApp')
return this.setProperty('categories', { value: value });
} else {
// getter
- var property = this.getProperty('categories');
+ var property = this.validate('categories', this.getProperty('categories'));
if(!property) {
return [];
}
@@ -267,6 +268,16 @@ angular.module('contactsApp')
// keep vCard in sync
self.data.addressData = $filter('JSON2vCard')(self.props);
+
+ // Revalidate all props
+ _.each(self.failedProps, function(name, index) {
+ if (!_.isUndefined(self.props[name]) && !_.isUndefined(self.props[name][0])) {
+ // Set dates again to make sure they are in RFC-6350 format
+ self.failedProps.splice(index, 1);
+ self.validate(name, self.props[name][0]);
+ }
+ });
+
},
matches: function(pattern) {
@@ -294,6 +305,26 @@ angular.module('contactsApp')
return false;
});
return matchingProps.length > 0;
+ },
+
+ validate: function(prop, property) {
+ switch(prop) {
+ case 'categories':
+ // Avoid unescaped commas
+ if (angular.isArray(property.value)) {
+ if(property.value.join(';').indexOf(',') !== -1) {
+ this.failedProps.push(prop);
+ property.value = property.value.join(',').split(',');
+ }
+ } else if (angular.isString(property.value)) {
+ if(property.value.indexOf(',') !== -1) {
+ this.failedProps.push(prop);
+ property.value = property.value.split(',');
+ }
+ }
+ break;
+ }
+ return property;
}
});
@@ -311,7 +342,7 @@ angular.module('contactsApp')
var property = this.getProperty('categories');
if(!property) {
- this.categories('');
+ this.categories([]);
} else {
if (angular.isString(property.value)) {
this.categories([property.value]);