From e8a9eb8dbed2a40c4b2cb45c56b98b2aa234e0bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Mon, 24 Oct 2016 13:45:18 +0200 Subject: [PATCH] [downstream] Fix issues with date formating in case of deleting a date field MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * downstream from https://github.com/owncloud/contacts/pull/527 Signed-off-by: Marius Blüm --- js/models/contact_model.js | 54 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/js/models/contact_model.js b/js/models/contact_model.js index 9e485adcb..7cb043fe5 100644 --- a/js/models/contact_model.js +++ b/js/models/contact_model.js @@ -145,15 +145,53 @@ angular.module('contactsApp') } }, +<<<<<<< HEAD getProperty: function(name) { if (this.props[name]) { return this.props[name][0]; +======= + 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] = []; } @@ -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 @@ -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); },