1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2025-01-19 08:52:22 +01:00

Fix editing contact photos.

This commit is contained in:
Thomas Tanghus 2013-10-22 17:10:23 +02:00
parent 8ce15144c9
commit bf095621e0
3 changed files with 33 additions and 24 deletions

View File

@ -251,7 +251,7 @@ $this->create('contacts_cache_fs_photo', 'addressbook/{backend}/{addressBookId}/
$dispatcher->dispatch('ContactPhotoController', 'cacheFileSystemPhoto'); $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') $this->create('contacts_tmp_contact_photo', 'addressbook/{backend}/{addressBookId}/contact/{contactId}/photo/{key}/tmp')
->get() ->get()

View File

@ -744,7 +744,7 @@ OC.Contacts = OC.Contacts || {
var form = $('#file_upload_form'); var form = $('#file_upload_form');
var url = OC.Router.generate( var url = OC.Router.generate(
'contacts_upload_contact_photo', '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); form.attr('action', url);
}).on('change', function() { }).on('change', function() {
@ -1456,11 +1456,12 @@ OC.Contacts = OC.Contacts || {
console.log('cloudPhotoSelected', metadata); console.log('cloudPhotoSelected', metadata);
var url = OC.Router.generate( var url = OC.Router.generate(
'contacts_cache_fs_photo', '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); console.log('response', response);
if(response.status == 'success') { response = self.storage.formatResponse(response, jqXHR);
if(!response.error) {
self.editPhoto(metadata, response.data.tmp); self.editPhoto(metadata, response.data.tmp);
} else { } else {
$(document).trigger('status.contacts.error', response); $(document).trigger('status.contacts.error', response);
@ -1471,13 +1472,13 @@ OC.Contacts = OC.Contacts || {
var self = this; var self = this;
var url = OC.Router.generate( var url = OC.Router.generate(
'contacts_cache_contact_photo', '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); console.log('url', url);
$.getJSON(url, function(response) { var jqXHR = $.getJSON(url, function(response) {
if(response.status == 'success') { response = self.storage.formatResponse(response, jqXHR)
if(!response.error) {
self.editPhoto(metadata, response.data.tmp); self.editPhoto(metadata, response.data.tmp);
$('#edit_photo_dialog_img').html(response.data.page);
} else { } else {
$(document).trigger('status.contacts.error', response); $(document).trigger('status.contacts.error', response);
} }
@ -1507,7 +1508,7 @@ OC.Contacts = OC.Contacts || {
var $container = $('<div />').appendTo($('body')); var $container = $('<div />').appendTo($('body'));
var url = OC.Router.generate( var url = OC.Router.generate(
'contacts_crop_contact_photo', '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( var $dlg = this.$cropBoxTmpl.octemplate(
{ {
@ -1520,8 +1521,8 @@ OC.Contacts = OC.Contacts || {
$.when(this.storage.getTempContactPhoto( $.when(this.storage.getTempContactPhoto(
metadata.backend, metadata.backend,
metadata.addressbookid, metadata.addressBookId,
metadata.contactid, metadata.contactId,
tmpkey tmpkey
)) ))
.then(function(image) { .then(function(image) {
@ -1577,8 +1578,8 @@ OC.Contacts = OC.Contacts || {
$target.on('load', function() { $target.on('load', function() {
console.log('submitted'); console.log('submitted');
var response = $.parseJSON($target.contents().text()); var response = $.parseJSON($target.contents().text());
if(response && response.status == 'success') {
console.log('response', response); console.log('response', response);
if(response && response.status == 'success') {
$(document).trigger('status.contact.photoupdated', { $(document).trigger('status.contact.photoupdated', {
id: response.data.id, id: response.data.id,
thumbnail: response.data.thumbnail thumbnail: response.data.thumbnail

View File

@ -125,13 +125,16 @@ class ContactPhotoController extends Controller {
return $response; return $response;
} }
$response->setParams(array( $response->setData(array(
'status' => 'success',
'data' => array(
'tmp'=>$tmpkey, 'tmp'=>$tmpkey,
'metadata' => array( 'metadata' => array(
'contactId'=> $params['contactId'], 'contactId'=> $params['contactId'],
'addressBookId'=> $params['addressBookId'], 'addressBookId'=> $params['addressBookId'],
'backend'=> $params['backend'], 'backend'=> $params['backend'],
), ),
)
)); ));
return $response; 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; $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; $h = (isset($this->request->post['h']) && $this->request->post['h']) ? $this->request->post['h'] : -1;
$tmpkey = $params['key']; $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()); $app = new App($this->api->getUserId());
$addressBook = $app->getAddressBook($params['backend'], $params['addressBookId']); $addressBook = $app->getAddressBook($params['backend'], $params['addressBookId']);
@ -322,14 +325,19 @@ class ContactPhotoController extends Controller {
$contact->add('PHOTO', $contact->add('PHOTO',
strval($image), array('ENCODING' => 'b', strval($image), array('ENCODING' => 'b',
'TYPE' => $type)); 'TYPE' => $type));
// TODO: Fix this hack
$contact->setSaved(false);
} }
if(!$contact->save()) { if(!$contact->save()) {
return $response->bailOut(App::$l10n->t('Error saving contact.')); return $response->bailOut(App::$l10n->t('Error saving contact.'));
} }
$thumbnail = $contact->cacheThumbnail($image); $thumbnail = $contact->cacheThumbnail($image);
$response->setParams(array( $response->setData(array(
'status' => 'success',
'data' => array(
'id' => $params['contactId'], 'id' => $params['contactId'],
'thumbnail' => $thumbnail, 'thumbnail' => $thumbnail,
)
)); ));
$this->server->getCache()->remove($tmpkey); $this->server->getCache()->remove($tmpkey);