From dd4ae60fa2f129b86ac43788b4fb654b37733f9c Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Wed, 29 Nov 2017 09:58:36 +0800 Subject: [PATCH] fix avatar/files update issues --- addressbook/inc/class.addressbook_ui.inc.php | 9 ++++-- api/js/etemplate/et2_widget_image.js | 32 ++++++++++++-------- api/src/Contacts.php | 1 + api/src/Contacts/Storage.php | 1 + 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/addressbook/inc/class.addressbook_ui.inc.php b/addressbook/inc/class.addressbook_ui.inc.php index 240010c77c..5fbde07286 100644 --- a/addressbook/inc/class.addressbook_ui.inc.php +++ b/addressbook/inc/class.addressbook_ui.inc.php @@ -3109,10 +3109,12 @@ window.egw_LAB.wait(function() { * Ajax method to update edited avatar photo via avatar widget * * @param int $contact_id - * @param file string $file = null null means to delete + * @param file string $file null means to delete + * @param string $etemplate_exec_id to update id, files, etag, ... */ - function ajax_update_photo ($contact_id, $file= null) + function ajax_update_photo ($contact_id, $file, $etemplate_exec_id) { + $et_request = Api\Etemplate\Request::read($etemplate_exec_id); $response = Api\Json\Response::get(); $contact = $this->read($contact_id); if ($file) @@ -3132,6 +3134,9 @@ window.egw_LAB.wait(function() { else { $response->data(true); + // merge changes (files, id, ...) into current eT request + unset($contact['jpegphoto'], $contact['photo_unchanged']); + $et_request->preserv = array_merge($et_request->preserv, $contact); } } diff --git a/api/js/etemplate/et2_widget_image.js b/api/js/etemplate/et2_widget_image.js index a52811d62f..4175ee8376 100644 --- a/api/js/etemplate/et2_widget_image.js +++ b/api/js/etemplate/et2_widget_image.js @@ -429,7 +429,7 @@ var et2_avatar = (function(){ "use strict"; return et2_image.extend( /** * Build Editable Mask Layer (EML) in order to show edit/delete actions * on top of profile picture. - * @param {boolean} disable delete button in initialization + * @param {boolean} _noDelete disable delete button in initialization */ _buildEditableLayer: function (_noDelete) { @@ -457,13 +457,16 @@ var et2_avatar = (function(){ "use strict"; return et2_image.extend( { var canvas = jQuery('#_cropper_image').cropper('getCroppedCanvas'); self.image.attr('src', canvas.toDataURL("image/jpeg", 1.0)); - egw.json('addressbook.addressbook_ui.ajax_update_photo', [self.options.contact_id, canvas.toDataURL('image/jpeg',1.0)], function(res){ - if (res) + self.egw().json('addressbook.addressbook_ui.ajax_update_photo', + [self.options.contact_id, canvas.toDataURL('image/jpeg',1.0), self.getInstanceManager().etemplate_exec_id], + function(res) { - del.show(); - egw.refresh('Avatar updated.', egw.app_name()); - } - }).sendRequest(); + if (res) + { + del.show(); + self.egw().refresh('Avatar updated.', egw.app_name()); + } + }).sendRequest(); } }, title: _title||egw.lang('Input required'), @@ -490,14 +493,17 @@ var et2_avatar = (function(){ "use strict"; return et2_image.extend( et2_dialog.show_dialog(function(_btn){ if (_btn == et2_dialog.YES_BUTTON) { - egw.json('addressbook.addressbook_ui.ajax_update_photo', [self.options.contact_id, null], function(res){ - if (res) + self.egw().json('addressbook.addressbook_ui.ajax_update_photo', + [self.options.contact_id, null, self.getInstanceManager().etemplate_exec_id], + function(res) { - self.image.attr('src',''); - del.hide(); + if (res) + { + self.image.attr('src',''); + del.hide(); egw.refresh('Avatar Deleted.', egw.app_name()); - } - }).sendRequest(); + } + }).sendRequest(); } }, egw.lang('Delete this photo?'), 'Delete', null, et2_dialog.BUTTONS_YES_NO); }) diff --git a/api/src/Contacts.php b/api/src/Contacts.php index 333919976c..26407f8fcd 100755 --- a/api/src/Contacts.php +++ b/api/src/Contacts.php @@ -994,6 +994,7 @@ class Contacts extends Contacts\Storage $contact['id'] = $to_write['id']; $contact['uid'] = $to_write['uid']; $contact['etag'] = $to_write['etag']; + $contact['files'] = $to_write['files']; // Clear any files saved with new entries // They've been dealt with already and they cause errors with linking diff --git a/api/src/Contacts/Storage.php b/api/src/Contacts/Storage.php index cf29d6e37c..40afd4ac31 100755 --- a/api/src/Contacts/Storage.php +++ b/api/src/Contacts/Storage.php @@ -575,6 +575,7 @@ class Storage $contact['id'] = $this->somain->data['id']; $contact['uid'] = $this->somain->data['uid']; $contact['etag'] = $this->somain->data['etag']; + $contact['files'] = $this->somain->data['files']; if ($this->contact_repository == 'sql-ldap') {