diff --git a/application/Espo/EntryPoints/Avatar.php b/application/Espo/EntryPoints/Avatar.php index 3d31bb936d..e6e33717bd 100644 --- a/application/Espo/EntryPoints/Avatar.php +++ b/application/Espo/EntryPoints/Avatar.php @@ -43,7 +43,16 @@ class Avatar extends Image if (!$user) { throw new NotFound(); } - $id = $user->get('avatarId'); + + if (isset($_GET['attachmentId'])) { + $id = $_GET['attachmentId']; + if ($id == 'false') { + $id = false; + } + } else { + $id = $user->get('avatarId'); + } + $size = null; if (!empty($_GET['size'])) { diff --git a/frontend/client/src/views/modals/image-crop.js b/frontend/client/src/views/modals/image-crop.js index f6f4b89474..76ad955b08 100644 --- a/frontend/client/src/views/modals/image-crop.js +++ b/frontend/client/src/views/modals/image-crop.js @@ -63,6 +63,13 @@ Espo.define('Views.Modals.ImageCrop', ['Views.Modal', 'lib!Cropper'], function ( }.bind(this) } ]; + + this.on('remove', function () { + if (this.$img.size()) { + this.$img.cropper('destroy'); + this.$img.parent().empty(); + } + }, this); }, afterRender: function () { diff --git a/frontend/client/src/views/user/fields/avatar.js b/frontend/client/src/views/user/fields/avatar.js index f85089e970..8283c5bd8e 100644 --- a/frontend/client/src/views/user/fields/avatar.js +++ b/frontend/client/src/views/user/fields/avatar.js @@ -23,7 +23,7 @@ Espo.define('Views.User.Fields.Avatar', 'Views.Fields.Image', function (Dep) { return Dep.extend({ handleFileUpload: function (file, contents, callback) { - + this.createView('crop', 'Modals.ImageCrop', { contents: contents }, function (view) { @@ -47,6 +47,7 @@ Espo.define('Views.User.Fields.Avatar', 'Views.Fields.Image', function (Dep) { this.render(); }.bind(this), 10); } + this.clearView('crop'); }.bind(this)); }.bind(this)); }, @@ -57,12 +58,20 @@ Espo.define('Views.User.Fields.Avatar', 'Views.Fields.Image', function (Dep) { var userId = this.model.id; var t = Date.now(); - - var imgHtml = ''; - if (!id) { + + var imgHtml; + + if (this.mode == 'detail') { + imgHtml = ''; + } else { + imgHtml = ''; + } + + if (id) { + return '' + imgHtml +' '; + } else { return imgHtml; } - return '' + imgHtml +' '; } },