Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with date formating in case of deleting a date field #11

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions js/models/contact_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,53 @@ angular.module('contactsApp')
}
},

<<<<<<< HEAD
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nop

getProperty: function(name) {
if (this.props[name]) {
return this.props[name][0];
=======
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nop

formatDateAsRFC6350: function(name, data) {
if (_.isUndefined(data) || _.isUndefined(data.value)) {
return data;
}
if (this.dateProperties.indexOf(name) !== -1) {
var match = data.value.match(/^(\d{4})-(\d{2})-(\d{2})$/);
if (match) {
data.value = match[1] + match[2] + match[3];
}
}

return data;
},

formatDateForDisplay: function(name, data) {
if (_.isUndefined(data) || _.isUndefined(data.value)) {
return data;
}
if (this.dateProperties.indexOf(name) !== -1) {
var match = data.value.match(/^(\d{4})(\d{2})(\d{2})$/);
if (match) {
data.value = match[1] + '-' + match[2] + '-' + match[3];
}
}

return data;
},

getProperty: function(name) {
if (this.props[name]) {
return this.formatDateForDisplay(name, this.props[name][0]);
>>>>>>> db23df5... Fix issues with date formating in case of deleting a date field
} else {
return undefined;
}
},
addProperty: function(name, data) {
data = angular.copy(data);
<<<<<<< HEAD
=======
data = this.formatDateAsRFC6350(name, data);
>>>>>>> db23df5... Fix issues with date formating in case of deleting a date field
if(!this.props[name]) {
this.props[name] = [];
}
Expand All @@ -168,6 +206,10 @@ angular.module('contactsApp')
if(!this.props[name]) {
this.props[name] = [];
}
<<<<<<< HEAD
=======
data = this.formatDateAsRFC6350(name, data);
>>>>>>> db23df5... Fix issues with date formating in case of deleting a date field
this.props[name][0] = data;

// keep vCard in sync
Expand All @@ -185,6 +227,18 @@ angular.module('contactsApp')
},

syncVCard: function() {
<<<<<<< HEAD
=======
var self = this;

_.each(this.dateProperties, function(name) {
if (!_.isUndefined(self.props[name]) && !_.isUndefined(self.props[name][0])) {
// Set dates again to make sure they are in RFC-6350 format
self.setProperty(name, self.props[name][0]);
}
});

>>>>>>> db23df5... Fix issues with date formating in case of deleting a date field
// keep vCard in sync
this.data.addressData = $filter('JSON2vCard')(this.props);
},
Expand Down