]*>([\s\S\r\n]*)<\/div>/gmi, convertDivs);
sText = '\n' + $.trim(sText) + '\n';
}
return sText;
}
return '';
},
convertPre = function () {
return (arguments && 1 < arguments.length) ? arguments[1].toString().replace(/[\n]/gm, '
') : '';
},
fixAttibuteValue = function () {
return (arguments && 1 < arguments.length) ?
'' + arguments[1] + arguments[2].replace(//g, '>') : '';
},
convertLinks = function () {
return (arguments && 1 < arguments.length) ? $.trim(arguments[1]) : '';
}
;
sText = sHtml
.replace(/
]*>([\s\S\r\n]*)<\/pre>/gmi, convertPre)
.replace(/[\s]+/gm, ' ')
.replace(/((?:href|data)\s?=\s?)("[^"]+?"|'[^']+?')/gmi, fixAttibuteValue)
.replace(/
]*>/gmi, '\n')
.replace(/<\/h[\d]>/gi, '\n')
.replace(/<\/p>/gi, '\n\n')
.replace(/<\/li>/gi, '\n')
.replace(/<\/td>/gi, '\n')
.replace(/<\/tr>/gi, '\n')
.replace(/
]*>/gmi, '\n_______________________________\n\n')
.replace(/]*>([\s\S\r\n]*)<\/div>/gmi, convertDivs)
.replace(/
]*>/gmi, '\n__bq__start__\n')
.replace(/<\/blockquote>/gmi, '\n__bq__end__\n')
.replace(/]*>([\s\S\r\n]*?)<\/a>/gmi, convertLinks)
.replace(/<\/div>/gi, '\n')
.replace(/ /gi, ' ')
.replace(/"/gi, '"')
.replace(/<[^>]*>/gm, '')
;
sText = Utils.$div.html(sText).text();
sText = sText
.replace(/\n[ \t]+/gm, '\n')
.replace(/[\n]{3,}/gm, '\n\n')
.replace(/>/gi, '>')
.replace(/</gi, '<')
.replace(/&/gi, '&')
;
iPos = 0;
iLimit = 100;
while (0 < iLimit)
{
iLimit--;
iP1 = sText.indexOf('__bq__start__', iPos);
if (-1 < iP1)
{
iP2 = sText.indexOf('__bq__start__', iP1 + 5);
iP3 = sText.indexOf('__bq__end__', iP1 + 5);
if ((-1 === iP2 || iP3 < iP2) && iP1 < iP3)
{
sText = sText.substring(0, iP1) +
convertBlockquote(sText.substring(iP1 + 13, iP3)) +
sText.substring(iP3 + 11);
iPos = 0;
}
else if (-1 < iP2 && iP2 < iP3)
{
iPos = iP2 - 1;
}
else
{
iPos = 0;
}
}
else
{
break;
}
}
sText = sText
.replace(/__bq__start__/gm, '')
.replace(/__bq__end__/gm, '')
;
return sText;
};
/**
* @param {string} sPlain
* @param {boolean} bLinkify = false
* @return {string}
*/
Utils.plainToHtml = function (sPlain, bLinkify)
{
sPlain = sPlain.toString().replace(/\r/g, '');
var
bIn = false,
bDo = true,
bStart = true,
aNextText = [],
sLine = '',
iIndex = 0,
aText = sPlain.split("\n")
;
do
{
bDo = false;
aNextText = [];
for (iIndex = 0; iIndex < aText.length; iIndex++)
{
sLine = aText[iIndex];
bStart = '>' === sLine.substr(0, 1);
if (bStart && !bIn)
{
bDo = true;
bIn = true;
aNextText.push('~~~blockquote~~~');
aNextText.push(sLine.substr(1));
}
else if (!bStart && bIn)
{
bIn = false;
aNextText.push('~~~/blockquote~~~');
aNextText.push(sLine);
}
else if (bStart && bIn)
{
aNextText.push(sLine.substr(1));
}
else
{
aNextText.push(sLine);
}
}
if (bIn)
{
bIn = false;
aNextText.push('~~~/blockquote~~~');
}
aText = aNextText;
}
while (bDo);
sPlain = aText.join("\n");
sPlain = sPlain
.replace(/&/g, '&')
.replace(/>/g, '>').replace(/')
.replace(/[\s]*~~~\/blockquote~~~/g, '
')
.replace(/[\-_~]{10,}/g, '
')
.replace(/\n/g, '
');
return bLinkify ? Utils.linkify(sPlain) : sPlain;
};
window.rainloop_Utils_htmlToPlain = Utils.htmlToPlain;
window.rainloop_Utils_plainToHtml = Utils.plainToHtml;
/**
* @param {string} sHtml
* @return {string}
*/
Utils.linkify = function (sHtml)
{
if ($.fn && $.fn.linkify)
{
sHtml = Utils.$div.html(sHtml.replace(/&/ig, 'amp_amp_12345_amp_amp'))
.linkify()
.find('.linkified').removeClass('linkified').end()
.html()
.replace(/amp_amp_12345_amp_amp/g, '&')
;
}
return sHtml;
};
Utils.resizeAndCrop = function (sUrl, iValue, fCallback)
{
var oTempImg = new window.Image();
oTempImg.onload = function() {
var
aDiff = [0, 0],
oCanvas = document.createElement('canvas'),
oCtx = oCanvas.getContext('2d')
;
oCanvas.width = iValue;
oCanvas.height = iValue;
if (this.width > this.height)
{
aDiff = [this.width - this.height, 0];
}
else
{
aDiff = [0, this.height - this.width];
}
oCtx.fillStyle = '#fff';
oCtx.fillRect(0, 0, iValue, iValue);
oCtx.drawImage(this, aDiff[0] / 2, aDiff[1] / 2, this.width - aDiff[0], this.height - aDiff[1], 0, 0, iValue, iValue);
fCallback(oCanvas.toDataURL('image/jpeg'));
};
oTempImg.src = sUrl;
};
Utils.computedPagenatorHelper = function (koCurrentPage, koPageCount)
{
return function() {
var
iPrev = 0,
iNext = 0,
iLimit = 2,
aResult = [],
iCurrentPage = koCurrentPage(),
iPageCount = koPageCount(),
/**
* @param {number} iIndex
* @param {boolean=} bPush
* @param {string=} sCustomName
*/
fAdd = function (iIndex, bPush, sCustomName) {
var oData = {
'current': iIndex === iCurrentPage,
'name': Utils.isUnd(sCustomName) ? iIndex.toString() : sCustomName.toString(),
'custom': Utils.isUnd(sCustomName) ? false : true,
'title': Utils.isUnd(sCustomName) ? '' : iIndex.toString(),
'value': iIndex.toString()
};
if (Utils.isUnd(bPush) ? true : !!bPush)
{
aResult.push(oData);
}
else
{
aResult.unshift(oData);
}
}
;
if (1 < iPageCount || (0 < iPageCount && iPageCount < iCurrentPage))
// if (0 < iPageCount && 0 < iCurrentPage)
{
if (iPageCount < iCurrentPage)
{
fAdd(iPageCount);
iPrev = iPageCount;
iNext = iPageCount;
}
else
{
if (3 >= iCurrentPage || iPageCount - 2 <= iCurrentPage)
{
iLimit += 2;
}
fAdd(iCurrentPage);
iPrev = iCurrentPage;
iNext = iCurrentPage;
}
while (0 < iLimit) {
iPrev -= 1;
iNext += 1;
if (0 < iPrev)
{
fAdd(iPrev, false);
iLimit--;
}
if (iPageCount >= iNext)
{
fAdd(iNext, true);
iLimit--;
}
else if (0 >= iPrev)
{
break;
}
}
if (3 === iPrev)
{
fAdd(2, false);
}
else if (3 < iPrev)
{
fAdd(window.Math.round((iPrev - 1) / 2), false, '...');
}
if (iPageCount - 2 === iNext)
{
fAdd(iPageCount - 1, true);
}
else if (iPageCount - 2 > iNext)
{
fAdd(window.Math.round((iPageCount + iNext) / 2), true, '...');
}
// first and last
if (1 < iPrev)
{
fAdd(1, false);
}
if (iPageCount > iNext)
{
fAdd(iPageCount, true);
}
}
return aResult;
};
};
Utils.selectElement = function (element)
{
/* jshint onevar: false */
if (window.getSelection)
{
var sel = window.getSelection();
sel.removeAllRanges();
var range = window.document.createRange();
range.selectNodeContents(element);
sel.addRange(range);
}
else if (window.document.selection)
{
var textRange = window.document.body.createTextRange();
textRange.moveToElementText(element);
textRange.select();
}
/* jshint onevar: true */
};
Utils.disableKeyFilter = function (Data)
{
if (window.key)
{
key.filter = function () {
return Data.useKeyboardShortcuts();
};
}
};
Utils.restoreKeyFilter = function (Data)
{
if (window.key)
{
key.filter = function (event) {
if (Data.useKeyboardShortcuts())
{
var
oElement = event.target || event.srcElement,
sTagName = oElement ? oElement.tagName : ''
;
sTagName = sTagName.toUpperCase();
return !(sTagName === 'INPUT' || sTagName === 'SELECT' || sTagName === 'TEXTAREA' ||
(oElement && sTagName === 'DIV' && 'editorHtmlArea' === oElement.className && oElement.contentEditable)
);
}
return false;
};
}
};
Utils.detectDropdownVisibility = _.debounce(function () {
Globals.dropdownVisibility(!!_.find(Globals.aBootstrapDropdowns, function (oItem) {
return oItem.hasClass('open');
}));
}, 50);
Utils.triggerAutocompleteInputChange = function (bDelay) {
var fFunc = function () {
$('.checkAutocomplete').trigger('change');
};
if (bDelay)
{
_.delay(fFunc, 100);
}
else
{
fFunc();
}
};
module.exports = Utils;
}(module));
// Base64 encode / decode
// http://www.webtoolkit.info/
(function (module) {
'use strict';
/*jslint bitwise: true*/
var Base64 = {
// private property
_keyStr : 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',
// public method for urlsafe encoding
urlsafe_encode : function (input) {
return Base64.encode(input).replace(/[+]/g, '-').replace(/[\/]/g, '_').replace(/[=]/g, '.');
},
// public method for encoding
encode : function (input) {
var
output = '',
chr1, chr2, chr3, enc1, enc2, enc3, enc4,
i = 0
;
input = Base64._utf8_encode(input);
while (i < input.length)
{
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2))
{
enc3 = enc4 = 64;
}
else if (isNaN(chr3))
{
enc4 = 64;
}
output = output +
this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
}
return output;
},
// public method for decoding
decode : function (input) {
var
output = '',
chr1, chr2, chr3, enc1, enc2, enc3, enc4,
i = 0
;
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, '');
while (i < input.length)
{
enc1 = this._keyStr.indexOf(input.charAt(i++));
enc2 = this._keyStr.indexOf(input.charAt(i++));
enc3 = this._keyStr.indexOf(input.charAt(i++));
enc4 = this._keyStr.indexOf(input.charAt(i++));
chr1 = (enc1 << 2) | (enc2 >> 4);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
chr3 = ((enc3 & 3) << 6) | enc4;
output = output + String.fromCharCode(chr1);
if (enc3 !== 64)
{
output = output + String.fromCharCode(chr2);
}
if (enc4 !== 64)
{
output = output + String.fromCharCode(chr3);
}
}
return Base64._utf8_decode(output);
},
// private method for UTF-8 encoding
_utf8_encode : function (string) {
string = string.replace(/\r\n/g, "\n");
var
utftext = '',
n = 0,
l = string.length,
c = 0
;
for (; n < l; n++) {
c = string.charCodeAt(n);
if (c < 128)
{
utftext += String.fromCharCode(c);
}
else if ((c > 127) && (c < 2048))
{
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
}
else
{
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}
}
return utftext;
},
// private method for UTF-8 decoding
_utf8_decode : function (utftext) {
var
string = '',
i = 0,
c = 0,
c2 = 0,
c3 = 0
;
while ( i < utftext.length )
{
c = utftext.charCodeAt(i);
if (c < 128)
{
string += String.fromCharCode(c);
i++;
}
else if((c > 191) && (c < 224))
{
c2 = utftext.charCodeAt(i+1);
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
i += 2;
}
else
{
c2 = utftext.charCodeAt(i+1);
c3 = utftext.charCodeAt(i+2);
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
i += 3;
}
}
return string;
}
};
module.exports = Base64;
/*jslint bitwise: false*/
}(module));
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module) {
'use strict';
var
window = require('../External/window.js'),
Utils = require('./Utils.js')
;
/**
* @constructor
*/
function LinkBuilder()
{
this.sBase = '#/';
this.sServer = './?';
this.sVersion = RL.settingsGet('Version');
this.sSpecSuffix = RL.settingsGet('AuthAccountHash') || '0';
this.sStaticPrefix = RL.settingsGet('StaticPrefix') || 'rainloop/v/' + this.sVersion + '/static/';
}
/**
* @return {string}
*/
LinkBuilder.prototype.root = function ()
{
return this.sBase;
};
/**
* @param {string} sDownload
* @return {string}
*/
LinkBuilder.prototype.attachmentDownload = function (sDownload)
{
return this.sServer + '/Raw/' + this.sSpecSuffix + '/Download/' + sDownload;
};
/**
* @param {string} sDownload
* @return {string}
*/
LinkBuilder.prototype.attachmentPreview = function (sDownload)
{
return this.sServer + '/Raw/' + this.sSpecSuffix + '/View/' + sDownload;
};
/**
* @param {string} sDownload
* @return {string}
*/
LinkBuilder.prototype.attachmentPreviewAsPlain = function (sDownload)
{
return this.sServer + '/Raw/' + this.sSpecSuffix + '/ViewAsPlain/' + sDownload;
};
/**
* @return {string}
*/
LinkBuilder.prototype.upload = function ()
{
return this.sServer + '/Upload/' + this.sSpecSuffix + '/';
};
/**
* @return {string}
*/
LinkBuilder.prototype.uploadContacts = function ()
{
return this.sServer + '/UploadContacts/' + this.sSpecSuffix + '/';
};
/**
* @return {string}
*/
LinkBuilder.prototype.uploadBackground = function ()
{
return this.sServer + '/UploadBackground/' + this.sSpecSuffix + '/';
};
/**
* @return {string}
*/
LinkBuilder.prototype.append = function ()
{
return this.sServer + '/Append/' + this.sSpecSuffix + '/';
};
/**
* @param {string} sEmail
* @return {string}
*/
LinkBuilder.prototype.change = function (sEmail)
{
return this.sServer + '/Change/' + this.sSpecSuffix + '/' + window.encodeURIComponent(sEmail) + '/';
};
/**
* @param {string=} sAdd
* @return {string}
*/
LinkBuilder.prototype.ajax = function (sAdd)
{
return this.sServer + '/Ajax/' + this.sSpecSuffix + '/' + sAdd;
};
/**
* @param {string} sRequestHash
* @return {string}
*/
LinkBuilder.prototype.messageViewLink = function (sRequestHash)
{
return this.sServer + '/Raw/' + this.sSpecSuffix + '/ViewAsPlain/' + sRequestHash;
};
/**
* @param {string} sRequestHash
* @return {string}
*/
LinkBuilder.prototype.messageDownloadLink = function (sRequestHash)
{
return this.sServer + '/Raw/' + this.sSpecSuffix + '/Download/' + sRequestHash;
};
/**
* @param {string} sEmail
* @return {string}
*/
LinkBuilder.prototype.avatarLink = function (sEmail)
{
return this.sServer + '/Raw/0/Avatar/' + window.encodeURIComponent(sEmail) + '/';
// return '//secure.gravatar.com/avatar/' + Utils.md5(sEmail.toLowerCase()) + '.jpg?s=80&d=mm';
};
/**
* @return {string}
*/
LinkBuilder.prototype.inbox = function ()
{
return this.sBase + 'mailbox/Inbox';
};
/**
* @return {string}
*/
LinkBuilder.prototype.messagePreview = function ()
{
return this.sBase + 'mailbox/message-preview';
};
/**
* @param {string=} sScreenName
* @return {string}
*/
LinkBuilder.prototype.settings = function (sScreenName)
{
var sResult = this.sBase + 'settings';
if (!Utils.isUnd(sScreenName) && '' !== sScreenName)
{
sResult += '/' + sScreenName;
}
return sResult;
};
/**
* @param {string} sScreenName
* @return {string}
*/
LinkBuilder.prototype.admin = function (sScreenName)
{
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 = ''
* @return {string}
*/
LinkBuilder.prototype.mailBox = function (sFolder, iPage, sSearch)
{
iPage = Utils.isNormal(iPage) ? Utils.pInt(iPage) : 1;
sSearch = Utils.pString(sSearch);
var sResult = this.sBase + 'mailbox/';
if ('' !== sFolder)
{
sResult += encodeURI(sFolder);
}
if (1 < iPage)
{
sResult = sResult.replace(/[\/]+$/, '');
sResult += '/p' + iPage;
}
if ('' !== sSearch)
{
sResult = sResult.replace(/[\/]+$/, '');
sResult += '/' + encodeURI(sSearch);
}
return sResult;
};
/**
* @return {string}
*/
LinkBuilder.prototype.phpInfo = function ()
{
return this.sServer + 'Info';
};
/**
* @param {string} sLang
* @return {string}
*/
LinkBuilder.prototype.langLink = function (sLang)
{
return this.sServer + '/Lang/0/' + encodeURI(sLang) + '/' + this.sVersion + '/';
};
/**
* @return {string}
*/
LinkBuilder.prototype.exportContactsVcf = function ()
{
return this.sServer + '/Raw/' + this.sSpecSuffix + '/ContactsVcf/';
};
/**
* @return {string}
*/
LinkBuilder.prototype.exportContactsCsv = function ()
{
return this.sServer + '/Raw/' + this.sSpecSuffix + '/ContactsCsv/';
};
/**
* @return {string}
*/
LinkBuilder.prototype.emptyContactPic = function ()
{
return this.sStaticPrefix + 'css/images/empty-contact.png';
};
/**
* @param {string} sFileName
* @return {string}
*/
LinkBuilder.prototype.sound = function (sFileName)
{
return this.sStaticPrefix + 'sounds/' + sFileName;
};
/**
* @param {string} sTheme
* @return {string}
*/
LinkBuilder.prototype.themePreviewLink = function (sTheme)
{
var sPrefix = 'rainloop/v/' + this.sVersion + '/';
if ('@custom' === sTheme.substr(-7))
{
sTheme = Utils.trim(sTheme.substring(0, sTheme.length - 7));
sPrefix = '';
}
return sPrefix + 'themes/' + encodeURI(sTheme) + '/images/preview.png';
};
/**
* @return {string}
*/
LinkBuilder.prototype.notificationMailIcon = function ()
{
return this.sStaticPrefix + 'css/images/icom-message-notification.png';
};
/**
* @return {string}
*/
LinkBuilder.prototype.openPgpJs = function ()
{
return this.sStaticPrefix + 'js/openpgp.min.js';
};
/**
* @return {string}
*/
LinkBuilder.prototype.socialGoogle = function ()
{
return this.sServer + 'SocialGoogle' + ('' !== this.sSpecSuffix ? '/' + this.sSpecSuffix + '/' : '');
};
/**
* @return {string}
*/
LinkBuilder.prototype.socialTwitter = function ()
{
return this.sServer + 'SocialTwitter' + ('' !== this.sSpecSuffix ? '/' + this.sSpecSuffix + '/' : '');
};
/**
* @return {string}
*/
LinkBuilder.prototype.socialFacebook = function ()
{
return this.sServer + 'SocialFacebook' + ('' !== this.sSpecSuffix ? '/' + this.sSpecSuffix + '/' : '');
};
module.exports = new LinkBuilder();
}(module));
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module) {
'use strict';
var
Plugins = {
__boot: null,
__remote: null,
__data: null
},
_ = require('../External/underscore.js'),
Utils = require('./Utils.js')
;
/**
* @type {Object}
*/
Plugins.oViewModelsHooks = {};
/**
* @type {Object}
*/
Plugins.oSimpleHooks = {};
/**
* @param {string} sName
* @param {Function} ViewModel
*/
Plugins.regViewModelHook = function (sName, ViewModel)
{
if (ViewModel)
{
ViewModel.__hookName = sName;
}
};
/**
* @param {string} sName
* @param {Function} fCallback
*/
Plugins.addHook = function (sName, fCallback)
{
if (Utils.isFunc(fCallback))
{
if (!Utils.isArray(Plugins.oSimpleHooks[sName]))
{
Plugins.oSimpleHooks[sName] = [];
}
Plugins.oSimpleHooks[sName].push(fCallback);
}
};
/**
* @param {string} sName
* @param {Array=} aArguments
*/
Plugins.runHook = function (sName, aArguments)
{
if (Utils.isArray(Plugins.oSimpleHooks[sName]))
{
aArguments = aArguments || [];
_.each(Plugins.oSimpleHooks[sName], function (fCallback) {
fCallback.apply(null, aArguments);
});
}
};
/**
* @param {string} sName
* @return {?}
*/
Plugins.mainSettingsGet = function (sName)
{
if (Plugins.__boot)
{
return Plugins.__boot.settingsGet(sName);
}
return null;
};
/**
* @param {Function} fCallback
* @param {string} sAction
* @param {Object=} oParameters
* @param {?number=} iTimeout
* @param {string=} sGetAdd = ''
* @param {Array=} aAbortActions = []
*/
Plugins.remoteRequest = function (fCallback, sAction, oParameters, iTimeout, sGetAdd, aAbortActions)
{
if (Plugins.__remote)
{
Plugins.__remote.defaultRequest(fCallback, sAction, oParameters, iTimeout, sGetAdd, aAbortActions);
}
};
/**
* @param {string} sPluginSection
* @param {string} sName
* @return {?}
*/
Plugins.settingsGet = function (sPluginSection, sName)
{
var oPlugin = Plugins.mainSettingsGet('Plugins');
oPlugin = oPlugin && Utils.isUnd(oPlugin[sPluginSection]) ? null : oPlugin[sPluginSection];
return oPlugin ? (Utils.isUnd(oPlugin[sName]) ? null : oPlugin[sName]) : null;
};
module.exports = Plugins;
}(module));
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module) {
'use strict';
var
$ = require('../../External/jquery.js'),
JSON = require('../../External/JSON.js'),
Consts = require('../../Common/Consts.js'),
Utils = require('../../Common/Utils.js')
;
/**
* @constructor
*/
function CookieDriver()
{
}
CookieDriver.supported = function ()
{
return true;
};
/**
* @param {string} sKey
* @param {*} mData
* @returns {boolean}
*/
CookieDriver.prototype.set = function (sKey, mData)
{
var
mCokieValue = $.cookie(Consts.Values.ClientSideCookieIndexName),
bResult = false,
mResult = null
;
try
{
mResult = null === mCokieValue ? null : JSON.parse(mCokieValue);
if (!mResult)
{
mResult = {};
}
mResult[sKey] = mData;
$.cookie(Consts.Values.ClientSideCookieIndexName, JSON.stringify(mResult), {
'expires': 30
});
bResult = true;
}
catch (oException) {}
return bResult;
};
/**
* @param {string} sKey
* @returns {*}
*/
CookieDriver.prototype.get = function (sKey)
{
var
mCokieValue = $.cookie(Consts.Values.ClientSideCookieIndexName),
mResult = null
;
try
{
mResult = null === mCokieValue ? null : JSON.parse(mCokieValue);
if (mResult && !Utils.isUnd(mResult[sKey]))
{
mResult = mResult[sKey];
}
else
{
mResult = null;
}
}
catch (oException) {}
return mResult;
};
module.exports = CookieDriver;
}(module));
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module) {
'use strict';
var
window = require('../../External/window.js'),
JSON = require('../../External/JSON.js'),
Consts = require('../../Common/Consts.js'),
Utils = require('../../Common/Utils.js')
;
/**
* @constructor
*/
function LocalStorageDriver()
{
}
LocalStorageDriver.supported = function ()
{
return !!window.localStorage;
};
/**
* @param {string} sKey
* @param {*} mData
* @returns {boolean}
*/
LocalStorageDriver.prototype.set = function (sKey, mData)
{
var
mCookieValue = window.localStorage[Consts.Values.ClientSideCookieIndexName] || null,
bResult = false,
mResult = null
;
try
{
mResult = null === mCookieValue ? null : JSON.parse(mCookieValue);
if (!mResult)
{
mResult = {};
}
mResult[sKey] = mData;
window.localStorage[Consts.Values.ClientSideCookieIndexName] = JSON.stringify(mResult);
bResult = true;
}
catch (oException) {}
return bResult;
};
/**
* @param {string} sKey
* @returns {*}
*/
LocalStorageDriver.prototype.get = function (sKey)
{
var
mCokieValue = window.localStorage[Consts.Values.ClientSideCookieIndexName] || null,
mResult = null
;
try
{
mResult = null === mCokieValue ? null : JSON.parse(mCokieValue);
if (mResult && !Utils.isUnd(mResult[sKey]))
{
mResult = mResult[sKey];
}
else
{
mResult = null;
}
}
catch (oException) {}
return mResult;
};
module.exports = LocalStorageDriver;
}(module));
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module) {
'use strict';
var
_ = require('../External/underscore.js'),
CookieDriver = require('./LocalStorages/CookieDriver.js'),
LocalStorageDriver = require('./LocalStorages/LocalStorageDriver.js')
;
/**
* @constructor
*/
function LocalStorage()
{
var
NextStorageDriver = _.find([LocalStorageDriver, CookieDriver], function (NextStorageDriver) {
return NextStorageDriver.supported();
})
;
if (NextStorageDriver)
{
NextStorageDriver = /** @type {?Function} */ NextStorageDriver;
this.oDriver = new NextStorageDriver();
}
}
LocalStorage.prototype.oDriver = null;
/**
* @param {number} iKey
* @param {*} mData
* @return {boolean}
*/
LocalStorage.prototype.set = function (iKey, mData)
{
return this.oDriver ? this.oDriver.set('p' + iKey, mData) : false;
};
/**
* @param {number} iKey
* @return {*}
*/
LocalStorage.prototype.get = function (iKey)
{
return this.oDriver ? this.oDriver.get('p' + iKey) : null;
};
module.exports = new LocalStorage();
}(module));
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module) {
'use strict';
var
window = require('../External/window.js'),
$ = require('../External/jquery.js'),
_ = require('../External/underscore.js'),
ko = require('../External/ko.js'),
hasher = require('../External/hasher.js'),
crossroads = require('../External/crossroads.js'),
$window = require('../External/$window.js'),
$html = require('../External/$html.js'),
Globals = require('../Common/Globals.js'),
Plugins = require('../Common/Plugins.js'),
Utils = require('../Common/Utils.js'),
RL = require('../RL.js'),
KnoinAbstractViewModel = require('../Knoin/KnoinAbstractViewModel.js')
;
/**
* @constructor
*/
function Knoin()
{
this.sDefaultScreenName = '';
this.oScreens = {};
this.oBoot = null;
this.oRemote = null;
this.oData = null;
this.oCurrentScreen = null;
}
/**
* @param {Object} thisObject
*/
Knoin.constructorEnd = function (thisObject)
{
if (Utils.isFunc(thisObject['__constructor_end']))
{
thisObject['__constructor_end'].call(thisObject);
}
};
Knoin.prototype.sDefaultScreenName = '';
Knoin.prototype.oScreens = {};
Knoin.prototype.oBoot = null;
Knoin.prototype.oRemote = null;
Knoin.prototype.oData = null;
Knoin.prototype.oCurrentScreen = null;
Knoin.prototype.hideLoading = function ()
{
$('#rl-loading').hide();
};
Knoin.prototype.rl = function ()
{
return this.oBoot;
};
Knoin.prototype.remote = function ()
{
return this.oRemote;
};
Knoin.prototype.data = function ()
{
return this.oData;
};
/**
* @param {Object} thisObject
*/
Knoin.prototype.constructorEnd = function (thisObject)
{
if (Utils.isFunc(thisObject['__constructor_end']))
{
thisObject['__constructor_end'].call(thisObject);
}
};
/**
* @param {string} sName
* @param {Function} ViewModelClass
* @param {Function=} AbstractViewModel = KnoinAbstractViewModel
*/
Knoin.prototype.extendAsViewModel = function (sName, ViewModelClass, AbstractViewModel)
{
if (ViewModelClass)
{
if (!AbstractViewModel)
{
AbstractViewModel = KnoinAbstractViewModel;
}
ViewModelClass.__name = sName;
Plugins.regViewModelHook(sName, ViewModelClass);
_.extend(ViewModelClass.prototype, AbstractViewModel.prototype);
}
};
/**
* @param {Function} SettingsViewModelClass
* @param {string} sLabelName
* @param {string} sTemplate
* @param {string} sRoute
* @param {boolean=} bDefault
*/
Knoin.prototype.addSettingsViewModel = function (SettingsViewModelClass, sTemplate, sLabelName, sRoute, bDefault)
{
SettingsViewModelClass.__rlSettingsData = {
'Label': sLabelName,
'Template': sTemplate,
'Route': sRoute,
'IsDefault': !!bDefault
};
Globals.aViewModels['settings'].push(SettingsViewModelClass);
};
/**
* @param {Function} SettingsViewModelClass
*/
Knoin.prototype.removeSettingsViewModel = function (SettingsViewModelClass)
{
Globals.aViewModels['settings-removed'].push(SettingsViewModelClass);
};
/**
* @param {Function} SettingsViewModelClass
*/
Knoin.prototype.disableSettingsViewModel = function (SettingsViewModelClass)
{
Globals.aViewModels['settings-disabled'].push(SettingsViewModelClass);
};
Knoin.prototype.routeOff = function ()
{
hasher.changed.active = false;
};
Knoin.prototype.routeOn = function ()
{
hasher.changed.active = true;
};
/**
* @param {string} sScreenName
* @return {?Object}
*/
Knoin.prototype.screen = function (sScreenName)
{
return ('' !== sScreenName && !Utils.isUnd(this.oScreens[sScreenName])) ? this.oScreens[sScreenName] : null;
};
/**
* @param {Function} ViewModelClass
* @param {Object=} oScreen
*/
Knoin.prototype.buildViewModel = function (ViewModelClass, oScreen)
{
if (ViewModelClass && !ViewModelClass.__builded)
{
var
kn = this,
oViewModel = new ViewModelClass(oScreen),
sPosition = oViewModel.viewModelPosition(),
oViewModelPlace = $('#rl-content #rl-' + sPosition.toLowerCase()),
oViewModelDom = null
;
ViewModelClass.__builded = true;
ViewModelClass.__vm = oViewModel;
oViewModel.viewModelName = ViewModelClass.__name;
if (oViewModelPlace && 1 === oViewModelPlace.length)
{
oViewModelDom = $('
').addClass('rl-view-model').addClass('RL-' + oViewModel.viewModelTemplate()).hide();
oViewModelDom.appendTo(oViewModelPlace);
oViewModel.viewModelDom = oViewModelDom;
ViewModelClass.__dom = oViewModelDom;
if ('Popups' === sPosition)
{
oViewModel.cancelCommand = oViewModel.closeCommand = Utils.createCommand(oViewModel, function () {
kn.hideScreenPopup(ViewModelClass);
});
oViewModel.modalVisibility.subscribe(function (bValue) {
var self = this;
if (bValue)
{
this.viewModelDom.show();
this.storeAndSetKeyScope(kn.data());
RL.popupVisibilityNames.push(this.viewModelName); // TODO cjs
oViewModel.viewModelDom.css('z-index', 3000 + RL.popupVisibilityNames().length + 10); // TODO cjs
Utils.delegateRun(this, 'onFocus', [], 500);
}
else
{
Utils.delegateRun(this, 'onHide');
this.restoreKeyScope(kn.data());
RL.popupVisibilityNames.remove(this.viewModelName); // TODO cjs
oViewModel.viewModelDom.css('z-index', 2000);
Globals.tooltipTrigger(!Globals.tooltipTrigger());
_.delay(function () {
self.viewModelDom.hide();
}, 300);
}
}, oViewModel);
}
Plugins.runHook('view-model-pre-build', [ViewModelClass.__name, oViewModel, oViewModelDom]); // TODO cjs
ko.applyBindingAccessorsToNode(oViewModelDom[0], {
'i18nInit': true,
'template': function () { return {'name': oViewModel.viewModelTemplate()};}
}, oViewModel);
Utils.delegateRun(oViewModel, 'onBuild', [oViewModelDom]);
if (oViewModel && 'Popups' === sPosition)
{
oViewModel.registerPopupKeyDown();
}
Plugins.runHook('view-model-post-build', [ViewModelClass.__name, oViewModel, oViewModelDom]); // TODO cjs
}
else
{
Utils.log('Cannot find view model position: ' + sPosition);
}
}
return ViewModelClass ? ViewModelClass.__vm : null;
};
/**
* @param {Object} oViewModel
* @param {Object} oViewModelDom
*/
Knoin.prototype.applyExternal = function (oViewModel, oViewModelDom)
{
if (oViewModel && oViewModelDom)
{
ko.applyBindings(oViewModel, oViewModelDom);
}
};
/**
* @param {Function} ViewModelClassToHide
*/
Knoin.prototype.hideScreenPopup = function (ViewModelClassToHide)
{
if (ViewModelClassToHide && ViewModelClassToHide.__vm && ViewModelClassToHide.__dom)
{
ViewModelClassToHide.__vm.modalVisibility(false);
Plugins.runHook('view-model-on-hide', [ViewModelClassToHide.__name, ViewModelClassToHide.__vm]); // TODO cjs
}
};
/**
* @param {Function} ViewModelClassToShow
* @param {Array=} aParameters
*/
Knoin.prototype.showScreenPopup = function (ViewModelClassToShow, aParameters)
{
if (ViewModelClassToShow)
{
this.buildViewModel(ViewModelClassToShow);
if (ViewModelClassToShow.__vm && ViewModelClassToShow.__dom)
{
ViewModelClassToShow.__vm.modalVisibility(true);
Utils.delegateRun(ViewModelClassToShow.__vm, 'onShow', aParameters || []);
Plugins.runHook('view-model-on-show', [ViewModelClassToShow.__name, ViewModelClassToShow.__vm, aParameters || []]); // TODO cjs
}
}
};
/**
* @param {Function} ViewModelClassToShow
* @return {boolean}
*/
Knoin.prototype.isPopupVisible = function (ViewModelClassToShow)
{
return ViewModelClassToShow && ViewModelClassToShow.__vm ? ViewModelClassToShow.__vm.modalVisibility() : false;
};
/**
* @param {string} sScreenName
* @param {string} sSubPart
*/
Knoin.prototype.screenOnRoute = function (sScreenName, sSubPart)
{
var
self = this,
oScreen = null,
oCross = null
;
if ('' === Utils.pString(sScreenName))
{
sScreenName = this.sDefaultScreenName;
}
if ('' !== sScreenName)
{
oScreen = this.screen(sScreenName);
if (!oScreen)
{
oScreen = this.screen(this.sDefaultScreenName);
if (oScreen)
{
sSubPart = sScreenName + '/' + sSubPart;
sScreenName = this.sDefaultScreenName;
}
}
if (oScreen && oScreen.__started)
{
if (!oScreen.__builded)
{
oScreen.__builded = true;
if (Utils.isNonEmptyArray(oScreen.viewModels()))
{
_.each(oScreen.viewModels(), function (ViewModelClass) {
this.buildViewModel(ViewModelClass, oScreen);
}, this);
}
Utils.delegateRun(oScreen, 'onBuild');
}
_.defer(function () {
// hide screen
if (self.oCurrentScreen)
{
Utils.delegateRun(self.oCurrentScreen, 'onHide');
if (Utils.isNonEmptyArray(self.oCurrentScreen.viewModels()))
{
_.each(self.oCurrentScreen.viewModels(), function (ViewModelClass) {
if (ViewModelClass.__vm && ViewModelClass.__dom &&
'Popups' !== ViewModelClass.__vm.viewModelPosition())
{
ViewModelClass.__dom.hide();
ViewModelClass.__vm.viewModelVisibility(false);
Utils.delegateRun(ViewModelClass.__vm, 'onHide');
}
});
}
}
// --
self.oCurrentScreen = oScreen;
// show screen
if (self.oCurrentScreen)
{
Utils.delegateRun(self.oCurrentScreen, 'onShow');
Plugins.runHook('screen-on-show', [self.oCurrentScreen.screenName(), self.oCurrentScreen]); // TODO cjs
if (Utils.isNonEmptyArray(self.oCurrentScreen.viewModels()))
{
_.each(self.oCurrentScreen.viewModels(), function (ViewModelClass) {
if (ViewModelClass.__vm && ViewModelClass.__dom &&
'Popups' !== ViewModelClass.__vm.viewModelPosition())
{
ViewModelClass.__dom.show();
ViewModelClass.__vm.viewModelVisibility(true);
Utils.delegateRun(ViewModelClass.__vm, 'onShow');
Utils.delegateRun(ViewModelClass.__vm, 'onFocus', [], 200);
Plugins.runHook('view-model-on-show', [ViewModelClass.__name, ViewModelClass.__vm]); // TODO cjs
}
}, self);
}
}
// --
oCross = oScreen.__cross();
if (oCross)
{
oCross.parse(sSubPart);
}
});
}
}
};
/**
* @param {Array} aScreensClasses
*/
Knoin.prototype.startScreens = function (aScreensClasses)
{
$('#rl-content').css({
'visibility': 'hidden'
});
_.each(aScreensClasses, function (CScreen) {
var
oScreen = new CScreen(),
sScreenName = oScreen ? oScreen.screenName() : ''
;
if (oScreen && '' !== sScreenName)
{
if ('' === this.sDefaultScreenName)
{
this.sDefaultScreenName = sScreenName;
}
this.oScreens[sScreenName] = oScreen;
}
}, this);
_.each(this.oScreens, function (oScreen) {
if (oScreen && !oScreen.__started && oScreen.__start)
{
oScreen.__started = true;
oScreen.__start();
Plugins.runHook('screen-pre-start', [oScreen.screenName(), oScreen]); // TODO cjs
Utils.delegateRun(oScreen, 'onStart');
Plugins.runHook('screen-post-start', [oScreen.screenName(), oScreen]); // TODO cjs
}
}, this);
var oCross = crossroads.create();
oCross.addRoute(/^([a-zA-Z0-9\-]*)\/?(.*)$/, _.bind(this.screenOnRoute, this));
hasher.initialized.add(oCross.parse, oCross);
hasher.changed.add(oCross.parse, oCross);
hasher.init();
$('#rl-content').css({
'visibility': 'visible'
});
_.delay(function () {
$html.removeClass('rl-started-trigger').addClass('rl-started');
}, 50);
};
/**
* @param {string} sHash
* @param {boolean=} bSilence = false
* @param {boolean=} bReplace = false
*/
Knoin.prototype.setHash = function (sHash, bSilence, bReplace)
{
sHash = '#' === sHash.substr(0, 1) ? sHash.substr(1) : sHash;
sHash = '/' === sHash.substr(0, 1) ? sHash.substr(1) : sHash;
bReplace = Utils.isUnd(bReplace) ? false : !!bReplace;
if (Utils.isUnd(bSilence) ? false : !!bSilence)
{
hasher.changed.active = false;
hasher[bReplace ? 'replaceHash' : 'setHash'](sHash);
hasher.changed.active = true;
}
else
{
hasher.changed.active = true;
hasher[bReplace ? 'replaceHash' : 'setHash'](sHash);
hasher.setHash(sHash);
}
};
/**
* @return {Knoin}
*/
Knoin.prototype.bootstart = function (RL, Remote, Data)
{
this.oBoot = RL;
this.oData = Data;
this.oRemote = Remote;
Plugins.__boot = this.oBoot;
Plugins.__data = this.oData;
Plugins.__remote = this.oRemote;
$html.addClass(Globals.bMobileDevice ? 'mobile' : 'no-mobile');
$window.keydown(Utils.killCtrlAandS).keyup(Utils.killCtrlAandS);
$window.unload(function () {
Globals.bUnload = true;
});
$html.on('click.dropdown.data-api', function () {
Utils.detectDropdownVisibility();
});
// export
window['rl'] = window['rl'] || {};
window['rl']['addHook'] = Plugins.addHook;
window['rl']['settingsGet'] = Plugins.mainSettingsGet;
window['rl']['remoteRequest'] = Plugins.remoteRequest;
window['rl']['pluginSettingsGet'] = Plugins.settingsGet;
window['rl']['addSettingsViewModel'] = _.bind(this.addSettingsViewModel, this);
window['rl']['createCommand'] = Utils.createCommand;
window['rl']['EmailModel'] = require('../Models/EmailModel.js');
window['rl']['Enums'] = require('../Common/Enums.js');
window['__RLBOOT'] = function (fCall) {
// boot
$(function () {
if (window['rainloopTEMPLATES'] && window['rainloopTEMPLATES'][0])
{
$('#rl-templates').html(window['rainloopTEMPLATES'][0]);
_.delay(function () {
RL.bootstart();
$html.removeClass('no-js rl-booted-trigger').addClass('rl-booted');
}, 50);
}
else
{
fCall(false);
}
window['__RLBOOT'] = null;
});
};
};
module.exports = new Knoin();
}(module));
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module) {
'use strict';
var
Enums = require('../Common/Enums.js'),
Utils = require('../Common/Utils.js')
;
/**
* @param {string=} sEmail
* @param {string=} sName
*
* @constructor
*/
function EmailModel(sEmail, sName)
{
this.email = sEmail || '';
this.name = sName || '';
this.privateType = null;
this.clearDuplicateName();
}
/**
* @static
* @param {AjaxJsonEmail} oJsonEmail
* @return {?EmailModel}
*/
EmailModel.newInstanceFromJson = function (oJsonEmail)
{
var oEmailModel = new EmailModel();
return oEmailModel.initByJson(oJsonEmail) ? oEmailModel : null;
};
/**
* @type {string}
*/
EmailModel.prototype.name = '';
/**
* @type {string}
*/
EmailModel.prototype.email = '';
/**
* @type {(number|null)}
*/
EmailModel.prototype.privateType = null;
EmailModel.prototype.clear = function ()
{
this.email = '';
this.name = '';
this.privateType = null;
};
/**
* @returns {boolean}
*/
EmailModel.prototype.validate = function ()
{
return '' !== this.name || '' !== this.email;
};
/**
* @param {boolean} bWithoutName = false
* @return {string}
*/
EmailModel.prototype.hash = function (bWithoutName)
{
return '#' + (bWithoutName ? '' : this.name) + '#' + this.email + '#';
};
EmailModel.prototype.clearDuplicateName = function ()
{
if (this.name === this.email)
{
this.name = '';
}
};
/**
* @return {number}
*/
EmailModel.prototype.type = function ()
{
if (null === this.privateType)
{
if (this.email && '@facebook.com' === this.email.substr(-13))
{
this.privateType = Enums.EmailType.Facebook;
}
if (null === this.privateType)
{
this.privateType = Enums.EmailType.Default;
}
}
return this.privateType;
};
/**
* @param {string} sQuery
* @return {boolean}
*/
EmailModel.prototype.search = function (sQuery)
{
return -1 < (this.name + ' ' + this.email).toLowerCase().indexOf(sQuery.toLowerCase());
};
/**
* @param {string} sString
*/
EmailModel.prototype.parse = function (sString)
{
this.clear();
sString = Utils.trim(sString);
var
mRegex = /(?:"([^"]+)")? ?(.*?@[^>,]+)>?,? ?/g,
mMatch = mRegex.exec(sString)
;
if (mMatch)
{
this.name = mMatch[1] || '';
this.email = mMatch[2] || '';
this.clearDuplicateName();
}
else if ((/^[^@]+@[^@]+$/).test(sString))
{
this.name = '';
this.email = sString;
}
};
/**
* @param {AjaxJsonEmail} oJsonEmail
* @return {boolean}
*/
EmailModel.prototype.initByJson = function (oJsonEmail)
{
var bResult = false;
if (oJsonEmail && 'Object/Email' === oJsonEmail['@Object'])
{
this.name = Utils.trim(oJsonEmail.Name);
this.email = Utils.trim(oJsonEmail.Email);
bResult = '' !== this.email;
this.clearDuplicateName();
}
return bResult;
};
/**
* @param {boolean} bFriendlyView
* @param {boolean=} bWrapWithLink = false
* @param {boolean=} bEncodeHtml = false
* @return {string}
*/
EmailModel.prototype.toLine = function (bFriendlyView, bWrapWithLink, bEncodeHtml)
{
var sResult = '';
if ('' !== this.email)
{
bWrapWithLink = Utils.isUnd(bWrapWithLink) ? false : !!bWrapWithLink;
bEncodeHtml = Utils.isUnd(bEncodeHtml) ? false : !!bEncodeHtml;
if (bFriendlyView && '' !== this.name)
{
sResult = bWrapWithLink ? '
') +
'" target="_blank" tabindex="-1">' + Utils.encodeHtml(this.name) + '' :
(bEncodeHtml ? Utils.encodeHtml(this.name) : this.name);
}
else
{
sResult = this.email;
if ('' !== this.name)
{
if (bWrapWithLink)
{
sResult = Utils.encodeHtml('"' + this.name + '" <') +
'
') + '" target="_blank" tabindex="-1">' + Utils.encodeHtml(sResult) + '' + Utils.encodeHtml('>');
}
else
{
sResult = '"' + this.name + '" <' + sResult + '>';
if (bEncodeHtml)
{
sResult = Utils.encodeHtml(sResult);
}
}
}
else if (bWrapWithLink)
{
sResult = '
' + Utils.encodeHtml(this.email) + '';
}
}
}
return sResult;
};
/**
* @param {string} $sEmailAddress
* @return {boolean}
*/
EmailModel.prototype.mailsoParse = function ($sEmailAddress)
{
$sEmailAddress = Utils.trim($sEmailAddress);
if ('' === $sEmailAddress)
{
return false;
}
var
substr = function (str, start, len) {
str += '';
var end = str.length;
if (start < 0) {
start += end;
}
end = typeof len === 'undefined' ? end : (len < 0 ? len + end : len + start);
return start >= str.length || start < 0 || start > end ? false : str.slice(start, end);
},
substr_replace = function (str, replace, start, length) {
if (start < 0) {
start = start + str.length;
}
length = length !== undefined ? length : str.length;
if (length < 0) {
length = length + str.length - start;
}
return str.slice(0, start) + replace.substr(0, length) + replace.slice(length) + str.slice(start + length);
},
$sName = '',
$sEmail = '',
$sComment = '',
$bInName = false,
$bInAddress = false,
$bInComment = false,
$aRegs = null,
$iStartIndex = 0,
$iEndIndex = 0,
$iCurrentIndex = 0
;
while ($iCurrentIndex < $sEmailAddress.length)
{
switch ($sEmailAddress.substr($iCurrentIndex, 1))
{
case '"':
if ((!$bInName) && (!$bInAddress) && (!$bInComment))
{
$bInName = true;
$iStartIndex = $iCurrentIndex;
}
else if ((!$bInAddress) && (!$bInComment))
{
$iEndIndex = $iCurrentIndex;
$sName = substr($sEmailAddress, $iStartIndex + 1, $iEndIndex - $iStartIndex - 1);
$sEmailAddress = substr_replace($sEmailAddress, '', $iStartIndex, $iEndIndex - $iStartIndex + 1);
$iEndIndex = 0;
$iCurrentIndex = 0;
$iStartIndex = 0;
$bInName = false;
}
break;
case '<':
if ((!$bInName) && (!$bInAddress) && (!$bInComment))
{
if ($iCurrentIndex > 0 && $sName.length === 0)
{
$sName = substr($sEmailAddress, 0, $iCurrentIndex);
}
$bInAddress = true;
$iStartIndex = $iCurrentIndex;
}
break;
case '>':
if ($bInAddress)
{
$iEndIndex = $iCurrentIndex;
$sEmail = substr($sEmailAddress, $iStartIndex + 1, $iEndIndex - $iStartIndex - 1);
$sEmailAddress = substr_replace($sEmailAddress, '', $iStartIndex, $iEndIndex - $iStartIndex + 1);
$iEndIndex = 0;
$iCurrentIndex = 0;
$iStartIndex = 0;
$bInAddress = false;
}
break;
case '(':
if ((!$bInName) && (!$bInAddress) && (!$bInComment))
{
$bInComment = true;
$iStartIndex = $iCurrentIndex;
}
break;
case ')':
if ($bInComment)
{
$iEndIndex = $iCurrentIndex;
$sComment = substr($sEmailAddress, $iStartIndex + 1, $iEndIndex - $iStartIndex - 1);
$sEmailAddress = substr_replace($sEmailAddress, '', $iStartIndex, $iEndIndex - $iStartIndex + 1);
$iEndIndex = 0;
$iCurrentIndex = 0;
$iStartIndex = 0;
$bInComment = false;
}
break;
case '\\':
$iCurrentIndex++;
break;
}
$iCurrentIndex++;
}
if ($sEmail.length === 0)
{
$aRegs = $sEmailAddress.match(/[^@\s]+@\S+/i);
if ($aRegs && $aRegs[0])
{
$sEmail = $aRegs[0];
}
else
{
$sName = $sEmailAddress;
}
}
if ($sEmail.length > 0 && $sName.length === 0 && $sComment.length === 0)
{
$sName = $sEmailAddress.replace($sEmail, '');
}
$sEmail = Utils.trim($sEmail).replace(/^[<]+/, '').replace(/[>]+$/, '');
$sName = Utils.trim($sName).replace(/^["']+/, '').replace(/["']+$/, '');
$sComment = Utils.trim($sComment).replace(/^[(]+/, '').replace(/[)]+$/, '');
// Remove backslash
$sName = $sName.replace(/\\\\(.)/, '$1');
$sComment = $sComment.replace(/\\\\(.)/, '$1');
this.name = $sName;
this.email = $sEmail;
this.clearDuplicateName();
return true;
};
/**
* @return {string}
*/
EmailModel.prototype.inputoTagLine = function ()
{
return 0 < this.name.length ? this.name + ' (' + this.email + ')' : this.email;
};
module.exports = EmailModel;
}(module));
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module) {
'use strict';
var
ko = require('../External/ko.js'),
Utils = require('../Common/Utils.js')
;
/**
* @constructor
*/
function ContactTagModel()
{
this.idContactTag = 0;
this.name = ko.observable('');
this.readOnly = false;
}
ContactTagModel.prototype.parse = function (oItem)
{
var bResult = false;
if (oItem && 'Object/Tag' === oItem['@Object'])
{
this.idContact = Utils.pInt(oItem['IdContactTag']);
this.name(Utils.pString(oItem['Name']));
this.readOnly = !!oItem['ReadOnly'];
bResult = true;
}
return bResult;
};
/**
* @param {string} sSearch
* @return {boolean}
*/
ContactTagModel.prototype.filterHelper = function (sSearch)
{
return this.name().toLowerCase().indexOf(sSearch.toLowerCase()) !== -1;
};
/**
* @param {boolean=} bEncodeHtml = false
* @return {string}
*/
ContactTagModel.prototype.toLine = function (bEncodeHtml)
{
return (Utils.isUnd(bEncodeHtml) ? false : !!bEncodeHtml) ?
Utils.encodeHtml(this.name()) : this.name();
};
module.exports = ContactTagModel;
}(module));
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module) {
'use strict';
var
_ = require('../../External/underscore.js'),
ko = require('../../External/ko.js'),
Enums = require('../../Common/Enums.js'),
Consts = require('../../Common/Consts.js'),
Utils = require('../../Common/Utils.js'),
Remote = require('../../Storages/AdminAjaxRemoteStorage.js'),
kn = require('../../Knoin/Knoin.js'),
KnoinAbstractViewModel = require('../../Knoin/KnoinAbstractViewModel.js')
;
/**
* @constructor
* @extends KnoinAbstractViewModel
*/
function PopupsDomainViewModel()
{
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsDomain');
this.edit = ko.observable(false);
this.saving = ko.observable(false);
this.savingError = ko.observable('');
this.whiteListPage = ko.observable(false);
this.testing = ko.observable(false);
this.testingDone = ko.observable(false);
this.testingImapError = ko.observable(false);
this.testingSmtpError = ko.observable(false);
this.testingImapErrorDesc = ko.observable('');
this.testingSmtpErrorDesc = ko.observable('');
this.testingImapError.subscribe(function (bValue) {
if (!bValue)
{
this.testingImapErrorDesc('');
}
}, this);
this.testingSmtpError.subscribe(function (bValue) {
if (!bValue)
{
this.testingSmtpErrorDesc('');
}
}, this);
this.testingImapErrorDesc = ko.observable('');
this.testingSmtpErrorDesc = ko.observable('');
this.imapServerFocus = ko.observable(false);
this.smtpServerFocus = ko.observable(false);
this.name = ko.observable('');
this.name.focused = ko.observable(false);
this.imapServer = ko.observable('');
this.imapPort = ko.observable('' + Consts.Values.ImapDefaulPort);
this.imapSecure = ko.observable(Enums.ServerSecure.None);
this.imapShortLogin = ko.observable(false);
this.smtpServer = ko.observable('');
this.smtpPort = ko.observable('' + Consts.Values.SmtpDefaulPort);
this.smtpSecure = ko.observable(Enums.ServerSecure.None);
this.smtpShortLogin = ko.observable(false);
this.smtpAuth = ko.observable(true);
this.whiteList = ko.observable('');
this.headerText = ko.computed(function () {
var sName = this.name();
return this.edit() ? 'Edit Domain "' + sName + '"' :
'Add Domain' + ('' === sName ? '' : ' "' + sName + '"');
}, this);
this.domainIsComputed = ko.computed(function () {
return '' !== this.name() &&
'' !== this.imapServer() &&
'' !== this.imapPort() &&
'' !== this.smtpServer() &&
'' !== this.smtpPort();
}, this);
this.canBeTested = ko.computed(function () {
return !this.testing() && this.domainIsComputed();
}, this);
this.canBeSaved = ko.computed(function () {
return !this.saving() && this.domainIsComputed();
}, this);
this.createOrAddCommand = Utils.createCommand(this, function () {
this.saving(true);
Remote.createOrUpdateDomain(
_.bind(this.onDomainCreateOrSaveResponse, this),
!this.edit(),
this.name(),
this.imapServer(),
Utils.pInt(this.imapPort()),
this.imapSecure(),
this.imapShortLogin(),
this.smtpServer(),
Utils.pInt(this.smtpPort()),
this.smtpSecure(),
this.smtpShortLogin(),
this.smtpAuth(),
this.whiteList()
);
}, this.canBeSaved);
this.testConnectionCommand = Utils.createCommand(this, function () {
this.whiteListPage(false);
this.testingDone(false);
this.testingImapError(false);
this.testingSmtpError(false);
this.testing(true);
Remote.testConnectionForDomain(
_.bind(this.onTestConnectionResponse, this),
this.name(),
this.imapServer(),
Utils.pInt(this.imapPort()),
this.imapSecure(),
this.smtpServer(),
Utils.pInt(this.smtpPort()),
this.smtpSecure(),
this.smtpAuth()
);
}, this.canBeTested);
this.whiteListCommand = Utils.createCommand(this, function () {
this.whiteListPage(!this.whiteListPage());
});
// smart form improvements
this.imapServerFocus.subscribe(function (bValue) {
if (bValue && '' !== this.name() && '' === this.imapServer())
{
this.imapServer(this.name().replace(/[.]?[*][.]?/g, ''));
}
}, this);
this.smtpServerFocus.subscribe(function (bValue) {
if (bValue && '' !== this.imapServer() && '' === this.smtpServer())
{
this.smtpServer(this.imapServer().replace(/imap/ig, 'smtp'));
}
}, this);
this.imapSecure.subscribe(function (sValue) {
var iPort = Utils.pInt(this.imapPort());
sValue = Utils.pString(sValue);
switch (sValue)
{
case '0':
if (993 === iPort)
{
this.imapPort('143');
}
break;
case '1':
if (143 === iPort)
{
this.imapPort('993');
}
break;
}
}, this);
this.smtpSecure.subscribe(function (sValue) {
var iPort = Utils.pInt(this.smtpPort());
sValue = Utils.pString(sValue);
switch (sValue)
{
case '0':
if (465 === iPort || 587 === iPort)
{
this.smtpPort('25');
}
break;
case '1':
if (25 === iPort || 587 === iPort)
{
this.smtpPort('465');
}
break;
case '2':
if (25 === iPort || 465 === iPort)
{
this.smtpPort('587');
}
break;
}
}, this);
kn.constructorEnd(this);
}
kn.extendAsViewModel('PopupsDomainViewModel', PopupsDomainViewModel);
PopupsDomainViewModel.prototype.onTestConnectionResponse = function (sResult, oData)
{
this.testing(false);
if (Enums.StorageResultType.Success === sResult && oData.Result)
{
this.testingDone(true);
this.testingImapError(true !== oData.Result.Imap);
this.testingSmtpError(true !== oData.Result.Smtp);
if (this.testingImapError() && oData.Result.Imap)
{
this.testingImapErrorDesc(oData.Result.Imap);
}
if (this.testingSmtpError() && oData.Result.Smtp)
{
this.testingSmtpErrorDesc(oData.Result.Smtp);
}
}
else
{
this.testingImapError(true);
this.testingSmtpError(true);
}
};
PopupsDomainViewModel.prototype.onDomainCreateOrSaveResponse = function (sResult, oData)
{
this.saving(false);
if (Enums.StorageResultType.Success === sResult && oData)
{
if (oData.Result)
{
RL.reloadDomainList();
this.closeCommand();
}
else if (Enums.Notification.DomainAlreadyExists === oData.ErrorCode)
{
this.savingError('Domain already exists');
}
}
else
{
this.savingError('Unknown error');
}
};
PopupsDomainViewModel.prototype.onHide = function ()
{
this.whiteListPage(false);
};
PopupsDomainViewModel.prototype.onShow = function (oDomain)
{
this.saving(false);
this.whiteListPage(false);
this.testing(false);
this.testingDone(false);
this.testingImapError(false);
this.testingSmtpError(false);
this.clearForm();
if (oDomain)
{
this.edit(true);
this.name(Utils.trim(oDomain.Name));
this.imapServer(Utils.trim(oDomain.IncHost));
this.imapPort('' + Utils.pInt(oDomain.IncPort));
this.imapSecure(Utils.trim(oDomain.IncSecure));
this.imapShortLogin(!!oDomain.IncShortLogin);
this.smtpServer(Utils.trim(oDomain.OutHost));
this.smtpPort('' + Utils.pInt(oDomain.OutPort));
this.smtpSecure(Utils.trim(oDomain.OutSecure));
this.smtpShortLogin(!!oDomain.OutShortLogin);
this.smtpAuth(!!oDomain.OutAuth);
this.whiteList(Utils.trim(oDomain.WhiteList));
}
};
PopupsDomainViewModel.prototype.onFocus = function ()
{
if ('' === this.name())
{
this.name.focused(true);
}
};
PopupsDomainViewModel.prototype.clearForm = function ()
{
this.edit(false);
this.whiteListPage(false);
this.savingError('');
this.name('');
this.name.focused(false);
this.imapServer('');
this.imapPort('' + Consts.Values.ImapDefaulPort);
this.imapSecure(Enums.ServerSecure.None);
this.imapShortLogin(false);
this.smtpServer('');
this.smtpPort('' + Consts.Values.SmtpDefaulPort);
this.smtpSecure(Enums.ServerSecure.None);
this.smtpShortLogin(false);
this.smtpAuth(true);
this.whiteList('');
};
module.exports = new PopupsDomainViewModel();
}(module));
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module) {
'use strict';
var
_ = require('../../External/underscore.js'),
ko = require('../../External/ko.js'),
key = require('../../External/key.js'),
Enums = require('../../Common/Enums.js'),
Utils = require('../../Common/Utils.js'),
Remote = require('../../Storages/AdminAjaxRemoteStorage.js'),
kn = require('../../Knoin/Knoin.js'),
KnoinAbstractViewModel = require('../../Knoin/KnoinAbstractViewModel.js')
;
/**
* @constructor
* @extends KnoinAbstractViewModel
*/
function PopupsPluginViewModel()
{
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsPlugin');
var self = this;
this.onPluginSettingsUpdateResponse = _.bind(this.onPluginSettingsUpdateResponse, this);
this.saveError = ko.observable('');
this.name = ko.observable('');
this.readme = ko.observable('');
this.configures = ko.observableArray([]);
this.hasReadme = ko.computed(function () {
return '' !== this.readme();
}, this);
this.hasConfiguration = ko.computed(function () {
return 0 < this.configures().length;
}, this);
this.readmePopoverConf = {
'placement': 'top',
'trigger': 'hover',
'title': 'About',
'content': function () {
return self.readme();
}
};
this.saveCommand = Utils.createCommand(this, function () {
var oList = {};
oList['Name'] = this.name();
_.each(this.configures(), function (oItem) {
var mValue = oItem.value();
if (false === mValue || true === mValue)
{
mValue = mValue ? '1' : '0';
}
oList['_' + oItem['Name']] = mValue;
}, this);
this.saveError('');
Remote.pluginSettingsUpdate(this.onPluginSettingsUpdateResponse, oList);
}, this.hasConfiguration);
this.bDisabeCloseOnEsc = true;
this.sDefaultKeyScope = Enums.KeyState.All;
this.tryToClosePopup = _.debounce(_.bind(this.tryToClosePopup, this), 200);
kn.constructorEnd(this);
}
kn.extendAsViewModel('PopupsPluginViewModel', PopupsPluginViewModel);
PopupsPluginViewModel.prototype.onPluginSettingsUpdateResponse = function (sResult, oData)
{
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
{
this.cancelCommand();
}
else
{
this.saveError('');
if (oData && oData.ErrorCode)
{
this.saveError(Utils.getNotification(oData.ErrorCode));
}
else
{
this.saveError(Utils.getNotification(Enums.Notification.CantSavePluginSettings));
}
}
};
PopupsPluginViewModel.prototype.onShow = function (oPlugin)
{
this.name();
this.readme();
this.configures([]);
if (oPlugin)
{
this.name(oPlugin['Name']);
this.readme(oPlugin['Readme']);
var aConfig = oPlugin['Config'];
if (Utils.isNonEmptyArray(aConfig))
{
this.configures(_.map(aConfig, function (aItem) {
return {
'value': ko.observable(aItem[0]),
'Name': aItem[1],
'Type': aItem[2],
'Label': aItem[3],
'Default': aItem[4],
'Desc': aItem[5]
};
}));
}
}
};
PopupsPluginViewModel.prototype.tryToClosePopup = function ()
{
var self = this;
if (!kn.isPopupVisible(PopupsAskViewModel))
{
kn.showScreenPopup(PopupsAskViewModel, [Utils.i18n('POPUPS_ASK/DESC_WANT_CLOSE_THIS_WINDOW'), function () {
if (self.modalVisibility())
{
Utils.delegateRun(self, 'cancelCommand');
}
}]);
}
};
PopupsPluginViewModel.prototype.onBuild = function ()
{
key('esc', Enums.KeyState.All, _.bind(function () {
if (this.modalVisibility())
{
this.tryToClosePopup();
}
return false;
}, this));
};
module.exports = new PopupsPluginViewModel();
}(module));
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module) {
'use strict';
var
ko = require('../../External/ko.js'),
Enums = require('../../Common/Enums.js'),
Utils = require('../../Common/Utils.js'),
Data = require('../../Storages/AdminDataStorage.js'),
Remote = require('../../Storages/AdminAjaxRemoteStorage.js'),
kn = require('../../Knoin/Knoin.js'),
KnoinAbstractViewModel = require('../../Knoin/KnoinAbstractViewModel.js')
;
/**
* @constructor
* @extends KnoinAbstractViewModel
*/
function PopupsActivateViewModel()
{
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsActivate');
var self = this;
this.domain = ko.observable('');
this.key = ko.observable('');
this.key.focus = ko.observable(false);
this.activationSuccessed = ko.observable(false);
this.licenseTrigger = Data.licenseTrigger;
this.activateProcess = ko.observable(false);
this.activateText = ko.observable('');
this.activateText.isError = ko.observable(false);
this.key.subscribe(function () {
this.activateText('');
this.activateText.isError(false);
}, this);
this.activationSuccessed.subscribe(function (bValue) {
if (bValue)
{
this.licenseTrigger(!this.licenseTrigger());
}
}, this);
this.activateCommand = Utils.createCommand(this, function () {
this.activateProcess(true);
if (this.validateSubscriptionKey())
{
Remote.licensingActivate(function (sResult, oData) {
self.activateProcess(false);
if (Enums.StorageResultType.Success === sResult && oData.Result)
{
if (true === oData.Result)
{
self.activationSuccessed(true);
self.activateText('Subscription Key Activated Successfully');
self.activateText.isError(false);
}
else
{
self.activateText(oData.Result);
self.activateText.isError(true);
self.key.focus(true);
}
}
else if (oData.ErrorCode)
{
self.activateText(Utils.getNotification(oData.ErrorCode));
self.activateText.isError(true);
self.key.focus(true);
}
else
{
self.activateText(Utils.getNotification(Enums.Notification.UnknownError));
self.activateText.isError(true);
self.key.focus(true);
}
}, this.domain(), this.key());
}
else
{
this.activateProcess(false);
this.activateText('Invalid Subscription Key');
this.activateText.isError(true);
this.key.focus(true);
}
}, function () {
return !this.activateProcess() && '' !== this.domain() && '' !== this.key() && !this.activationSuccessed();
});
kn.constructorEnd(this);
}
kn.extendAsViewModel('PopupsActivateViewModel', PopupsActivateViewModel);
PopupsActivateViewModel.prototype.onShow = function ()
{
this.domain(RL.settingsGet('AdminDomain'));
if (!this.activateProcess())
{
this.key('');
this.activateText('');
this.activateText.isError(false);
this.activationSuccessed(false);
}
};
PopupsActivateViewModel.prototype.onFocus = function ()
{
if (!this.activateProcess())
{
this.key.focus(true);
}
};
/**
* @returns {boolean}
*/
PopupsActivateViewModel.prototype.validateSubscriptionKey = function ()
{
var sValue = this.key();
return '' === sValue || !!/^RL[\d]+-[A-Z0-9\-]+Z$/.test(Utils.trim(sValue));
};
module.exports = new PopupsActivateViewModel();
}(module));
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module) {
'use strict';
var
_ = require('../../External/underscore.js'),
ko = require('../../External/ko.js'),
Utils = require('../../Common/Utils.js'),
Data = require('../../Storages/WebMailDataStorage.js'),
kn = require('../../Knoin/Knoin.js'),
KnoinAbstractViewModel = require('../../Knoin/KnoinAbstractViewModel.js')
;
/**
* @constructor
* @extends KnoinAbstractViewModel
*/
function PopupsLanguagesViewModel()
{
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsLanguages');
this.exp = ko.observable(false);
this.languages = ko.computed(function () {
return _.map(Data.languages(), function (sLanguage) {
return {
'key': sLanguage,
'selected': ko.observable(false),
'fullName': Utils.convertLangName(sLanguage)
};
});
});
Data.mainLanguage.subscribe(function () {
this.resetMainLanguage();
}, this);
kn.constructorEnd(this);
}
kn.extendAsViewModel('PopupsLanguagesViewModel', PopupsLanguagesViewModel);
PopupsLanguagesViewModel.prototype.languageEnName = function (sLanguage)
{
return Utils.convertLangName(sLanguage, true);
};
PopupsLanguagesViewModel.prototype.resetMainLanguage = function ()
{
var sCurrent = Data.mainLanguage();
_.each(this.languages(), function (oItem) {
oItem['selected'](oItem['key'] === sCurrent);
});
};
PopupsLanguagesViewModel.prototype.onShow = function ()
{
this.exp(true);
this.resetMainLanguage();
};
PopupsLanguagesViewModel.prototype.onHide = function ()
{
this.exp(false);
};
PopupsLanguagesViewModel.prototype.changeLanguage = function (sLang)
{
Data.mainLanguage(sLang);
this.cancelCommand();
};
module.exports = new PopupsLanguagesViewModel();
}(module));
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module) {
'use strict';
var
ko = require('../../External/ko.js'),
key = require('../../External/key.js'),
Enums = require('../../Common/Enums.js'),
Utils = require('../../Common/Utils.js'),
kn = require('../../Knoin/Knoin.js'),
KnoinAbstractViewModel = require('../../Knoin/KnoinAbstractViewModel.js')
;
/**
* @constructor
* @extends KnoinAbstractViewModel
*/
function PopupsAskViewModel()
{
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsAsk');
this.askDesc = ko.observable('');
this.yesButton = ko.observable('');
this.noButton = ko.observable('');
this.yesFocus = ko.observable(false);
this.noFocus = ko.observable(false);
this.fYesAction = null;
this.fNoAction = null;
this.bDisabeCloseOnEsc = true;
this.sDefaultKeyScope = Enums.KeyState.PopupAsk;
kn.constructorEnd(this);
}
kn.extendAsViewModel('PopupsAskViewModel', PopupsAskViewModel);
PopupsAskViewModel.prototype.clearPopup = function ()
{
this.askDesc('');
this.yesButton(Utils.i18n('POPUPS_ASK/BUTTON_YES'));
this.noButton(Utils.i18n('POPUPS_ASK/BUTTON_NO'));
this.yesFocus(false);
this.noFocus(false);
this.fYesAction = null;
this.fNoAction = null;
};
PopupsAskViewModel.prototype.yesClick = function ()
{
this.cancelCommand();
if (Utils.isFunc(this.fYesAction))
{
this.fYesAction.call(null);
}
};
PopupsAskViewModel.prototype.noClick = function ()
{
this.cancelCommand();
if (Utils.isFunc(this.fNoAction))
{
this.fNoAction.call(null);
}
};
/**
* @param {string} sAskDesc
* @param {Function=} fYesFunc
* @param {Function=} fNoFunc
* @param {string=} sYesButton
* @param {string=} sNoButton
*/
PopupsAskViewModel.prototype.onShow = function (sAskDesc, fYesFunc, fNoFunc, sYesButton, sNoButton)
{
this.clearPopup();
this.fYesAction = fYesFunc || null;
this.fNoAction = fNoFunc || null;
this.askDesc(sAskDesc || '');
if (sYesButton)
{
this.yesButton(sYesButton);
}
if (sYesButton)
{
this.yesButton(sNoButton);
}
};
PopupsAskViewModel.prototype.onFocus = function ()
{
this.yesFocus(true);
};
PopupsAskViewModel.prototype.onBuild = function ()
{
key('tab, shift+tab, right, left', Enums.KeyState.PopupAsk, _.bind(function () {
if (this.yesFocus())
{
this.noFocus(true);
}
else
{
this.yesFocus(true);
}
return false;
}, this));
key('esc', Enums.KeyState.PopupAsk, _.bind(function () {
this.noClick();
return false;
}, this));
};
module.exports = new PopupsAskViewModel();
}(module));
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module) {
'use strict';
var
_ = require('../External/underscore.js'),
ko = require('../External/ko.js'),
Enums = require('../Common/Enums.js'),
Utils = require('../Common/Utils.js'),
Remote = require('../Storages/AdminAjaxRemoteStorage.js'),
kn = require('../Knoin/Knoin.js'),
KnoinAbstractViewModel = require('../Knoin/KnoinAbstractViewModel.js')
;
/**
* @constructor
* @extends KnoinAbstractViewModel
*/
function AdminLoginViewModel()
{
KnoinAbstractViewModel.call(this, 'Center', 'AdminLogin');
this.login = ko.observable('');
this.password = ko.observable('');
this.loginError = ko.observable(false);
this.passwordError = ko.observable(false);
this.loginFocus = ko.observable(false);
this.login.subscribe(function () {
this.loginError(false);
}, this);
this.password.subscribe(function () {
this.passwordError(false);
}, this);
this.submitRequest = ko.observable(false);
this.submitError = ko.observable('');
this.submitCommand = Utils.createCommand(this, function () {
Utils.triggerAutocompleteInputChange();
this.loginError('' === Utils.trim(this.login()));
this.passwordError('' === Utils.trim(this.password()));
if (this.loginError() || this.passwordError())
{
return false;
}
this.submitRequest(true);
Remote.adminLogin(_.bind(function (sResult, oData) {
if (Enums.StorageResultType.Success === sResult && oData && 'AdminLogin' === oData.Action)
{
if (oData.Result)
{
RL.loginAndLogoutReload();
}
else if (oData.ErrorCode)
{
this.submitRequest(false);
this.submitError(Utils.getNotification(oData.ErrorCode));
}
}
else
{
this.submitRequest(false);
this.submitError(Utils.getNotification(Enums.Notification.UnknownError));
}
}, this), this.login(), this.password());
return true;
}, function () {
return !this.submitRequest();
});
kn.constructorEnd(this);
}
kn.extendAsViewModel('AdminLoginViewModel', AdminLoginViewModel);
AdminLoginViewModel.prototype.onShow = function ()
{
kn.routeOff();
_.delay(_.bind(function () {
this.loginFocus(true);
}, this), 100);
};
AdminLoginViewModel.prototype.onHide = function ()
{
this.loginFocus(false);
};
AdminLoginViewModel.prototype.onBuild = function ()
{
Utils.triggerAutocompleteInputChange(true);
};
AdminLoginViewModel.prototype.submitForm = function ()
{
this.submitCommand();
};
module.exports = new AdminLoginViewModel();
}(module));
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module) {
'use strict';
var
kn = require('../Knoin/Knoin.js'),
Data = require('../Storages/AdminDataStorage.js'),
KnoinAbstractViewModel = require('../Knoin/KnoinAbstractViewModel.js')
;
/**
* @param {?} oScreen
*
* @constructor
* @extends KnoinAbstractViewModel
*/
function AdminMenuViewModel(oScreen)
{
KnoinAbstractViewModel.call(this, 'Left', 'AdminMenu');
this.leftPanelDisabled = Data.leftPanelDisabled;
this.menu = oScreen.menu;
kn.constructorEnd(this);
}
kn.extendAsViewModel('AdminMenuViewModel', AdminMenuViewModel);
AdminMenuViewModel.prototype.link = function (sRoute)
{
return '#/' + sRoute;
};
module.exports = new AdminMenuViewModel();
}(module));
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module) {
'use strict';
var
ko = require('../External/ko.js'),
Data = require('../Storages/AdminDataStorage.js'),
Remote = require('../Storages/AdminAjaxRemoteStorage.js'),
RL = require('../RL.js'),
kn = require('../Knoin/Knoin.js'),
KnoinAbstractViewModel = require('../Knoin/KnoinAbstractViewModel.js')
;
/**
* @constructor
* @extends KnoinAbstractViewModel
*/
function AdminPaneViewModel()
{
KnoinAbstractViewModel.call(this, 'Right', 'AdminPane');
this.adminDomain = ko.observable(RL().settingsGet('AdminDomain'));
this.version = ko.observable(RL().settingsGet('Version'));
this.adminManLoadingVisibility = Data.adminManLoadingVisibility;
kn.constructorEnd(this);
}
kn.extendAsViewModel('AdminPaneViewModel', AdminPaneViewModel);
AdminPaneViewModel.prototype.logoutClick = function ()
{
Remote.adminLogout(function () {
RL().loginAndLogoutReload();
});
};
module.exports = new AdminPaneViewModel();
}(module));
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module) {
'use strict';
var
ko = require('../External/ko.js'),
key = require('../External/key.js'),
Enums = require('../Common/Enums.js'),
Globals = require('../Common/Globals.js'),
Utils = require('../Common/Utils.js'),
RL = require('../RL.js')
;
/**
* @constructor
*/
function AbstractData()
{
var self = this;
this.leftPanelDisabled = ko.observable(false);
this.useKeyboardShortcuts = ko.observable(true);
this.keyScopeReal = ko.observable(Enums.KeyState.All);
this.keyScopeFake = ko.observable(Enums.KeyState.All);
this.keyScope = ko.computed({
'owner': this,
'read': function () {
return this.keyScopeFake();
},
'write': function (sValue) {
if (Enums.KeyState.Menu !== sValue)
{
if (Enums.KeyState.Compose === sValue)
{
Utils.disableKeyFilter(self);
}
else
{
Utils.restoreKeyFilter(self);
}
this.keyScopeFake(sValue);
if (Globals.dropdownVisibility())
{
sValue = Enums.KeyState.Menu;
}
}
this.keyScopeReal(sValue);
}
});
this.keyScopeReal.subscribe(function (sValue) {
// window.console.log(sValue);
key.setScope(sValue);
});
this.leftPanelDisabled.subscribe(function (bValue) {
RL().pub('left-panel.' + (bValue ? 'off' : 'on'));
});
Globals.dropdownVisibility.subscribe(function (bValue) {
if (bValue)
{
Globals.tooltipTrigger(!Globals.tooltipTrigger());
this.keyScope(Enums.KeyState.Menu);
}
else if (Enums.KeyState.Menu === key.getScope())
{
this.keyScope(this.keyScopeFake());
}
}, this);
Utils.initDataConstructorBySettings(this);
}
AbstractData.prototype.populateDataOnStart = function()
{
var
mLayout = Utils.pInt(RL().settingsGet('Layout')), // TODO cjs
aLanguages = RL().settingsGet('Languages'),
aThemes = RL().settingsGet('Themes')
;
if (Utils.isArray(aLanguages))
{
this.languages(aLanguages);
}
if (Utils.isArray(aThemes))
{
this.themes(aThemes);
}
this.mainLanguage(RL().settingsGet('Language'));
this.mainTheme(RL().settingsGet('Theme'));
this.capaAdditionalAccounts(RL().capa(Enums.Capa.AdditionalAccounts));
this.capaAdditionalIdentities(RL().capa(Enums.Capa.AdditionalIdentities));
this.capaGravatar(RL().capa(Enums.Capa.Gravatar));
this.determineUserLanguage(!!RL().settingsGet('DetermineUserLanguage'));
this.determineUserDomain(!!RL().settingsGet('DetermineUserDomain'));
this.capaThemes(RL().capa(Enums.Capa.Themes));
this.allowLanguagesOnLogin(!!RL().settingsGet('AllowLanguagesOnLogin'));
this.allowLanguagesOnSettings(!!RL().settingsGet('AllowLanguagesOnSettings'));
this.useLocalProxyForExternalImages(!!RL().settingsGet('UseLocalProxyForExternalImages'));
this.editorDefaultType(RL().settingsGet('EditorDefaultType'));
this.showImages(!!RL().settingsGet('ShowImages'));
this.contactsAutosave(!!RL().settingsGet('ContactsAutosave'));
this.interfaceAnimation(RL().settingsGet('InterfaceAnimation'));
this.mainMessagesPerPage(RL().settingsGet('MPP'));
this.desktopNotifications(!!RL().settingsGet('DesktopNotifications'));
this.useThreads(!!RL().settingsGet('UseThreads'));
this.replySameFolder(!!RL().settingsGet('ReplySameFolder'));
this.useCheckboxesInList(!!RL().settingsGet('UseCheckboxesInList'));
this.layout(Enums.Layout.SidePreview);
if (-1 < Utils.inArray(mLayout, [Enums.Layout.NoPreview, Enums.Layout.SidePreview, Enums.Layout.BottomPreview]))
{
this.layout(mLayout);
}
this.facebookSupported(!!RL().settingsGet('SupportedFacebookSocial'));
this.facebookEnable(!!RL().settingsGet('AllowFacebookSocial'));
this.facebookAppID(RL().settingsGet('FacebookAppID'));
this.facebookAppSecret(RL().settingsGet('FacebookAppSecret'));
this.twitterEnable(!!RL().settingsGet('AllowTwitterSocial'));
this.twitterConsumerKey(RL().settingsGet('TwitterConsumerKey'));
this.twitterConsumerSecret(RL().settingsGet('TwitterConsumerSecret'));
this.googleEnable(!!RL().settingsGet('AllowGoogleSocial'));
this.googleClientID(RL().settingsGet('GoogleClientID'));
this.googleClientSecret(RL().settingsGet('GoogleClientSecret'));
this.googleApiKey(RL().settingsGet('GoogleApiKey'));
this.dropboxEnable(!!RL().settingsGet('AllowDropboxSocial'));
this.dropboxApiKey(RL().settingsGet('DropboxApiKey'));
this.contactsIsAllowed(!!RL().settingsGet('ContactsIsAllowed'));
};
module.exports = AbstractData;
}(module));
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module) {
'use strict';
var
$ = require('../External/jquery.js'),
_ = require('../External/underscore.js'),
ko = require('../External/ko.js'),
Globals = require('../Common/Globals.js'),
Utils = require('../Common/Utils.js'),
LinkBuilder = require('../Common/LinkBuilder.js'),
kn = require('../Knoin/Knoin.js'),
KnoinAbstractScreen = require('../Knoin/KnoinAbstractScreen.js')
;
/**
* @param {Array} aViewModels
* @constructor
* @extends KnoinAbstractScreen
*/
function AbstractSettings(aViewModels)
{
KnoinAbstractScreen.call(this, 'settings', aViewModels);
this.menu = ko.observableArray([]);
this.oCurrentSubScreen = null;
this.oViewModelPlace = null;
}
_.extend(AbstractSettings.prototype, KnoinAbstractScreen.prototype);
AbstractSettings.prototype.onRoute = function (sSubName)
{
var
self = this,
oSettingsScreen = null,
RoutedSettingsViewModel = null,
oViewModelPlace = null,
oViewModelDom = null
;
RoutedSettingsViewModel = _.find(Globals.aViewModels['settings'], function (SettingsViewModel) {
return SettingsViewModel && SettingsViewModel.__rlSettingsData &&
sSubName === SettingsViewModel.__rlSettingsData.Route;
});
if (RoutedSettingsViewModel)
{
if (_.find(Globals.aViewModels['settings-removed'], function (DisabledSettingsViewModel) {
return DisabledSettingsViewModel && DisabledSettingsViewModel === RoutedSettingsViewModel;
}))
{
RoutedSettingsViewModel = null;
}
if (RoutedSettingsViewModel && _.find(Globals.aViewModels['settings-disabled'], function (DisabledSettingsViewModel) {
return DisabledSettingsViewModel && DisabledSettingsViewModel === RoutedSettingsViewModel;
}))
{
RoutedSettingsViewModel = null;
}
}
if (RoutedSettingsViewModel)
{
if (RoutedSettingsViewModel.__builded && RoutedSettingsViewModel.__vm)
{
oSettingsScreen = RoutedSettingsViewModel.__vm;
}
else
{
oViewModelPlace = this.oViewModelPlace;
if (oViewModelPlace && 1 === oViewModelPlace.length)
{
RoutedSettingsViewModel = /** @type {?Function} */ RoutedSettingsViewModel;
oSettingsScreen = new RoutedSettingsViewModel();
oViewModelDom = $('
').addClass('rl-settings-view-model').hide();
oViewModelDom.appendTo(oViewModelPlace);
oSettingsScreen.viewModelDom = oViewModelDom;
oSettingsScreen.__rlSettingsData = RoutedSettingsViewModel.__rlSettingsData;
RoutedSettingsViewModel.__dom = oViewModelDom;
RoutedSettingsViewModel.__builded = true;
RoutedSettingsViewModel.__vm = oSettingsScreen;
ko.applyBindingAccessorsToNode(oViewModelDom[0], {
'i18nInit': true,
'template': function () { return {'name': RoutedSettingsViewModel.__rlSettingsData.Template}; }
}, oSettingsScreen);
Utils.delegateRun(oSettingsScreen, 'onBuild', [oViewModelDom]);
}
else
{
Utils.log('Cannot find sub settings view model position: SettingsSubScreen');
}
}
if (oSettingsScreen)
{
_.defer(function () {
// hide
if (self.oCurrentSubScreen)
{
Utils.delegateRun(self.oCurrentSubScreen, 'onHide');
self.oCurrentSubScreen.viewModelDom.hide();
}
// --
self.oCurrentSubScreen = oSettingsScreen;
// show
if (self.oCurrentSubScreen)
{
self.oCurrentSubScreen.viewModelDom.show();
Utils.delegateRun(self.oCurrentSubScreen, 'onShow');
Utils.delegateRun(self.oCurrentSubScreen, 'onFocus', [], 200);
_.each(self.menu(), function (oItem) {
oItem.selected(oSettingsScreen && oSettingsScreen.__rlSettingsData && oItem.route === oSettingsScreen.__rlSettingsData.Route);
});
$('#rl-content .b-settings .b-content .content').scrollTop(0);
}
// --
Utils.windowResize();
});
}
}
else
{
kn.setHash(LinkBuilder.settings(), false, true); // TODO cjs
}
};
AbstractSettings.prototype.onHide = function ()
{
if (this.oCurrentSubScreen && this.oCurrentSubScreen.viewModelDom)
{
Utils.delegateRun(this.oCurrentSubScreen, 'onHide');
this.oCurrentSubScreen.viewModelDom.hide();
}
};
AbstractSettings.prototype.onBuild = function ()
{
_.each(Globals.aViewModels['settings'], function (SettingsViewModel) {
if (SettingsViewModel && SettingsViewModel.__rlSettingsData &&
!_.find(Globals.aViewModels['settings-removed'], function (RemoveSettingsViewModel) {
return RemoveSettingsViewModel && RemoveSettingsViewModel === SettingsViewModel;
}))
{
this.menu.push({
'route': SettingsViewModel.__rlSettingsData.Route,
'label': SettingsViewModel.__rlSettingsData.Label,
'selected': ko.observable(false),
'disabled': !!_.find(Globals.aViewModels['settings-disabled'], function (DisabledSettingsViewModel) {
return DisabledSettingsViewModel && DisabledSettingsViewModel === SettingsViewModel;
})
});
}
}, this);
this.oViewModelPlace = $('#rl-content #rl-settings-subscreen');
};
AbstractSettings.prototype.routes = function ()
{
var
DefaultViewModel = _.find(Globals.aViewModels['settings'], function (SettingsViewModel) {
return SettingsViewModel && SettingsViewModel.__rlSettingsData && SettingsViewModel.__rlSettingsData['IsDefault'];
}),
sDefaultRoute = DefaultViewModel ? DefaultViewModel.__rlSettingsData['Route'] : 'general',
oRules = {
'subname': /^(.*)$/,
'normalize_': function (oRequest, oVals) {
oVals.subname = Utils.isUnd(oVals.subname) ? sDefaultRoute : Utils.pString(oVals.subname);
return [oVals.subname];
}
}
;
return [
['{subname}/', oRules],
['{subname}', oRules],
['', oRules]
];
};
module.exports = AbstractSettings;
}(module));
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module) {
'use strict';
var
_ = require('../External/underscore.js'),
KnoinAbstractScreen = require('../Knoin/KnoinAbstractScreen.js'),
AdminLoginViewModel = require('../ViewModels/AdminLoginViewModel.js')
;
/**
* @constructor
* @extends KnoinAbstractScreen
*/
function AdminLoginScreen()
{
KnoinAbstractScreen.call(this, 'login', [AdminLoginViewModel]);
}
_.extend(AdminLoginScreen.prototype, KnoinAbstractScreen.prototype);
AdminLoginScreen.prototype.onShow = function ()
{
RL.setTitle(''); // TODO cjs
};
module.exports = AdminLoginScreen;
}(module));
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module) {
'use strict';
var
_ = require('../External/underscore.js'),
AbstractSettings = require('./AbstractSettings.js'),
AdminMenuViewModel = require('../ViewModels/AdminMenuViewModel.js'),
AdminPaneViewModel = require('../ViewModels/AdminPaneViewModel.js')
;
/**
* @constructor
* @extends AbstractSettings
*/
function AdminSettingsScreen()
{
AbstractSettings.call(this, [
AdminMenuViewModel,
AdminPaneViewModel
]);
}
_.extend(AdminSettingsScreen.prototype, AbstractSettings.prototype);
AdminSettingsScreen.prototype.onShow = function ()
{
RL.setTitle(''); // TODO cjs
};
module.exports = AdminSettingsScreen;
}(module));
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module) {
'use strict';
var
$ = require('../External/jquery.js'),
_ = require('../External/underscore.js'),
ko = require('../External/ko.js'),
window = require('../External/window.js'),
$html = require('../External/$html.js'),
$window = require('../External/$window.js'),
$doc = require('../External/$doc.js'),
AppData = require('../External/AppData.js'),
Globals = require('../Common/Globals.js'),
Utils = require('../Common/Utils.js'),
Plugins = require('../Common/Plugins.js'),
LinkBuilder = require('../Common/LinkBuilder.js'),
kn = require('../Knoin/Knoin.js'),
KnoinAbstractBoot = require('../Knoin/KnoinAbstractBoot.js')
;
/**
* @param {*} Remote
* @constructor
* @extends KnoinAbstractBoot
*/
function AbstractApp(Remote)
{
KnoinAbstractBoot.call(this);
this.oSettings = null;
this.oPlugins = null;
this.oLocal = null;
this.oLink = null;
this.oSubs = {};
this.isLocalAutocomplete = true;
this.popupVisibilityNames = ko.observableArray([]);
this.popupVisibility = ko.computed(function () {
return 0 < this.popupVisibilityNames().length;
}, this);
this.iframe = $('
').appendTo('body');
$window.on('error', function (oEvent) {
if (oEvent && oEvent.originalEvent && oEvent.originalEvent.message &&
-1 === Utils.inArray(oEvent.originalEvent.message, [
'Script error.', 'Uncaught Error: Error calling method on NPObject.'
]))
{
Remote.jsError(
Utils.emptyFunction,
oEvent.originalEvent.message,
oEvent.originalEvent.filename,
oEvent.originalEvent.lineno,
window.location && window.location.toString ? window.location.toString() : '',
$html.attr('class'),
Utils.microtime() - Globals.now
);
}
});
$doc.on('keydown', function (oEvent) {
if (oEvent && oEvent.ctrlKey)
{
$html.addClass('rl-ctrl-key-pressed');
}
}).on('keyup', function (oEvent) {
if (oEvent && !oEvent.ctrlKey)
{
$html.removeClass('rl-ctrl-key-pressed');
}
});
}
_.extend(AbstractApp.prototype, KnoinAbstractBoot.prototype);
AbstractApp.prototype.oSettings = null;
AbstractApp.prototype.oPlugins = null;
AbstractApp.prototype.oLocal = null;
AbstractApp.prototype.oLink = null;
AbstractApp.prototype.oSubs = {};
/**
* @param {string} sLink
* @return {boolean}
*/
AbstractApp.prototype.download = function (sLink)
{
var
oE = null,
oLink = null,
sUserAgent = window.navigator.userAgent.toLowerCase()
;
if (sUserAgent && (sUserAgent.indexOf('chrome') > -1 || sUserAgent.indexOf('chrome') > -1))
{
oLink = window.document.createElement('a');
oLink['href'] = sLink;
if (window.document['createEvent'])
{
oE = window.document['createEvent']('MouseEvents');
if (oE && oE['initEvent'] && oLink['dispatchEvent'])
{
oE['initEvent']('click', true, true);
oLink['dispatchEvent'](oE);
return true;
}
}
}
if (Globals.bMobileDevice)
{
window.open(sLink, '_self');
window.focus();
}
else
{
this.iframe.attr('src', sLink);
// window.document.location.href = sLink;
}
return true;
};
/**
* @param {string} sName
* @return {?}
*/
AbstractApp.prototype.settingsGet = function (sName)
{
if (null === this.oSettings)
{
this.oSettings = Utils.isNormal(AppData) ? AppData : {};
}
return Utils.isUnd(this.oSettings[sName]) ? null : this.oSettings[sName];
};
/**
* @param {string} sName
* @param {?} mValue
*/
AbstractApp.prototype.settingsSet = function (sName, mValue)
{
if (null === this.oSettings)
{
this.oSettings = Utils.isNormal(AppData) ? AppData : {};
}
this.oSettings[sName] = mValue;
};
AbstractApp.prototype.setTitle = function (sTitle)
{
sTitle = ((Utils.isNormal(sTitle) && 0 < sTitle.length) ? sTitle + ' - ' : '') +
this.settingsGet('Title') || '';
window.document.title = '_';
window.document.title = sTitle;
};
/**
* @param {boolean=} bLogout = false
* @param {boolean=} bClose = false
*/
AbstractApp.prototype.loginAndLogoutReload = function (bLogout, bClose)
{
var
sCustomLogoutLink = Utils.pString(this.settingsGet('CustomLogoutLink')),
bInIframe = !!this.settingsGet('InIframe')
;
bLogout = Utils.isUnd(bLogout) ? false : !!bLogout;
bClose = Utils.isUnd(bClose) ? false : !!bClose;
if (bLogout && bClose && window.close)
{
window.close();
}
if (bLogout && '' !== sCustomLogoutLink && window.location.href !== sCustomLogoutLink)
{
_.delay(function () {
if (bInIframe && window.parent)
{
window.parent.location.href = sCustomLogoutLink;
}
else
{
window.location.href = sCustomLogoutLink;
}
}, 100);
}
else
{
kn.routeOff();
kn.setHash(LinkBuilder.root(), true);
kn.routeOff();
_.delay(function () {
if (bInIframe && window.parent)
{
window.parent.location.reload();
}
else
{
window.location.reload();
}
}, 100);
}
};
AbstractApp.prototype.historyBack = function ()
{
window.history.back();
};
/**
* @param {string} sQuery
* @param {Function} fCallback
*/
AbstractApp.prototype.getAutocomplete = function (sQuery, fCallback)
{
fCallback([], sQuery);
};
/**
* @param {string} sName
* @param {Function} fFunc
* @param {Object=} oContext
* @return {AbstractApp}
*/
AbstractApp.prototype.sub = function (sName, fFunc, oContext)
{
if (Utils.isUnd(this.oSubs[sName]))
{
this.oSubs[sName] = [];
}
this.oSubs[sName].push([fFunc, oContext]);
return this;
};
/**
* @param {string} sName
* @param {Array=} aArgs
* @return {AbstractApp}
*/
AbstractApp.prototype.pub = function (sName, aArgs)
{
Plugins.runHook('rl-pub', [sName, aArgs]);
if (!Utils.isUnd(this.oSubs[sName]))
{
_.each(this.oSubs[sName], function (aItem) {
if (aItem[0])
{
aItem[0].apply(aItem[1] || null, aArgs || []);
}
});
}
return this;
};
/**
* @param {string} sName
* @return {boolean}
*/
AbstractApp.prototype.capa = function (sName)
{
var mCapa = this.settingsGet('Capa');
return Utils.isArray(mCapa) && Utils.isNormal(sName) && -1 < Utils.inArray(sName, mCapa);
};
AbstractApp.prototype.bootstart = function (Data)
{
var
self = this,
ssm = require('../External/ssm.js')
;
Utils.initOnStartOrLangChange(function () {
Utils.initNotificationLanguage();
}, null);
_.delay(function () {
Utils.windowResize();
}, 1000);
ssm.addState({
'id': 'mobile',
'maxWidth': 767,
'onEnter': function() {
$html.addClass('ssm-state-mobile');
self.pub('ssm.mobile-enter');
},
'onLeave': function() {
$html.removeClass('ssm-state-mobile');
self.pub('ssm.mobile-leave');
}
});
ssm.addState({
'id': 'tablet',
'minWidth': 768,
'maxWidth': 999,
'onEnter': function() {
$html.addClass('ssm-state-tablet');
},
'onLeave': function() {
$html.removeClass('ssm-state-tablet');
}
});
ssm.addState({
'id': 'desktop',
'minWidth': 1000,
'maxWidth': 1400,
'onEnter': function() {
$html.addClass('ssm-state-desktop');
},
'onLeave': function() {
$html.removeClass('ssm-state-desktop');
}
});
ssm.addState({
'id': 'desktop-large',
'minWidth': 1400,
'onEnter': function() {
$html.addClass('ssm-state-desktop-large');
},
'onLeave': function() {
$html.removeClass('ssm-state-desktop-large');
}
});
this.sub('ssm.mobile-enter', function () {
Data.leftPanelDisabled(true);
});
this.sub('ssm.mobile-leave', function () {
Data.leftPanelDisabled(false);
});
Data.leftPanelDisabled.subscribe(function (bValue) {
$html.toggleClass('rl-left-panel-disabled', bValue);
});
ssm.ready();
};
module.exports = AbstractApp;
}(module));
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module) {
'use strict';
var
ko = require('../External/ko.js'),
_ = require('../External/underscore.js'),
window = require('../External/window.js'),
Enums = require('../Common/Enums.js'),
Utils = require('../Common/Utils.js'),
LinkBuilder = require('../Common/LinkBuilder.js'),
kn = require('../Knoin/Knoin.js'),
Data = require('../Storages/AdminDataStorage.js'),
Remote = require('../Storages/AdminAjaxRemoteStorage.js'),
AbstractApp = require('./AbstractApp.js')
;
/**
* @constructor
* @extends AbstractApp
*/
function AdminApp()
{
AbstractApp.call(this, Remote);
this.oData = null;
this.oRemote = null;
this.oCache = null;
}
_.extend(AdminApp.prototype, AbstractApp.prototype);
AdminApp.prototype.oData = null;
AdminApp.prototype.oRemote = null;
AdminApp.prototype.oCache = null;
/**
* @return {AdminDataStorage}
*/
AdminApp.prototype.data = function ()
{
if (null === this.oData)
{
this.oData = new AdminDataStorage(); // TODO cjs
}
return this.oData;
};
/**
* @return {AdminAjaxRemoteStorage}
*/
AdminApp.prototype.remote = function ()
{
if (null === this.oRemote)
{
this.oRemote = new AdminAjaxRemoteStorage(); // TODO cjs
}
return this.oRemote;
};
AdminApp.prototype.reloadDomainList = function ()
{
// TODO cjs
Data.domainsLoading(true);
Remote.domainList(function (sResult, oData) {
Data.domainsLoading(false);
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
{
var aList = _.map(oData.Result, function (bEnabled, sName) {
return {
'name': sName,
'disabled': ko.observable(!bEnabled),
'deleteAccess': ko.observable(false)
};
}, this);
Data.domains(aList);
}
});
};
AdminApp.prototype.reloadPluginList = function ()
{
// TODO cjs
Data.pluginsLoading(true);
Remote.pluginList(function (sResult, oData) {
Data.pluginsLoading(false);
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
{
var aList = _.map(oData.Result, function (oItem) {
return {
'name': oItem['Name'],
'disabled': ko.observable(!oItem['Enabled']),
'configured': ko.observable(!!oItem['Configured'])
};
}, this);
Data.plugins(aList);
}
});
};
AdminApp.prototype.reloadPackagesList = function ()
{
// TODO cjs
Data.packagesLoading(true);
Data.packagesReal(true);
Remote.packagesList(function (sResult, oData) {
Data.packagesLoading(false);
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
{
Data.packagesReal(!!oData.Result.Real);
Data.packagesMainUpdatable(!!oData.Result.MainUpdatable);
var
aList = [],
aLoading = {}
;
_.each(Data.packages(), function (oItem) {
if (oItem && oItem['loading']())
{
aLoading[oItem['file']] = oItem;
}
});
if (Utils.isArray(oData.Result.List))
{
aList = _.compact(_.map(oData.Result.List, function (oItem) {
if (oItem)
{
oItem['loading'] = ko.observable(!Utils.isUnd(aLoading[oItem['file']]));
return 'core' === oItem['type'] && !oItem['canBeInstalled'] ? null : oItem;
}
return null;
}));
}
Data.packages(aList);
}
else
{
Data.packagesReal(false);
}
});
};
AdminApp.prototype.updateCoreData = function ()
{
Data.coreUpdating(true);
Remote.updateCoreData(function (sResult, oData) {
Data.coreUpdating(false);
Data.coreRemoteVersion('');
Data.coreRemoteRelease('');
Data.coreVersionCompare(-2);
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
{
Data.coreReal(true);
window.location.reload();
}
else
{
Data.coreReal(false);
}
});
};
AdminApp.prototype.reloadCoreData = function ()
{
Data.coreChecking(true);
Data.coreReal(true);
Remote.coreData(function (sResult, oData) {
Data.coreChecking(false);
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
{
Data.coreReal(!!oData.Result.Real);
Data.coreUpdatable(!!oData.Result.Updatable);
Data.coreAccess(!!oData.Result.Access);
Data.coreRemoteVersion(oData.Result.RemoteVersion || '');
Data.coreRemoteRelease(oData.Result.RemoteRelease || '');
Data.coreVersionCompare(Utils.pInt(oData.Result.VersionCompare));
}
else
{
Data.coreReal(false);
Data.coreRemoteVersion('');
Data.coreRemoteRelease('');
Data.coreVersionCompare(-2);
}
});
};
/**
*
* @param {boolean=} bForce = false
*/
AdminApp.prototype.reloadLicensing = function (bForce)
{
bForce = Utils.isUnd(bForce) ? false : !!bForce;
// TODO cjs
Data.licensingProcess(true);
Data.licenseError('');
Remote.licensing(function (sResult, oData) {
Data.licensingProcess(false);
if (Enums.StorageResultType.Success === sResult && oData && oData.Result && Utils.isNormal(oData.Result['Expired']))
{
Data.licenseValid(true);
Data.licenseExpired(Utils.pInt(oData.Result['Expired']));
Data.licenseError('');
Data.licensing(true);
}
else
{
if (oData && oData.ErrorCode && -1 < Utils.inArray(Utils.pInt(oData.ErrorCode), [
Enums.Notification.LicensingServerIsUnavailable,
Enums.Notification.LicensingExpired
]))
{
Data.licenseError(Utils.getNotification(Utils.pInt(oData.ErrorCode)));
Data.licensing(true);
}
else
{
if (Enums.StorageResultType.Abort === sResult)
{
Data.licenseError(Utils.getNotification(Enums.Notification.LicensingServerIsUnavailable));
Data.licensing(true);
}
else
{
Data.licensing(false);
}
}
}
}, bForce);
};
AdminApp.prototype.bootstart = function ()
{
AbstractApp.prototype.bootstart.call(this, Data);
Data.populateDataOnStart();
kn.hideLoading();
if (!RL.settingsGet('AllowAdminPanel'))
{
kn.routeOff();
kn.setHash(LinkBuilder.root(), true);
kn.routeOff();
_.defer(function () {
window.location.href = '/';
});
}
else
{
// kn.removeSettingsViewModel(AdminAbout);
if (!RL.capa(Enums.Capa.Prem))
{
kn.removeSettingsViewModel(AdminBranding);
}
if (!!RL.settingsGet('Auth'))
{
// TODO
// if (!RL.settingsGet('AllowPackages') && AdminPackages)
// {
// kn.disableSettingsViewModel(AdminPackages);
// }
kn.startScreens([AdminSettingsScreen]);
}
else
{
kn.startScreens([AdminLoginScreen]);
}
}
if (window.SimplePace)
{
window.SimplePace.set(100);
}
};
module.exports = new AdminApp();
}(module));
}(window, jQuery, ko, crossroads, hasher, _));