Filter image

PHOTO EMBED

Thu Jan 25 2024 12:41:23 GMT+0000 (Coordinated Universal Time)

Saved by @Yous

function(i18n) {
	return {
		template: '<div ng-show="attachments.length > 0" class="sp-attachment-manager" >' +
								'<h2 style="display: inline" class="h5">{{::translations["Attachments"]}}</h2>' +
								'<button class="btn btn-link m-l" ng-show="::!omitEdit" ng-click="toggleEditMode()" aria-label="{{translations[\'Edit Attachments mode\']}}" aria-pressed={{editMode}}>{{getToggleName()}}</button>' +
								'<ul class="unstyled-list" aria-label="{{::translations[\'Attachments\']}}">' +
									'<li class="attached-file" ng-repeat="attachment in attachments  " ng-if="attachmentIsImage(attachment)">' +
										'<a ng-if="attachment.state === \'available\'" ng-href="{{getAttachmentURL(attachment)}}" target="_blank" aria-label="{{::getAriaLabel(attachment)}}" title="{{::getTitle(attachment)}}"><span class="fa {{getIcon(attachment)}}"></span>' +
										'{{attachment.file_name}}</a>' +
										'<a href="#" ng-if="attachment.state === \'pending\' || attachment.state === \'\' || attachment.state === \'available_conditionally\'" ng-click="scanAttachment(attachment)" aria-label="{{::getAriaLabel(attachment)}}" title="{{::getTitle(attachment)}}"><span class="fa {{getIcon(attachment)}}"></span>' +
										'{{attachment.file_name}}</a>' +
										'<span ng-if="attachment.state === \'not_available\'" aria-label="{{::translations[\'Attachment\']}}: {{attachment.file_name}}" title="{{::getTitle(attachment)}}" class="{{attachment.state}}">' +
										'{{attachment.file_name}} <span class="error">({{::translations[\'File failed security scan\']}})</span></span>' +
										'<button ng-show="editMode && attachment.canDelete" aria-label="{{::translations[\'Delete\']}} {{attachment.file_name}}" title="{{::translations[\'Delete\']}} {{attachment.file_name}}" data-toggle="tooltip" data-placement="top" ng-click="removeAttachment($event, attachment)" class="fa fa-times m-l-xs delete-attachment"></button>' +
									'</li>' +
								'</ul>' +
							'</div>',
		restrict: 'E',
		replace: true,
		scope: {
			table: "=",
			sysId: "=",
			omitEdit: "="
		},
		link: function(scope, elem, attr) {
			i18n.getMessages(['Attachment',
							  'Edit',
							  'Done',
							  'File failed security scan',
							  'Attachments',
							  'Delete',
							  'Attachment deleted successfully',
							  'View attachment',
							  'Download attachment',
							  'Edit Attachments mode'], function(msgArr){
				scope.translations = msgArr;
			});
		},
		controller: function($scope, snAttachmentHandler, spAriaUtil) {
			var cacheMap = {};
			
			$scope.attachments = [];
			$scope.translations = [];
			var attachmentHandler;

			function initializeAttachmentHandler() {
				$scope.editMode = false;
				
				var key = $scope.table + '.' + $scope.sysId;
				var cached = cacheMap[key];
				
				if(cached) {
					attachmentHandler = cached.handler;
					$scope.attachments = cached.attachments;
					return;
				}
				
				attachmentHandler = snAttachmentHandler.create($scope.table, $scope.sysId);
				attachmentHandler.getAttachments().then(function(response) {
					$scope.attachments = response;
					cacheMap[key] = {
						handler: attachmentHandler,
						attachments: $scope.attachments
					};
				});
			}


	
			$scope.attachmentIsImage = function(attachment)
            {
                var file_type = ['png', 'jpeg','jpg', 'tiff', 'gif']
                var file_name = attachment.file_name;
                var ext = file_name.split('.')[1];
                if(file_type.includes(ext.toLowerCase()))
                    return false;
                return true;
 
            }


			$scope.getIcon = function(attachment) {
				return attachment.encryption_context ? "fa-lock" : (extIconMap[attachment.ext] || fileIconMap[attachment.content_type] || "fa-file-o");
			}

			initializeAttachmentHandler();
		}
	};
}
content_copyCOPY