"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:
return {
restrict: 'E',
template: '
',
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);
});
}
};
}]);
}());