snappymail/dev/Models/AttachmentModel.js
RainLoop Team 4cc2207513 Uploading and preparing the repository to the dev version.
Original unminified source code (dev folder - js, css, less) (fixes #6)
Grunt build system
Multiple identities correction (fixes #9)
Compose html editor (fixes #12)
New general settings - Loading Description
New warning about default admin password
Split general and login screen settings
2013-11-16 02:21:12 +04:00

228 lines
5.8 KiB
JavaScript

/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
/**
* @constructor
*/
function AttachmentModel()
{
this.mimeType = '';
this.fileName = '';
this.estimatedSize = 0;
this.friendlySize = '';
this.isInline = false;
this.isLinked = false;
this.cid = '';
this.cidWithOutTags = '';
this.contentLocation = '';
this.download = '';
this.folder = '';
this.uid = '';
this.mimeIndex = '';
}
/**
* @static
* @param {AjaxJsonAttachment} oJsonAttachment
* @return {?AttachmentModel}
*/
AttachmentModel.newInstanceFromJson = function (oJsonAttachment)
{
var oAttachmentModel = new AttachmentModel();
return oAttachmentModel.initByJson(oJsonAttachment) ? oAttachmentModel : null;
};
AttachmentModel.prototype.mimeType = '';
AttachmentModel.prototype.fileName = '';
AttachmentModel.prototype.estimatedSize = 0;
AttachmentModel.prototype.friendlySize = '';
AttachmentModel.prototype.isInline = false;
AttachmentModel.prototype.isLinked = false;
AttachmentModel.prototype.cid = '';
AttachmentModel.prototype.cidWithOutTags = '';
AttachmentModel.prototype.contentLocation = '';
AttachmentModel.prototype.download = '';
AttachmentModel.prototype.folder = '';
AttachmentModel.prototype.uid = '';
AttachmentModel.prototype.mimeIndex = '';
/**
* @param {AjaxJsonAttachment} oJsonAttachment
*/
AttachmentModel.prototype.initByJson = function (oJsonAttachment)
{
var bResult = false;
if (oJsonAttachment && 'Object/Attachment' === oJsonAttachment['@Object'])
{
this.mimeType = oJsonAttachment.MimeType;
this.fileName = oJsonAttachment.FileName;
this.estimatedSize = Utils.pInt(oJsonAttachment.EstimatedSize);
this.isInline = !!oJsonAttachment.IsInline;
this.isLinked = !!oJsonAttachment.IsLinked;
this.cid = oJsonAttachment.CID;
this.contentLocation = oJsonAttachment.ContentLocation;
this.download = oJsonAttachment.Download;
this.folder = oJsonAttachment.Folder;
this.uid = oJsonAttachment.Uid;
this.mimeIndex = oJsonAttachment.MimeIndex;
this.friendlySize = Utils.friendlySize(this.estimatedSize);
this.cidWithOutTags = this.cid.replace(/^<+/, '').replace(/>+$/, '');
bResult = true;
}
return bResult;
};
/**
* @return {boolean}
*/
AttachmentModel.prototype.isImage = function ()
{
return -1 < Utils.inArray(this.mimeType.toLowerCase(),
['image/png', 'image/jpg', 'image/jpeg', 'image/gif']
);
};
/**
* @return {boolean}
*/
AttachmentModel.prototype.isText = function ()
{
return 'text/' === this.mimeType.substr(0, 5);
};
/**
* @return {string}
*/
AttachmentModel.prototype.linkDownload = function ()
{
return RL.link().attachmentDownload(this.download);
};
/**
* @return {string}
*/
AttachmentModel.prototype.linkPreview = function ()
{
return RL.link().attachmentPreview(this.download);
};
/**
* @return {string}
*/
AttachmentModel.prototype.linkPreviewAsPlain = function ()
{
return RL.link().attachmentPreviewAsPlain(this.download);
};
/**
* @return {string}
*/
AttachmentModel.prototype.generateTransferDownloadUrl = function ()
{
var sLink = this.linkDownload();
if ('http' !== sLink.substr(0, 4))
{
sLink = window.location.protocol + '//' + window.location.host + window.location.pathname + sLink;
}
return this.mimeType + ':' + this.fileName + ':' + sLink;
};
/**
* @param {AttachmentModel} oAttachment
* @param {*} oEvent
* @return {boolean}
*/
AttachmentModel.prototype.eventDragStart = function (oAttachment, oEvent)
{
var oLocalEvent = oEvent.originalEvent || oEvent;
if (oAttachment && oLocalEvent && oLocalEvent.dataTransfer && oLocalEvent.dataTransfer.setData)
{
oLocalEvent.dataTransfer.setData('DownloadURL', this.generateTransferDownloadUrl());
}
return true;
};
AttachmentModel.prototype.iconClass = function ()
{
var
aParts = this.mimeType.toLocaleString().split('/'),
sClass = 'icon-file'
;
if (aParts && aParts[1])
{
if ('image' === aParts[0])
{
sClass = 'icon-image';
}
else if ('text' === aParts[0])
{
sClass = 'icon-file-xml';
}
else if ('audio' === aParts[0])
{
sClass = 'icon-music';
}
else if ('video' === aParts[0])
{
sClass = 'icon-film';
}
else if (-1 < Utils.inArray(aParts[1],
['zip', '7z', 'tar', 'rar', 'gzip', 'bzip', 'bzip2', 'x-zip', 'x-7z', 'x-rar', 'x-tar', 'x-gzip', 'x-bzip', 'x-bzip2', 'x-zip-compressed', 'x-7z-compressed', 'x-rar-compressed']))
{
sClass = 'icon-file-zip';
}
else if (-1 < Utils.inArray(aParts[1],
['pdf', 'x-pdf']))
{
sClass = 'icon-file-pdf';
}
else if (-1 < Utils.inArray(aParts[1], [
'exe', 'x-exe', 'x-winexe', 'bat'
]))
{
sClass = 'icon-console';
}
else if (-1 < Utils.inArray(aParts[1], [
'rtf', 'msword', 'vnd.msword', 'vnd.openxmlformats-officedocument.wordprocessingml.document',
'vnd.openxmlformats-officedocument.wordprocessingml.template',
'vnd.ms-word.document.macroEnabled.12',
'vnd.ms-word.template.macroEnabled.12'
]))
{
sClass = 'icon-file-word';
}
else if (-1 < Utils.inArray(aParts[1], [
'excel', 'ms-excel', 'vnd.ms-excel',
'vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'vnd.openxmlformats-officedocument.spreadsheetml.template',
'vnd.ms-excel.sheet.macroEnabled.12',
'vnd.ms-excel.template.macroEnabled.12',
'vnd.ms-excel.addin.macroEnabled.12',
'vnd.ms-excel.sheet.binary.macroEnabled.12'
]))
{
sClass = 'icon-file-excel';
}
else if (-1 < Utils.inArray(aParts[1], [
'powerpoint', 'ms-powerpoint', 'vnd.ms-powerpoint',
'vnd.openxmlformats-officedocument.presentationml.presentation',
'vnd.openxmlformats-officedocument.presentationml.template',
'vnd.openxmlformats-officedocument.presentationml.slideshow',
'vnd.ms-powerpoint.addin.macroEnabled.12',
'vnd.ms-powerpoint.presentation.macroEnabled.12',
'vnd.ms-powerpoint.template.macroEnabled.12',
'vnd.ms-powerpoint.slideshow.macroEnabled.12'
]))
{
sClass = 'icon-file-powerpoint';
}
}
return sClass;
};