snappymail/dev/Common/Links.js

440 lines
10 KiB
JavaScript
Raw Normal View History

2014-09-05 06:49:03 +08:00
(function () {
2014-08-25 23:49:01 +08:00
'use strict';
2014-08-20 23:03:12 +08:00
var
window = require('window'),
2014-09-05 06:49:03 +08:00
Utils = require('Common/Utils')
2014-08-20 23:03:12 +08:00
;
2014-08-25 15:10:51 +08:00
2014-08-20 23:03:12 +08:00
/**
* @constructor
*/
2014-10-06 02:37:31 +08:00
function Links()
{
var Settings = require('Storage/Settings');
2014-08-25 15:10:51 +08:00
2014-08-20 23:03:12 +08:00
this.sBase = '#/';
this.sServer = './?';
2014-08-27 23:59:44 +08:00
this.sVersion = Settings.settingsGet('Version');
2015-05-06 00:41:15 +08:00
this.sAuthSuffix = Settings.settingsGet('AuthAccountHash') || '0';
2015-02-12 08:48:11 +08:00
this.sWebPrefix = Settings.settingsGet('WebPath') || '';
this.sVersionPrefix = Settings.settingsGet('WebVersionPath') || 'rainloop/v/' + this.sVersion + '/';
this.sStaticPrefix = this.sVersionPrefix + 'static/';
}
2015-05-06 00:41:15 +08:00
Links.prototype.populateAuthSuffix = function ()
{
this.sAuthSuffix = require('Storage/Settings').settingsGet('AuthAccountHash') || '0';
};
/**
* @return {string}
*/
Links.prototype.subQueryPrefix = function ()
{
return '&q[]=';
};
2014-08-20 23:03:12 +08:00
/**
2015-05-16 04:15:22 +08:00
* @param {string=} sStartupUrl
2014-08-20 23:03:12 +08:00
* @return {string}
*/
2015-05-16 04:15:22 +08:00
Links.prototype.root = function (sStartupUrl)
2014-08-20 23:03:12 +08:00
{
2015-05-16 04:15:22 +08:00
return this.sBase + Utils.pString(sStartupUrl);
2014-08-20 23:03:12 +08:00
};
2014-10-06 02:37:31 +08:00
/**
* @return {string}
*/
Links.prototype.rootAdmin = function ()
{
return this.sServer + '/Admin/';
};
2015-03-28 06:06:56 +08:00
/**
* @return {string}
*/
Links.prototype.rootUser = function ()
{
return './';
};
2014-08-20 23:03:12 +08:00
/**
* @param {string} sDownload
2015-04-25 06:15:11 +08:00
* @param {string=} sCustomSpecSuffix
2014-08-20 23:03:12 +08:00
* @return {string}
*/
2015-04-25 06:15:11 +08:00
Links.prototype.attachmentDownload = function (sDownload, sCustomSpecSuffix)
2014-08-20 23:03:12 +08:00
{
2015-05-06 00:41:15 +08:00
sCustomSpecSuffix = Utils.isUnd(sCustomSpecSuffix) ? this.sAuthSuffix : sCustomSpecSuffix;
2015-04-25 06:15:11 +08:00
return this.sServer + '/Raw/' + this.subQueryPrefix() + '/' + sCustomSpecSuffix + '/Download/' +
this.subQueryPrefix() + '/' + sDownload;
2014-08-20 23:03:12 +08:00
};
/**
* @param {string} sDownload
2015-04-25 06:15:11 +08:00
* @param {string=} sCustomSpecSuffix
2014-08-20 23:03:12 +08:00
* @return {string}
*/
2015-04-25 06:15:11 +08:00
Links.prototype.attachmentPreview = function (sDownload, sCustomSpecSuffix)
2014-08-20 23:03:12 +08:00
{
2015-05-06 00:41:15 +08:00
sCustomSpecSuffix = Utils.isUnd(sCustomSpecSuffix) ? this.sAuthSuffix : sCustomSpecSuffix;
2015-04-25 06:15:11 +08:00
return this.sServer + '/Raw/' + this.subQueryPrefix() + '/' + sCustomSpecSuffix + '/View/' +
this.subQueryPrefix() + '/' + sDownload;
2014-08-20 23:03:12 +08:00
};
/**
* @param {string} sDownload
2015-04-25 06:15:11 +08:00
* @param {string=} sCustomSpecSuffix
* @return {string}
*/
2015-04-25 06:15:11 +08:00
Links.prototype.attachmentThumbnailPreview = function (sDownload, sCustomSpecSuffix)
{
2015-05-06 00:41:15 +08:00
sCustomSpecSuffix = Utils.isUnd(sCustomSpecSuffix) ? this.sAuthSuffix : sCustomSpecSuffix;
2015-04-25 06:15:11 +08:00
return this.sServer + '/Raw/' + this.subQueryPrefix() + '/' + sCustomSpecSuffix + '/ViewThumbnail/' +
this.subQueryPrefix() + '/' + sDownload;
};
2014-08-20 23:03:12 +08:00
/**
* @param {string} sDownload
2015-04-25 06:15:11 +08:00
* @param {string=} sCustomSpecSuffix
2014-08-20 23:03:12 +08:00
* @return {string}
*/
2015-04-25 06:15:11 +08:00
Links.prototype.attachmentPreviewAsPlain = function (sDownload, sCustomSpecSuffix)
2014-08-20 23:03:12 +08:00
{
2015-05-06 00:41:15 +08:00
sCustomSpecSuffix = Utils.isUnd(sCustomSpecSuffix) ? this.sAuthSuffix : sCustomSpecSuffix;
2015-04-25 06:15:11 +08:00
return this.sServer + '/Raw/' + this.subQueryPrefix() + '/' + sCustomSpecSuffix + '/ViewAsPlain/' +
this.subQueryPrefix() + '/' + sDownload;
2014-08-20 23:03:12 +08:00
};
/**
* @param {string} sDownload
2015-04-25 06:15:11 +08:00
* @param {string=} sCustomSpecSuffix
* @return {string}
*/
2015-04-25 06:15:11 +08:00
Links.prototype.attachmentFramed = function (sDownload, sCustomSpecSuffix)
{
2015-05-06 00:41:15 +08:00
sCustomSpecSuffix = Utils.isUnd(sCustomSpecSuffix) ? this.sAuthSuffix : sCustomSpecSuffix;
2015-04-25 06:15:11 +08:00
return this.sServer + '/Raw/' + this.subQueryPrefix() + '/' + sCustomSpecSuffix + '/FramedView/' +
this.subQueryPrefix() + '/' + sDownload;
};
2014-08-20 23:03:12 +08:00
/**
* @return {string}
*/
2014-10-06 02:37:31 +08:00
Links.prototype.upload = function ()
{
2015-05-06 00:41:15 +08:00
return this.sServer + '/Upload/' + this.subQueryPrefix() + '/' + this.sAuthSuffix + '/';
2014-08-20 23:03:12 +08:00
};
/**
* @return {string}
*/
2014-10-06 02:37:31 +08:00
Links.prototype.uploadContacts = function ()
{
2015-05-06 00:41:15 +08:00
return this.sServer + '/UploadContacts/' + this.subQueryPrefix() + '/' + this.sAuthSuffix + '/';
2014-08-20 23:03:12 +08:00
};
/**
* @return {string}
*/
2014-10-06 02:37:31 +08:00
Links.prototype.uploadBackground = function ()
{
2015-05-06 00:41:15 +08:00
return this.sServer + '/UploadBackground/' + this.subQueryPrefix() + '/' + this.sAuthSuffix + '/';
2014-08-20 23:03:12 +08:00
};
2014-08-20 23:03:12 +08:00
/**
* @return {string}
*/
2014-10-06 02:37:31 +08:00
Links.prototype.append = function ()
{
2015-05-06 00:41:15 +08:00
return this.sServer + '/Append/' + this.subQueryPrefix() + '/' + this.sAuthSuffix + '/';
2014-08-20 23:03:12 +08:00
};
/**
* @param {string} sEmail
* @return {string}
*/
2014-10-06 02:37:31 +08:00
Links.prototype.change = function (sEmail)
2014-08-20 23:03:12 +08:00
{
2015-05-06 00:41:15 +08:00
return this.sServer + '/Change/' + this.subQueryPrefix() + '/' + this.sAuthSuffix + '/' + Utils.encodeURIComponent(sEmail) + '/';
2014-08-20 23:03:12 +08:00
};
/**
* @param {string=} sAdd
* @return {string}
*/
2014-10-06 02:37:31 +08:00
Links.prototype.ajax = function (sAdd)
2014-08-20 23:03:12 +08:00
{
2015-05-06 00:41:15 +08:00
return this.sServer + '/Ajax/' + this.subQueryPrefix() + '/' + this.sAuthSuffix + '/' + sAdd;
2014-08-20 23:03:12 +08:00
};
/**
* @param {string} sRequestHash
* @return {string}
*/
2014-10-06 02:37:31 +08:00
Links.prototype.messageViewLink = function (sRequestHash)
2014-08-20 23:03:12 +08:00
{
2015-05-06 00:41:15 +08:00
return this.sServer + '/Raw/' + this.subQueryPrefix() + '/' + this.sAuthSuffix + '/ViewAsPlain/' + this.subQueryPrefix() + '/' + sRequestHash;
2014-08-20 23:03:12 +08:00
};
/**
* @param {string} sRequestHash
* @return {string}
*/
2014-10-06 02:37:31 +08:00
Links.prototype.messageDownloadLink = function (sRequestHash)
2014-08-20 23:03:12 +08:00
{
2015-05-06 00:41:15 +08:00
return this.sServer + '/Raw/' + this.subQueryPrefix() + '/' + this.sAuthSuffix + '/Download/' + this.subQueryPrefix() + '/' + sRequestHash;
2014-08-20 23:03:12 +08:00
};
/**
* @param {string} sEmail
* @return {string}
*/
2014-10-06 02:37:31 +08:00
Links.prototype.avatarLink = function (sEmail)
2014-08-20 23:03:12 +08:00
{
2014-09-05 06:49:03 +08:00
return this.sServer + '/Raw/0/Avatar/' + Utils.encodeURIComponent(sEmail) + '/';
2014-08-20 23:03:12 +08:00
};
/**
* @param {string} sHash
* @return {string}
*/
Links.prototype.publicLink = function (sHash)
{
return this.sServer + '/Raw/0/Public/' + sHash + '/';
};
2014-08-20 23:03:12 +08:00
/**
2015-02-05 13:14:13 +08:00
* @param {string} sHash
* @return {string}
*/
Links.prototype.userBackground = function (sHash)
{
2015-05-06 00:41:15 +08:00
return this.sServer + '/Raw/' + this.subQueryPrefix() + '/' + this.sAuthSuffix +
'/UserBackground/' + this.subQueryPrefix() + '/' + sHash;
2015-02-05 13:14:13 +08:00
};
/**
* @param {string} sInboxFolderName = 'INBOX'
2014-08-20 23:03:12 +08:00
* @return {string}
*/
Links.prototype.inbox = function (sInboxFolderName)
2014-08-20 23:03:12 +08:00
{
sInboxFolderName = Utils.isUnd(sInboxFolderName) ? 'INBOX' : sInboxFolderName;
return this.sBase + 'mailbox/' + sInboxFolderName;
2014-08-20 23:03:12 +08:00
};
/**
* @param {string=} sScreenName
* @return {string}
*/
2014-10-06 02:37:31 +08:00
Links.prototype.settings = function (sScreenName)
2014-08-20 23:03:12 +08:00
{
var sResult = this.sBase + 'settings';
if (!Utils.isUnd(sScreenName) && '' !== sScreenName)
{
sResult += '/' + sScreenName;
}
return sResult;
};
2014-08-27 23:59:44 +08:00
/**
* @return {string}
*/
2014-10-06 02:37:31 +08:00
Links.prototype.about = function ()
2014-08-27 23:59:44 +08:00
{
return this.sBase + 'about';
};
2014-08-20 23:03:12 +08:00
/**
* @param {string} sScreenName
* @return {string}
*/
2014-10-06 02:37:31 +08:00
Links.prototype.admin = function (sScreenName)
2014-08-20 23:03:12 +08:00
{
var sResult = this.sBase;
switch (sScreenName) {
case 'AdminDomains':
sResult += 'domains';
break;
case 'AdminSecurity':
sResult += 'security';
break;
case 'AdminLicensing':
sResult += 'licensing';
break;
}
return sResult;
};
/**
* @param {string} sFolder
* @param {number=} iPage = 1
* @param {string=} sSearch = ''
2015-04-21 03:49:51 +08:00
* @param {string=} sThreadUid = ''
2014-08-20 23:03:12 +08:00
* @return {string}
*/
2015-04-21 03:49:51 +08:00
Links.prototype.mailBox = function (sFolder, iPage, sSearch, sThreadUid)
2014-08-20 23:03:12 +08:00
{
iPage = Utils.isNormal(iPage) ? Utils.pInt(iPage) : 1;
sSearch = Utils.pString(sSearch);
2015-04-21 03:49:51 +08:00
var
sResult = this.sBase + 'mailbox/',
iThreadUid = Utils.pInt(sThreadUid)
;
2014-08-20 23:03:12 +08:00
if ('' !== sFolder)
{
2015-04-21 06:39:14 +08:00
sResult += encodeURI(sFolder) + (0 < iThreadUid ? '~' + iThreadUid : '');
2014-08-20 23:03:12 +08:00
}
2015-04-21 03:49:51 +08:00
2014-08-20 23:03:12 +08:00
if (1 < iPage)
{
sResult = sResult.replace(/[\/]+$/, '');
sResult += '/p' + iPage;
}
2015-04-21 03:49:51 +08:00
2014-08-20 23:03:12 +08:00
if ('' !== sSearch)
{
sResult = sResult.replace(/[\/]+$/, '');
sResult += '/' + encodeURI(sSearch);
}
return sResult;
};
/**
* @return {string}
*/
2014-10-06 02:37:31 +08:00
Links.prototype.phpInfo = function ()
2014-08-20 23:03:12 +08:00
{
return this.sServer + 'Info';
};
/**
* @param {string} sLang
* @return {string}
*/
2015-03-28 06:06:56 +08:00
Links.prototype.langLink = function (sLang, bAdmin)
2014-08-20 23:03:12 +08:00
{
2015-03-28 06:06:56 +08:00
return this.sServer + '/Lang/0/' + (bAdmin ? 'Admin' : 'App') + '/' + encodeURI(sLang) + '/' + this.sVersion + '/';
2014-08-20 23:03:12 +08:00
};
/**
* @return {string}
*/
2014-10-06 02:37:31 +08:00
Links.prototype.exportContactsVcf = function ()
2014-08-20 23:03:12 +08:00
{
2015-05-06 00:41:15 +08:00
return this.sServer + '/Raw/' + this.subQueryPrefix() + '/' + this.sAuthSuffix + '/ContactsVcf/';
2014-08-20 23:03:12 +08:00
};
/**
* @return {string}
*/
2014-10-06 02:37:31 +08:00
Links.prototype.exportContactsCsv = function ()
2014-08-20 23:03:12 +08:00
{
2015-05-06 00:41:15 +08:00
return this.sServer + '/Raw/' + this.subQueryPrefix() + '/' + this.sAuthSuffix + '/ContactsCsv/';
2014-08-20 23:03:12 +08:00
};
/**
* @return {string}
*/
2014-10-06 02:37:31 +08:00
Links.prototype.emptyContactPic = function ()
2014-08-20 23:03:12 +08:00
{
return this.sStaticPrefix + 'css/images/empty-contact.png';
};
/**
* @param {string} sFileName
* @return {string}
*/
2014-10-06 02:37:31 +08:00
Links.prototype.sound = function (sFileName)
2014-08-20 23:03:12 +08:00
{
return this.sStaticPrefix + 'sounds/' + sFileName;
};
/**
* @param {string} sTheme
* @return {string}
*/
2014-10-06 02:37:31 +08:00
Links.prototype.themePreviewLink = function (sTheme)
2014-08-20 23:03:12 +08:00
{
2015-02-12 08:48:11 +08:00
var sPrefix = this.sVersionPrefix;
2014-08-20 23:03:12 +08:00
if ('@custom' === sTheme.substr(-7))
{
sTheme = Utils.trim(sTheme.substring(0, sTheme.length - 7));
2015-02-12 08:48:11 +08:00
sPrefix = this.sWebPrefix;
2014-08-20 23:03:12 +08:00
}
return sPrefix + 'themes/' + window.encodeURI(sTheme) + '/images/preview.png';
2014-08-20 23:03:12 +08:00
};
/**
* @return {string}
*/
2014-10-06 02:37:31 +08:00
Links.prototype.notificationMailIcon = function ()
2014-08-20 23:03:12 +08:00
{
return this.sStaticPrefix + 'css/images/icom-message-notification.png';
};
/**
* @return {string}
*/
2014-10-06 02:37:31 +08:00
Links.prototype.openPgpJs = function ()
2014-08-20 23:03:12 +08:00
{
2015-07-06 02:06:19 +08:00
return this.sStaticPrefix + 'js/min/openpgp.min.js';
};
/**
* @return {string}
*/
Links.prototype.openPgpWorkerJs = function ()
{
return this.sStaticPrefix + 'js/min/openpgp.worker.min.js';
};
/**
* @return {string}
*/
Links.prototype.openPgpWorkerPath = function ()
{
return this.sStaticPrefix + 'js/min/';
2014-08-20 23:03:12 +08:00
};
/**
* @param {boolean} bXAuth = false
2014-08-20 23:03:12 +08:00
* @return {string}
*/
Links.prototype.socialGoogle = function (bXAuth)
2014-08-20 23:03:12 +08:00
{
return this.sServer + 'SocialGoogle' + ('' !== this.sAuthSuffix ? '/' + this.subQueryPrefix() + '/' + this.sAuthSuffix + '/' : '') +
(bXAuth ? '&xauth=1' : '');
2014-08-20 23:03:12 +08:00
};
/**
* @return {string}
*/
2014-10-06 02:37:31 +08:00
Links.prototype.socialTwitter = function ()
2014-08-20 23:03:12 +08:00
{
2015-05-06 00:41:15 +08:00
return this.sServer + 'SocialTwitter' + ('' !== this.sAuthSuffix ? '/' + this.subQueryPrefix() + '/' + this.sAuthSuffix + '/' : '');
2014-08-20 23:03:12 +08:00
};
/**
* @return {string}
*/
2014-10-06 02:37:31 +08:00
Links.prototype.socialFacebook = function ()
2014-08-20 23:03:12 +08:00
{
2015-05-06 00:41:15 +08:00
return this.sServer + 'SocialFacebook' + ('' !== this.sAuthSuffix ? '/' + this.subQueryPrefix() + '/' + this.sAuthSuffix + '/' : '');
2014-08-20 23:03:12 +08:00
};
2014-10-06 02:37:31 +08:00
module.exports = new Links();
2014-09-05 06:49:03 +08:00
}());