diff --git a/NEWS b/NEWS index a444225db..85f64f0d1 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,7 @@ Enhancements - [web] AngularJS optimizations in Mail module - [web] AngularJS optimization of color picker - [web] improve display of tasks status + - [web] added custom fields support from Thunderbird's address book Bug fixes - [web] respect SOGoLanguage and SOGoSupportedLanguages (#4169) diff --git a/UI/Contacts/UIxContactEditor.m b/UI/Contacts/UIxContactEditor.m index 52851f87f..f9f1ffeaf 100644 --- a/UI/Contacts/UIxContactEditor.m +++ b/UI/Contacts/UIxContactEditor.m @@ -337,11 +337,13 @@ static Class SOGoContactGCSEntryK = Nil; - (void) setAttributes: (NSDictionary *) attributes { - CardElement *element; - NSArray *elements, *values; NSMutableArray *orgs, *categories; + NSDictionary *customFields; + NSArray *elements, *values; NSCalendarDate *date; + CardElement *element; id o; + unsigned int i, year, month, day; [card setNWithFamily: [attributes objectForKey: @"c_sn"] @@ -485,6 +487,38 @@ static Class SOGoContactGCSEntryK = Nil; [card setCategories: categories]; } + customFields = [attributes objectForKey: @"customFields"]; + if (customFields && [customFields isKindOfClass: [NSDictionary class]]) + { + if ((o = [customFields objectForKey: @"1"])) + { + elements = [card childrenWithTag: @"custom1"]; + [card removeChildren: elements]; + [card addElementWithTag: @"custom1" ofType: nil withValue: o]; + } + + if ((o = [customFields objectForKey: @"2"])) + { + elements = [card childrenWithTag: @"custom2"]; + [card removeChildren: elements]; + [card addElementWithTag: @"custom2" ofType: nil withValue: o]; + } + + if ((o = [customFields objectForKey: @"3"])) + { + elements = [card childrenWithTag: @"custom3"]; + [card removeChildren: elements]; + [card addElementWithTag: @"custom1" ofType: nil withValue: o]; + } + + if ((o = [customFields objectForKey: @"4"])) + { + elements = [card childrenWithTag: @"custom4"]; + [card removeChildren: elements]; + [card addElementWithTag: @"custom1" ofType: nil withValue: o]; + } + } + [card cleanupEmptyChildren]; } diff --git a/UI/Contacts/UIxContactView.m b/UI/Contacts/UIxContactView.m index bfec54742..6eaf282c1 100644 --- a/UI/Contacts/UIxContactView.m +++ b/UI/Contacts/UIxContactView.m @@ -270,14 +270,15 @@ * @apiSuccess (Success 200) {Object[]} [urls] URLs * @apiSuccess (Success 200) {String} urls.type Type (e.g., personal or work) * @apiSuccess (Success 200) {String} urls.value URL + * @apiSuccess (Success 200) {Object[]} customFields Custom fields from Thunderbird */ - (id ) dataAction { - id result; - id o; + NSMutableDictionary *customFields, *data; SOGoObject *contact; + id result; NSArray *values; - NSMutableDictionary *data; + id o; contact = [self clientObject]; card = [contact vCard]; @@ -355,6 +356,23 @@ if ([contact hasPhoto]) [data setObject: [self photoURL] forKey: @"photoURL"]; + // Custom fields from Thunderbird + customFields = [NSMutableDictionary dictionary]; + if ((o = [[card uniqueChildWithTag: @"custom1"] flattenedValuesForKey: @""]) && [o length]) + [customFields setObject: o forKey: @"1"]; + + if ((o = [[card uniqueChildWithTag: @"custom2"] flattenedValuesForKey: @""]) && [o length]) + [customFields setObject: o forKey: @"2"]; + + if ((o = [[card uniqueChildWithTag: @"custom3"] flattenedValuesForKey: @""]) && [o length]) + [customFields setObject: o forKey: @"3"]; + + if ((o = [[card uniqueChildWithTag: @"custom4"] flattenedValuesForKey: @""]) && [o length]) + [customFields setObject: o forKey: @"4"]; + + if ([customFields count]) + [data setObject: customFields forKey: @"customFields"]; + result = [self responseWithStatus: 200 andString: [data jsonRepresentation]]; diff --git a/UI/Templates/ContactsUI/UIxContactEditorTemplate.wox b/UI/Templates/ContactsUI/UIxContactEditorTemplate.wox index 184b2efca..12a890ee1 100644 --- a/UI/Templates/ContactsUI/UIxContactEditorTemplate.wox +++ b/UI/Templates/ContactsUI/UIxContactEditorTemplate.wox @@ -348,6 +348,38 @@ + +
+
+
+ + remove_circle + + + + + + + + + +
+
+
+ + add_circle + + +
+
+ diff --git a/UI/Templates/ContactsUI/UIxContactViewTemplate.wox b/UI/Templates/ContactsUI/UIxContactViewTemplate.wox index baf79a1c2..b144d0a6b 100644 --- a/UI/Templates/ContactsUI/UIxContactViewTemplate.wox +++ b/UI/Templates/ContactsUI/UIxContactViewTemplate.wox @@ -146,6 +146,33 @@ +
+
+ +
+ {{editor.card.customFields['1']}} +
+
+
+ +
+ {{editor.card.customFields['2']}} +
+
+
+ +
+ {{editor.card.customFields['3']}} +
+
+
+ +
+ {{editor.card.customFields['4']}} +
+
+
+
diff --git a/UI/WebServerResources/js/Contacts/CardController.js b/UI/WebServerResources/js/Contacts/CardController.js index 495b0e3fa..81a6046a6 100644 --- a/UI/WebServerResources/js/Contacts/CardController.js +++ b/UI/WebServerResources/js/Contacts/CardController.js @@ -29,6 +29,9 @@ vm.addPhone = addPhone; vm.addUrl = addUrl; vm.addAddress = addAddress; + vm.canAddCustomField = canAddCustomField; + vm.addCustomField = addCustomField; + vm.deleteCustomField = deleteCustomField; vm.userFilter = userFilter; vm.save = save; vm.close = close; @@ -98,6 +101,20 @@ var i = vm.card.$addUrl('', ''); focus('url_' + i); } + function canAddCustomField() { + return _.keys(stateCard.customFields).length < 4; + } + function addCustomField() { + if (!angular.isDefined(vm.card.customFields)) + vm.card.customFields = {}; + + // Find the first 'available' custom field + var availableKeys = _.pullAll(['1', '2', '3', '4'], _.keys(stateCard.customFields)); + vm.card.customFields[availableKeys[0]] = ""; + } + function deleteCustomField(key) { + delete vm.card.customFields[key]; + } function addAddress() { var i = vm.card.$addAddress('', '', '', '', '', '', '', ''); focus('address_' + i);