]> source.dussan.org Git - nextcloud-server.git/commitdiff
Contacts: Hack to add structured name from formatted name.
authorThomas Tanghus <thomas@tanghus.net>
Thu, 10 May 2012 23:13:19 +0000 (01:13 +0200)
committerThomas Tanghus <thomas@tanghus.net>
Thu, 10 May 2012 23:14:11 +0000 (01:14 +0200)
apps/contacts/js/contacts.js
apps/contacts/lib/vcard.php

index 2c9cb68b00367bd40e1e21601d52def093f2b30d..b37383a12f48bb472775fbdc3d81e18a11d295d5 100644 (file)
@@ -443,7 +443,6 @@ Contacts={
                                        }
                                });
                                this.fn = ''; this.fullname = ''; this.givname = ''; this.famname = ''; this.addname = ''; this.honpre = ''; this.honsuf = '';
-                               var full = '';
                                var narray = undefined;
                                if(this.data.FN) {
                                        this.fn = this.data.FN[0]['value'];
@@ -453,7 +452,6 @@ Contacts={
                                }
                                if(this.data.N == undefined) {
                                        narray = [this.fn,'','','','']; // Checking for non-existing 'N' property :-P
-                                       full = this.fn;
                                } else {
                                        narray = this.data.N[0]['value'];
                                }
@@ -479,7 +477,6 @@ Contacts={
                                }
                                $('#n').html(this.fullname);
                                $('#fn_select option').remove();
-                               $('#fn_select').combobox('value', this.fn);
                                var names = [this.fullname, this.givname + ' ' + this.famname, this.famname + ' ' + this.givname, this.famname + ', ' + this.givname];
                                if(this.data.ORG) {
                                        names[names.length]=this.data.ORG[0].value;
@@ -489,6 +486,7 @@ Contacts={
                                                .append($('<option></option>')
                                                .text(value)); 
                                });
+                               $('#fn_select').combobox('value', this.fn);
                                $('#contact_identity').find('*[data-element="N"]').data('checksum', this.data.N[0]['checksum']);
                                if(this.data.FN) {
                                        $('#contact_identity').find('*[data-element="FN"]').data('checksum', this.data.FN[0]['checksum']);
@@ -564,6 +562,22 @@ Contacts={
                                var checksum = container.data('checksum');
                                var name = container.data('element');
                                var fields = container.find('input.contacts_property,select.contacts_property').serializeArray();
+                               switch(name) {
+                                       case 'FN':
+                                               var nempty = true;
+                                               for(var i in Contacts.UI.Card.data.N[0]['value']) {
+                                                       if(Contacts.UI.Card.data.N[0]['value'][i] != '') {
+                                                               nempty = false;
+                                                               break;
+                                                       }
+                                               }
+                                               if(nempty) {
+                                                       $('#n').val(fields[0].value + ';;;;');
+                                                       Contacts.UI.Card.data.N[0]['value'] = Array(fields[0].value, '', '', '', '');
+                                                       setTimeout(function() {Contacts.UI.Card.saveProperty($('#n'))}, 500);
+                                               }
+                                               break;
+                               }
                                var q = container.find('input.contacts_property,select.contacts_property,textarea.contacts_property').serialize();
                                if(q == '' || q == undefined) {
                                        OC.dialogs.alert(t('contacts', 'Couldn\'t serialize elements.'), t('contacts', 'Error'));
index c2ab0e07e91c86ee199991fb13dedf2e422fed5d..91ae3a7514d73a4cf40fde758f795a466a84d246 100755 (executable)
@@ -241,15 +241,6 @@ class OC_Contacts_VCard{
                if(self::trueUID($aid, $uid)) {
                        $vcard->setString('UID', $uid);
                }
-               $vcard->setString('VERSION','3.0');
-               // Add product ID is missing.
-               $prodid = trim($vcard->getAsString('PRODID'));
-               if(!$prodid) {
-                       $appinfo = OCP\App::getAppInfo('contacts');
-                       $appversion = OCP\App::getAppVersion('contacts');
-                       $prodid = '-//ownCloud//NONSGML '.$appinfo['name'].' '.$appversion.'//EN';
-                       $vcard->setString('PRODID', $prodid);
-               }
                $now = new DateTime;
                $vcard->setString('REV', $now->format(DateTime::W3C));
        }
@@ -272,6 +263,16 @@ class OC_Contacts_VCard{
                        self::updateValuesFromAdd($aid, $card);
                }
 
+               $card->setString('VERSION','3.0');
+               // Add product ID is missing.
+               $prodid = trim($card->getAsString('PRODID'));
+               if(!$prodid) {
+                       $appinfo = OCP\App::getAppInfo('contacts');
+                       $appversion = OCP\App::getAppVersion('contacts');
+                       $prodid = '-//ownCloud//NONSGML '.$appinfo['name'].' '.$appversion.'//EN';
+                       $card->setString('PRODID', $prodid);
+               }
+
                $fn = $card->getAsString('FN');
                if (empty($fn)) {
                        $fn = '';