diff options
author | Thomas Tanghus <thomas@tanghus.net> | 2012-02-09 19:04:07 +0100 |
---|---|---|
committer | Thomas Tanghus <thomas@tanghus.net> | 2012-02-09 19:04:07 +0100 |
commit | ff53b0c2097ae5d0390336238454dc1792158905 (patch) | |
tree | fb31d989dac41784e1fa6e2182d5db1b742a82e2 /apps/contacts | |
parent | 25faa40bd09f35cfc14a699d23d2d747173922d3 (diff) | |
download | nextcloud-server-ff53b0c2097ae5d0390336238454dc1792158905.tar.gz nextcloud-server-ff53b0c2097ae5d0390336238454dc1792158905.zip |
Keep js data structure in sync on changes.
More checks for missing properties.
Diffstat (limited to 'apps/contacts')
-rw-r--r-- | apps/contacts/ajax/contactdetails.php | 3 | ||||
-rw-r--r-- | apps/contacts/css/contacts.css | 8 | ||||
-rw-r--r-- | apps/contacts/js/contacts.js | 46 | ||||
-rw-r--r-- | apps/contacts/lib/app.php | 18 | ||||
-rw-r--r-- | apps/contacts/lib/vcard.php | 18 | ||||
-rw-r--r-- | apps/contacts/templates/part.contact.php | 6 |
6 files changed, 82 insertions, 17 deletions
diff --git a/apps/contacts/ajax/contactdetails.php b/apps/contacts/ajax/contactdetails.php index abec500c396..f7ac25ea515 100644 --- a/apps/contacts/ajax/contactdetails.php +++ b/apps/contacts/ajax/contactdetails.php @@ -60,7 +60,8 @@ if(!isset($details['FN'])) { // Make up for not supporting the 'N' field in earlier version. if(!isset($details['N'])) { - $details['N'] = array(array($details['FN'][0]['value'],'','','','')); + $details['N'] = array(); + $details['N'][0] = array($details['FN'][0]['value'],'','','',''); } // Don't wanna transfer the photo in a json string. diff --git a/apps/contacts/css/contacts.css b/apps/contacts/css/contacts.css index d90e93f64e9..86322a2cc2a 100644 --- a/apps/contacts/css/contacts.css +++ b/apps/contacts/css/contacts.css @@ -8,10 +8,10 @@ #contacts_deletecard {position:absolute;top:15px;right:25px;} #contacts_downloadcard {position:absolute;top:15px;right:50px;} #contacts_propertymenu_button { position:absolute;top:15px;right:150px; height: 20px; width: 150px; background:url('../../../core/img/actions/add.svg') no-repeat center; } -#contacts_propertymenu { position:absolute;top:35px;right:150px; -moz-border-radius:0.5em; -webkit-border-radius:0.5em; border-radius:0.5em; -moz-border-radius:0.5em; -webkit-border-radius:0.5em; border-radius:0.5em; } -#contacts_propertymenu li { display: block; font-weight: bold; border-left: thin solid #1d2d44; border-right: thin solid #1d2d44; height: 20px; width: 100px; } -#contacts_propertymenu li:first-child { border-top: thin solid #1d2d44; -moz-border-radius-topleft:0.5em; -webkit-border-top-left-radius:0.5em; border-top-left-radius:0.5em; -moz-border-radius-topright:0.5em; -webkit-border-top-right-radius:0.5em; border-top-right-radius:0.5em; } -#contacts_propertymenu li:last-child { border-bottom: thin solid #1d2d44; -moz-border-radius-bottomleft:0.5em; -webkit-border-bottom-left-radius:0.5em; border-bottom-left-radius:0.5em; -moz-border-radius-bottomright:0.5em; -webkit-border-bottom-right-radius:0.5em; border-bottom-right-radius:0.5em; } +#contacts_propertymenu { position:absolute;top:40px;right:150px; overflow:hidden; text-overflow:ellipsis; /*border: thin solid #1d2d44;*/ -moz-box-shadow:0 0 10px #000; -webkit-box-shadow:0 0 10px #000; box-shadow:0 0 10px #000; -moz-border-radius:0.5em; -webkit-border-radius:0.5em; border-radius:0.5em; -moz-border-radius:0.5em; -webkit-border-radius:0.5em; border-radius:0.5em; } +#contacts_propertymenu li { display: block; font-weight: bold; height: 20px; width: 100px; } +/*#contacts_propertymenu li:first-child { border-top: thin solid #1d2d44; -moz-border-radius-topleft:0.5em; -webkit-border-top-left-radius:0.5em; border-top-left-radius:0.5em; -moz-border-radius-topright:0.5em; -webkit-border-top-right-radius:0.5em; border-top-right-radius:0.5em; } +#contacts_propertymenu li:last-child { border-bottom: thin solid #1d2d44; -moz-border-radius-bottomleft:0.5em; -webkit-border-bottom-left-radius:0.5em; border-bottom-left-radius:0.5em; -moz-border-radius-bottomright:0.5em; -webkit-border-bottom-right-radius:0.5em; border-bottom-right-radius:0.5em; }*/ #contacts_propertymenu li a { padding: 3px; display: block } #contacts_propertymenu li:hover { background-color: #1d2d44; } #contacts_propertymenu li a:hover { color: #fff } diff --git a/apps/contacts/js/contacts.js b/apps/contacts/js/contacts.js index 34210a4567c..7f4e938c48a 100644 --- a/apps/contacts/js/contacts.js +++ b/apps/contacts/js/contacts.js @@ -154,7 +154,7 @@ Contacts={ ); }, loadHandlers:function() { - console.log('loadHandlers'); + //console.log('loadHandlers'); /* $('.formfloat').hover( function () { @@ -164,9 +164,9 @@ Contacts={ $(this).find('.add').fadeOut(500); } );*/ + $('.button,.action').tipsy(); $('#contacts_deletecard').tipsy({gravity: 'ne'}); $('#contacts_downloadcard').tipsy({gravity: 'ne'}); - $('.button').tipsy(); $('#fn').jec(); $('.jecEditableOption').attr('title', t('contacts','Custom')); $('#fn').tipsy(); @@ -265,7 +265,7 @@ Contacts={ $('#contact_communication').hide(); this.data = jsondata; this.id = this.data.id; - console.log('loaded: ' + this.data.FN[0]['value']); + //console.log('loaded: ' + this.data.FN[0]['value']); this.populateNameFields(); this.loadPhoto(); this.loadMails(); @@ -417,13 +417,38 @@ Contacts={ } }); }, + savePropertyInternal:function(name, fields, oldchecksum, checksum){ + // TODO: Add functionality for new fields. + //console.log('savePropertyInternal: ' + name + ', checksum: ' + checksum); + //console.log('savePropertyInternal: ' + this.data[name]); + var params = {}; + var value = undefined; + jQuery.each(fields, function(i, field){ + //.substring(11,'parameters[TYPE][]'.indexOf(']')) + if(field.name.substring(0, 5) === 'value') { + value = field.value; + } else if(field.name.substring(0, 10) === 'parameters') { + var p = field.name.substring(11,'parameters[TYPE][]'.indexOf(']')); + if(!(p in params)) { + params[p] = []; + } + params[p].push(field.value); + } + }); + for(var i in this.data[name]) { + if(this.data[name][i]['checksum'] == oldchecksum) { + this.data[name][i]['checksum'] = checksum; + this.data[name][i]['value'] = value; + this.data[name][i]['parameters'] = params; + } + } + }, saveProperty:function(obj){ // I couldn't get the selector to filter on 'contacts_property' so I filter by hand here :-/ if(!$(obj).hasClass('contacts_property')) { //console.log('Filtering out object.' + obj); return false; } - console.log('saveProperty. ' + $(obj).val()); if($(obj).hasClass('nonempty') && $(obj).val().trim() == '') { Contacts.UI.messageBox(t('contacts', 'Error'), t('contacts', 'This property has to be non-empty.')); return false; @@ -432,7 +457,9 @@ Contacts={ Contacts.UI.loading(container, true); var checksum = container.data('checksum'); var name = container.data('element'); - var q = container.find('input,select').serialize(); + console.log('saveProperty: ' + name); + var fields = container.find('input[class*="contacts_property"],select[class*="contacts_property"]').serializeArray(); + var q = container.find('input[class*="contacts_property"],select[class*="contacts_property"]').serialize(); if(q == '' || q == undefined) { console.log('Couldn\'t serialize elements.'); Contacts.UI.loading(container, false); @@ -445,6 +472,7 @@ Contacts={ $.post('ajax/saveproperty.php',q,function(jsondata){ if(jsondata.status == 'success'){ container.data('checksum', jsondata.data.checksum); + Contacts.UI.Card.savePropertyInternal(name, fields, checksum, jsondata.data.checksum); Contacts.UI.loading(container, false); return true; } @@ -459,6 +487,8 @@ Contacts={ $.post('ajax/addproperty.php',q,function(jsondata){ if(jsondata.status == 'success'){ container.data('checksum', jsondata.data.checksum); + // TODO: savePropertyInternal doesn't know about new fields + //Contacts.UI.Card.savePropertyInternal(name, fields, checksum, jsondata.data.checksum); Contacts.UI.loading(container, false); return true; } @@ -884,7 +914,7 @@ Contacts={ for(ptype in this.data.TEL[phone]['parameters'][param]) { var pt = this.data.TEL[phone]['parameters'][param][ptype]; $('#phonelist li:last-child').find('select option').each(function(){ - if ($(this).val().toUpperCase() == pt) { + if ($(this).val().toUpperCase() == pt.toUpperCase()) { $(this).attr('selected', 'selected'); } }); @@ -1204,7 +1234,11 @@ $(document).ready(function(){ xhr.send(file); } + $('#contacts_propertymenu_button').live('click',function(){ + $('#contacts_propertymenu').is(':hidden') && $('#contacts_propertymenu').show() || $('#contacts_propertymenu').hide(); + }); $('#contacts_propertymenu a').live('click',function(){ Contacts.UI.Card.addProperty(this); + $('#contacts_propertymenu').hide(); }); }); diff --git a/apps/contacts/lib/app.php b/apps/contacts/lib/app.php index 724d632ea5d..f62bd311479 100644 --- a/apps/contacts/lib/app.php +++ b/apps/contacts/lib/app.php @@ -67,13 +67,29 @@ class OC_Contacts_App{ } /** - * @brief Gets the VCard as text + * @brief Gets the VCard as an OC_VObject * @returns The card or null if the card could not be parsed. */ public static function getContactVCard($id){ $card = self::getContactObject( $id ); $vcard = OC_VObject::parse($card['carddata']); + // Try to fix cards with missing 'N' field from pre ownCloud 4. Hot damn, this is ugly... + if(!is_null($vcard) && !$vcard->__isset('N')){ + $appinfo = $info=OC_App::getAppInfo('contacts'); + if($appinfo['version'] >= 5) { + OC_Log::write('contacts','OC_Contacts_App::getContactVCard. Deprecated check for missing N field', OC_Log::DEBUG); + } + OC_Log::write('contacts','getContactVCard, Missing N field', OC_Log::DEBUG); + if($vcard->__isset('FN')) { + OC_Log::write('contacts','getContactVCard, found FN field: '.$vcard->__get('FN'), OC_Log::DEBUG); + $n = implode(';', array_reverse(array_slice(explode(' ', $vcard->__get('FN')), 0, 2))).';;;'; + OC_Contacts_VCard::edit( $id, $vcard->serialize()); + } else { // Else just add an empty 'N' field :-P + $vcard->setString('N', 'Unknown;Name;;;'); + } + $vcard->setString('N', $n); + } return $vcard; } diff --git a/apps/contacts/lib/vcard.php b/apps/contacts/lib/vcard.php index bb5b2da23d5..f9ca427354e 100644 --- a/apps/contacts/lib/vcard.php +++ b/apps/contacts/lib/vcard.php @@ -134,7 +134,7 @@ class OC_Contacts_VCard{ // Add product ID. $prodid = trim($card->getAsString('PRODID')); if(!$prodid) { - $appinfo = $info=OC_App::getAppInfo('contacts'); + $appinfo = OC_App::getAppInfo('contacts'); $prodid = '//ownCloud//NONSGML '.$appinfo['name'].' '.$appinfo['version'].'//EN'; $card->setString('PRODID', $prodid); } @@ -176,7 +176,7 @@ class OC_Contacts_VCard{ * @return insertid */ public static function addFromDAVData($id,$uri,$data){ - $fn = null; + $fn = $n = null; $email = null; $card = OC_VObject::parse($data); if(!is_null($card)){ @@ -184,19 +184,31 @@ class OC_Contacts_VCard{ if($property->name == 'FN'){ $fn = $property->value; } + if($property->name == 'N'){ + $n = $property->value; + } if($property->name == 'EMAIL' && is_null($email)){ $email = $property->value; } } } if(!$fn) { - if($email) { + if($n){ + $fn = join(' ', array_reverse(array_slice(explode(';', $n), 0, 2))); + } elseif($email) { $fn = $email; } else { $fn = 'Unknown Name'; } $card->addProperty('FN', $fn); $data = $card->serialize(); + OC_Log::write('contacts','OC_Contacts_VCard::add. Added missing \'FN\' field: '.$n,OC_Log::DEBUG); + } + if(!$n){ // Fix missing 'N' field. + $n = implode(';', array_reverse(array_slice(explode(' ', $fn), 0, 2))).';;;'; + $card->setString('N', $n); + $data = $card->serialize(); + OC_Log::write('contacts','OC_Contacts_VCard::add. Added missing \'N\' field: '.$n,OC_Log::DEBUG); } $stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*contacts_cards (addressbookid,fullname,carddata,uri,lastmodified) VALUES(?,?,?,?,?)' ); diff --git a/apps/contacts/templates/part.contact.php b/apps/contacts/templates/part.contact.php index 446a9b88ede..a56999dbf39 100644 --- a/apps/contacts/templates/part.contact.php +++ b/apps/contacts/templates/part.contact.php @@ -4,8 +4,9 @@ $id = isset($_['id']) ? $_['id'] : ''; ?> <div id="card"> <div id="actionbar"> - <a id="contacts_propertymenu_button"></a> - <ul id="contacts_propertymenu"> + <a title="<?php echo $l->t('Add field'); ?>" class="svg action" id="contacts_propertymenu_button"></a> + <div id="contacts_propertymenu" style="display: none;"> + <ul> <li><a data-type="PHOTO"><?php echo $l->t('Profile picture'); ?></a></li> <li><a data-type="ORG"><?php echo $l->t('Organization'); ?></a></li> <li><a data-type="NICKNAME"><?php echo $l->t('Nickname'); ?></a></li> @@ -14,6 +15,7 @@ $id = isset($_['id']) ? $_['id'] : ''; <li><a data-type="EMAIL"><?php echo $l->t('Email'); ?></a></li> <li><a data-type="ADR"><?php echo $l->t('Address'); ?></a></li> </ul> + </div> <img onclick="Contacts.UI.Card.export();" class="svg action" id="contacts_downloadcard" src="<?php echo image_path('', 'actions/download.svg'); ?>" title="<?php echo $l->t('Download contact');?>" /> <img class="svg action" id="contacts_deletecard" src="<?php echo image_path('', 'actions/delete.svg'); ?>" title="<?php echo $l->t('Delete contact');?>" /> </div> |