File: /home/barbeatleanalyti/www/public_html/webmail/modules/CoreWebclient/js/utils/Files.js
'use strict';
var
TextUtils = require('%PathToCoreWebclientModule%/js/utils/Text.js'),
Popups = require('%PathToCoreWebclientModule%/js/Popups.js'),
AlertPopup = require('%PathToCoreWebclientModule%/js/popups/AlertPopup.js'),
UserSettings = require('%PathToCoreWebclientModule%/js/Settings.js'),
FilesUtils = {}
;
/**
* Gets link for download by hash.
*
* @param {string} sModuleName Name of module that owns the file.
* @param {string} sHash Hash of the file.
* @param {string} sPublicHash Hash of shared folder if the file is displayed by public link.
*
* @return {string}
*/
FilesUtils.getDownloadLink = function (sModuleName, sHash, sPublicHash)
{
return sHash.length > 0 ? '?/Download/' + sModuleName + '/DownloadFile/' + sHash + '/' + (sPublicHash ? '0/' + sPublicHash : '') : '';
};
/**
* Gets link for view by hash in iframe.
*
* @param {number} iAccountId
* @param {string} sUrl
*
* @return {string}
*/
FilesUtils.getIframeWrappwer = function (iAccountId, sUrl)
{
return '?/Raw/Iframe/' + iAccountId + '/' + window.encodeURIComponent(sUrl) + '/';
};
FilesUtils.thumbQueue = (function () {
var
oImages = {},
oImagesIncrements = {},
iNumberOfImages = 2
;
return function (sSessionUid, sImageSrc, fImageSrcObserver)
{
if(sImageSrc && fImageSrcObserver)
{
if(!(sSessionUid in oImagesIncrements) || oImagesIncrements[sSessionUid] > 0) //load first images
{
if(!(sSessionUid in oImagesIncrements)) //on first image
{
oImagesIncrements[sSessionUid] = iNumberOfImages;
oImages[sSessionUid] = [];
}
oImagesIncrements[sSessionUid]--;
fImageSrcObserver(sImageSrc); //load image
}
else //create queue
{
oImages[sSessionUid].push({
imageSrc: sImageSrc,
imageSrcObserver: fImageSrcObserver,
messageUid: sSessionUid
});
}
}
else //load images from queue (fires load event)
{
if(oImages[sSessionUid] && oImages[sSessionUid].length)
{
oImages[sSessionUid][0].imageSrcObserver(oImages[sSessionUid][0].imageSrc);
oImages[sSessionUid].shift();
}
}
};
}());
/**
* @param {string} sFileName
* @param {number} iSize
* @returns {Boolean}
*/
FilesUtils.showErrorIfAttachmentSizeLimit = function (sFileName, iSize)
{
var
sWarning = TextUtils.i18n('%MODULENAME%/ERROR_UPLOAD_SIZE_DETAILED', {
'FILENAME': sFileName,
'MAXSIZE': TextUtils.getFriendlySize(UserSettings.AttachmentSizeLimit)
})
;
if (UserSettings.AttachmentSizeLimit > 0 && iSize > UserSettings.AttachmentSizeLimit)
{
Popups.showPopup(AlertPopup, [sWarning]);
return true;
}
return false;
};
module.exports = FilesUtils;