From bf095621e09b494d90b1e894e5091d2681675b8e Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Tue, 22 Oct 2013 17:10:23 +0200 Subject: [PATCH] Fix editing contact photos. --- appinfo/routes.php | 2 +- js/app.js | 25 ++++++++++--------- lib/controller/contactphotocontroller.php | 30 ++++++++++++++--------- 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/appinfo/routes.php b/appinfo/routes.php index 76bad369..85b3a9c3 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -251,7 +251,7 @@ $this->create('contacts_cache_fs_photo', 'addressbook/{backend}/{addressBookId}/ $dispatcher->dispatch('ContactPhotoController', 'cacheFileSystemPhoto'); } ) - ->requirements(array('backend', 'addressbook', 'contactId')); + ->requirements(array('backend', 'addressBookId', 'contactId')); $this->create('contacts_tmp_contact_photo', 'addressbook/{backend}/{addressBookId}/contact/{contactId}/photo/{key}/tmp') ->get() diff --git a/js/app.js b/js/app.js index 6543ffbb..b0c16421 100644 --- a/js/app.js +++ b/js/app.js @@ -744,7 +744,7 @@ OC.Contacts = OC.Contacts || { var form = $('#file_upload_form'); var url = OC.Router.generate( 'contacts_upload_contact_photo', - {backend: metadata.backend, addressbookid: metadata.addressbookid, contactid: metadata.contactid} + {backend: metadata.backend, addressBookId: metadata.addressBookId, contactId: metadata.contactId} ); form.attr('action', url); }).on('change', function() { @@ -1456,11 +1456,12 @@ OC.Contacts = OC.Contacts || { console.log('cloudPhotoSelected', metadata); var url = OC.Router.generate( 'contacts_cache_fs_photo', - {backend: metadata.backend, addressbookid: metadata.addressbookid, contactid: metadata.contactid, path: path} + {backend: metadata.backend, addressBookId: metadata.addressBookId, contactId: metadata.contactId, path: path} ); - $.getJSON(url, function(response) { + var jqXHR = $.getJSON(url, function(response) { console.log('response', response); - if(response.status == 'success') { + response = self.storage.formatResponse(response, jqXHR); + if(!response.error) { self.editPhoto(metadata, response.data.tmp); } else { $(document).trigger('status.contacts.error', response); @@ -1471,13 +1472,13 @@ OC.Contacts = OC.Contacts || { var self = this; var url = OC.Router.generate( 'contacts_cache_contact_photo', - {backend: metadata.backend, addressbookid: metadata.addressbookid, contactid: metadata.contactid} + {backend: metadata.backend, addressBookId: metadata.addressBookId, contactId: metadata.contactId} ); console.log('url', url); - $.getJSON(url, function(response) { - if(response.status == 'success') { + var jqXHR = $.getJSON(url, function(response) { + response = self.storage.formatResponse(response, jqXHR) + if(!response.error) { self.editPhoto(metadata, response.data.tmp); - $('#edit_photo_dialog_img').html(response.data.page); } else { $(document).trigger('status.contacts.error', response); } @@ -1507,7 +1508,7 @@ OC.Contacts = OC.Contacts || { var $container = $('
').appendTo($('body')); var url = OC.Router.generate( 'contacts_crop_contact_photo', - {backend: metadata.backend, addressbookid: metadata.addressbookid, contactid: metadata.contactid, key: tmpkey} + {backend: metadata.backend, addressBookId: metadata.addressBookId, contactId: metadata.contactId, key: tmpkey} ); var $dlg = this.$cropBoxTmpl.octemplate( { @@ -1520,8 +1521,8 @@ OC.Contacts = OC.Contacts || { $.when(this.storage.getTempContactPhoto( metadata.backend, - metadata.addressbookid, - metadata.contactid, + metadata.addressBookId, + metadata.contactId, tmpkey )) .then(function(image) { @@ -1577,8 +1578,8 @@ OC.Contacts = OC.Contacts || { $target.on('load', function() { console.log('submitted'); var response = $.parseJSON($target.contents().text()); + console.log('response', response); if(response && response.status == 'success') { - console.log('response', response); $(document).trigger('status.contact.photoupdated', { id: response.data.id, thumbnail: response.data.thumbnail diff --git a/lib/controller/contactphotocontroller.php b/lib/controller/contactphotocontroller.php index 19b548cf..09209432 100644 --- a/lib/controller/contactphotocontroller.php +++ b/lib/controller/contactphotocontroller.php @@ -125,13 +125,16 @@ class ContactPhotoController extends Controller { return $response; } - $response->setParams(array( - 'tmp'=>$tmpkey, - 'metadata' => array( - 'contactId'=> $params['contactId'], - 'addressBookId'=> $params['addressBookId'], - 'backend'=> $params['backend'], - ), + $response->setData(array( + 'status' => 'success', + 'data' => array( + 'tmp'=>$tmpkey, + 'metadata' => array( + 'contactId'=> $params['contactId'], + 'addressBookId'=> $params['addressBookId'], + 'backend'=> $params['backend'], + ), + ) )); return $response; @@ -259,7 +262,7 @@ class ContactPhotoController extends Controller { $w = (isset($this->request->post['w']) && $this->request->post['w']) ? $this->request->post['w'] : -1; $h = (isset($this->request->post['h']) && $this->request->post['h']) ? $this->request->post['h'] : -1; $tmpkey = $params['key']; - $maxSize = isset($this->request->get['maxSize']) ? $this->request->post['maxSize'] : 200; + $maxSize = isset($this->request->post['maxSize']) ? $this->request->post['maxSize'] : 200; $app = new App($this->api->getUserId()); $addressBook = $app->getAddressBook($params['backend'], $params['addressBookId']); @@ -322,14 +325,19 @@ class ContactPhotoController extends Controller { $contact->add('PHOTO', strval($image), array('ENCODING' => 'b', 'TYPE' => $type)); + // TODO: Fix this hack + $contact->setSaved(false); } if(!$contact->save()) { return $response->bailOut(App::$l10n->t('Error saving contact.')); } $thumbnail = $contact->cacheThumbnail($image); - $response->setParams(array( - 'id' => $params['contactId'], - 'thumbnail' => $thumbnail, + $response->setData(array( + 'status' => 'success', + 'data' => array( + 'id' => $params['contactId'], + 'thumbnail' => $thumbnail, + ) )); $this->server->getCache()->remove($tmpkey);