fix avatar

This commit is contained in:
Yuri Kuznetsov
2014-12-01 16:58:09 +02:00
parent 344f0227e9
commit 63a9f67bd9
3 changed files with 31 additions and 6 deletions
+10 -1
View File
@@ -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'])) {
@@ -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 () {
@@ -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 = '<img src="?entryPoint=avatar&size=' + this.previewSize + '&id=' + userId + '&t=' + t + '">';
if (!id) {
var imgHtml;
if (this.mode == 'detail') {
imgHtml = '<img src="?entryPoint=avatar&size=' + this.previewSize + '&id=' + userId + '&t=' + t + '&attachmentId=' + ( id || 'false') + '">';
} else {
imgHtml = '<img src="?entryPoint=avatar&size=' + this.previewSize + '&id=' + userId + '&t=' + t + '">';
}
if (id) {
return '<a data-action="showImagePreview" data-id="' + id + '" href="?entryPoint=image&id=' + id + '">' + imgHtml +' </a>';
} else {
return imgHtml;
}
return '<a data-action="showImagePreview" data-id="' + id + '" href="?entryPoint=image&id=' + id + '">' + imgHtml +' </a>';
}
},