From 644b6e60d555cf5bae1c03e32c7330fe4d8dce56 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Sun, 22 Jul 2012 14:49:38 +0200 Subject: [PATCH] Revert "No need to set checksum for PHOTO." This reverts commit 3937d19fa2ef3da2719d0425ce02707d0345960c. --- apps/contacts/ajax/loadphoto.php | 46 ++++++++++++++ apps/contacts/js/contacts.js | 104 ++++++++++++++++--------------- 2 files changed, 101 insertions(+), 49 deletions(-) create mode 100644 apps/contacts/ajax/loadphoto.php diff --git a/apps/contacts/ajax/loadphoto.php b/apps/contacts/ajax/loadphoto.php new file mode 100644 index 0000000000..be924b5db4 --- /dev/null +++ b/apps/contacts/ajax/loadphoto.php @@ -0,0 +1,46 @@ + + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see . + * + */ + +// Check if we are a user +OCP\JSON::checkLoggedIn(); +OCP\JSON::checkAppEnabled('contacts'); + +require_once 'loghandler.php'; + +$id = isset($_GET['id']) ? $_GET['id'] : ''; +$refresh = isset($_GET['refresh']) ? true : false; + +if($id == '') { + bailOut(OC_Contacts_App::$l10n->t('Missing contact id.')); +} + +$checksum = ''; +$vcard = OC_Contacts_App::getContactVCard( $id ); +foreach($vcard->children as $property){ + if($property->name == 'PHOTO') { + $checksum = md5($property->serialize()); + break; + } +} + +OCP\JSON::success(array('data' => array('checksum'=>$checksum))); + diff --git a/apps/contacts/js/contacts.js b/apps/contacts/js/contacts.js index de6060a111..7c1304c559 100644 --- a/apps/contacts/js/contacts.js +++ b/apps/contacts/js/contacts.js @@ -21,31 +21,27 @@ Contacts={ * data: An object that will be passed as argument to the timeouthandler and clickhandler functions. */ notify:function(params) { - self = this; - if(!self.notifier) { - self.notifier = $('#notification'); - } - self.notifier.text(params.message); - self.notifier.fadeIn(); - self.notifier.on('click', function() { $(this).fadeOut();}); + var notifier = $('#notification'); + notifier.text(params.message); + notifier.fadeIn(); var timer = setTimeout(function() { - self.notifier.fadeOut(); + notifier.fadeOut(); if(params.timeouthandler && $.isFunction(params.timeouthandler)) { - params.timeouthandler(self.notifier.data(dataid)); - self.notifier.off('click'); - self.notifier.removeData(dataid); + params.timeouthandler(notifier.data(dataid)); + notifier.off('click'); + notifier.data(dataid, null); } }, params.timeout && $.isNumeric(params.timeout) ? parseInt(params.timeout)*1000 : 10000); var dataid = timer.toString(); if(params.data) { - self.notifier.data(dataid, params.data); + notifier.data(dataid, params.data); } if(params.clickhandler && $.isFunction(params.clickhandler)) { - self.notifier.on('click', function() { + notifier.on('click', function() { clearTimeout(timer); - self.notifier.off('click'); - params.clickhandler(self.notifier.data(dataid)); - self.notifier.removeData(dataid); + notifier.off('click'); + params.clickhandler(notifier.data(dataid)); + notifier.data(dataid, null); }); } }, @@ -299,6 +295,16 @@ Contacts={ $('#contacts_propertymenu_dropdown a').keydown(propertyMenuItem); }, Card:{ + id:'', + fn:'', + fullname:'', + shortname:'', + famname:'', + givname:'', + addname:'', + honpre:'', + honsuf:'', + data:undefined, update:function(params) { // params {cid:int, aid:int} if(!params) { params = {}; } $('#contacts li,#contacts h3').removeClass('active'); @@ -578,12 +584,8 @@ Contacts={ $(this).find('input').val(''); } }); - - with(this) { - delete fn; delete fullname; delete givname; delete famname; - delete addname; delete honpre; delete honsuf; - } - + this.fn = ''; this.fullname = ''; this.givname = ''; this.famname = ''; this.addname = ''; this.honpre = ''; this.honsuf = ''; + var narray = undefined; if(this.data.FN) { this.fn = this.data.FN[0]['value']; } @@ -1208,17 +1210,28 @@ Contacts={ $('#phototools li a').tipsy('hide'); var wrapper = $('#contacts_details_photo_wrapper'); wrapper.addClass('loading').addClass('wait'); - delete this.photo; - this.photo = new Image(); - $(this.photo).load(function () { + + var img = new Image(); + $(img).load(function () { $('img.contacts_details_photo').remove() - $(this).addClass('contacts_details_photo'); + $(this).addClass('contacts_details_photo').hide(); wrapper.removeClass('loading').removeClass('wait'); - $(this).insertAfter($('#phototools')).fadeIn('fast'); + $(this).insertAfter($('#phototools')).fadeIn(); }).error(function () { // notify the user that the image could not be loaded Contacts.UI.notify({message:t('contacts','Error loading profile picture.')}); }).attr('src', OC.linkTo('contacts', 'photo.php')+'?id='+self.id+refreshstr); + + $.getJSON(OC.filePath('contacts', 'ajax', 'loadphoto.php'),{'id':this.id, 'refresh': refresh},function(jsondata){ + if(jsondata.status == 'success'){ + $('#contacts_details_photo_wrapper').data('checksum', jsondata.data.checksum); + Contacts.UI.Card.loadPhotoHandlers(); + } + else{ + OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error')); + } + }); + $('#file_upload_form').show(); }, editCurrentPhoto:function(){ $.getJSON(OC.filePath('contacts', 'ajax', 'currentphoto.php'),{'id':this.id},function(jsondata){ @@ -1480,15 +1493,7 @@ Contacts={ } }, Contacts:{ - contacts:{}, batchnum:50, - get:function(id) { - if(!this.contacts[id]) { - // TODO: Check if item isn't loaded yet. If so insert it. - this.contacts[id] = $('#contacts li[data-id="'+id+'"]'); - } - return this.contacts[id]; - }, drop:function(event, ui) { var dragitem = ui.draggable, droptarget = $(this); if(dragitem.is('li')) { @@ -1527,16 +1532,13 @@ Contacts={ * If 'contactlist' or 'contacts' aren't defined they will be search for based in the properties in 'data'. */ insertContact:function(params) { - var id, bookid; if(!params.contactlist) { // FIXME: Check if contact really exists. - bookid = params.data ? params.data.addressbookid : params.contact.data('bookid'); - id = params.data ? params.data.id : params.contact.data('id'); + var bookid = params.data ? params.data.addressbookid : params.contact.data('bookid'); params.contactlist = $('#contacts ul[data-id="'+bookid+'"]'); } if(!params.contacts) { - bookid = params.data ? params.data.addressbookid : params.contact.data('bookid'); - id = params.data ? params.data.id : params.contact.data('id'); + var bookid = params.data ? params.data.addressbookid : params.contact.data('bookid'); params.contacts = $('#contacts ul[data-id="'+bookid+'"] li'); } var contact = params.data @@ -1556,7 +1558,6 @@ Contacts={ if(!added || !params.contacts) { params.contactlist.append(contact); } - //this.contacts[id] = contact; return contact; }, next:function(reverse) { @@ -1691,13 +1692,18 @@ $(document).ready(function(){ OCCategories.changed = Contacts.UI.Card.categoriesChanged; OCCategories.app = 'contacts'; - $('#chooseaddressbook').on('click keydown', Contacts.UI.Addressbooks.overview); - $('#contacts_newcontact').on('click keydown', Contacts.UI.Card.editNew); + $('#notification').click(function(){ + $('#notification').fadeOut(); + }); - var ninjahelp = $('#ninjahelp'); + $('#chooseaddressbook').click(Contacts.UI.Addressbooks.overview); + $('#chooseaddressbook').keydown(Contacts.UI.Addressbooks.overview); - ninjahelp.find('.close').on('click keydown',function() { - ninjahelp.hide(); + $('#contacts_newcontact').click(Contacts.UI.Card.editNew); + $('#contacts_newcontact').keydown(Contacts.UI.Card.editNew); + + $('#ninjahelp .close').on('click keydown',function() { + $('#ninjahelp').hide(); }); $(document).on('keyup', function(event) { @@ -1715,7 +1721,7 @@ $(document).ready(function(){ */ switch(event.which) { case 27: // Esc - ninjahelp.hide(); + $('#ninjahelp').hide(); break; case 46: if(event.shiftKey) { @@ -1762,7 +1768,7 @@ $(document).ready(function(){ Contacts.UI.Contacts.update({cid:Contacts.UI.Card.id}); break; case 191: // ? - ninjahelp.toggle('fast'); + $('#ninjahelp').toggle('fast'); break; } @@ -1774,7 +1780,7 @@ $(document).ready(function(){ $('.contacts').click(); } }); - $(document).on('click', '#contacts', function(event){ + $(document).on('click', '.contacts', function(event){ var $tgt = $(event.target); if ($tgt.is('li') || $tgt.is('a')) { var item = $tgt.is('li')?$($tgt):($tgt).parent();