56 lines
2.4 KiB
JavaScript
56 lines
2.4 KiB
JavaScript
"use strict";
|
|
(function () {
|
|
'use strict';
|
|
angular.module('myitsmApp')
|
|
.directive('thumbnailImg', [function () {
|
|
return {
|
|
restrict: 'A',
|
|
replace: true,
|
|
priority: 99,
|
|
link: function (scope, element, attr) {
|
|
attr.$observe('thumbnailImg', function (value) {
|
|
var placeholderMap = {
|
|
user: 'styles/img/user-thumbnail-placeholder.png',
|
|
asset: 'styles/img/asset-thumbnail-placeholder.png',
|
|
attachment: 'styles/img/attachment-generic.png'
|
|
}, placeholder = angular.isDefined(attr.imgplaceholder) ? placeholderMap[attr.imgplaceholder] : attr.imgplaceholder;
|
|
var thumbnail;
|
|
if (value) {
|
|
thumbnail = new AttachmentVO().normalizeThumbnail(value);
|
|
}
|
|
var imgSrc = thumbnail ? thumbnail : placeholder;
|
|
if (!imgSrc) {
|
|
return;
|
|
}
|
|
attr.$set('src', imgSrc);
|
|
});
|
|
}
|
|
};
|
|
}])
|
|
.directive('userAvatar', [function () {
|
|
//usage: <user-avatar user="item.author" size="small"></user-avatar>
|
|
return {
|
|
restrict: 'E',
|
|
template: '<img class="app__person-avatar_{{size}}" alt="{{user.fullName}}" ng-src="/smartit/rest/v2/attachment/thumbnail/social/user/{{user.loginId}}/1?binary=true"/>',
|
|
scope: {
|
|
user: '=user',
|
|
size: '@'
|
|
},
|
|
link: function (scope, iElement) {
|
|
var defaultSize = 'small';
|
|
if (!scope.size) {
|
|
scope.size = defaultSize;
|
|
}
|
|
function onErrorHandler() {
|
|
this.src = 'styles/img/user-thumbnail-placeholder.png';
|
|
}
|
|
iElement.find('img').on('error', onErrorHandler);
|
|
scope.$on("$destroy", function () {
|
|
console.log("userAvatar: unbind events");
|
|
iElement.find('img').off('error', onErrorHandler);
|
|
});
|
|
}
|
|
};
|
|
}]);
|
|
}());
|