]*>([\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(Math.round((iPrev - 1) / 2), false, '...');
}
if (iPageCount - 2 === iNext)
{
fAdd(iPageCount - 1, true);
}
else if (iPageCount - 2 > iNext)
{
fAdd(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 = document.createRange();
range.selectNodeContents(element);
sel.addRange(range);
}
else if (document.selection)
{
var textRange = document.body.createTextRange();
textRange.moveToElementText(element);
textRange.select();
}
/* jshint onevar: true */
};
Utils.disableKeyFilter = function ()
{
if (window.key)
{
key.filter = function () {
return RL.data().useKeyboardShortcuts();
};
}
};
Utils.restoreKeyFilter = function ()
{
if (window.key)
{
key.filter = function (event) {
if (RL.data().useKeyboardShortcuts())
{
var
element = event.target || event.srcElement,
tagName = element ? element.tagName : ''
;
tagName = tagName.toUpperCase();
return !(tagName === 'INPUT' || tagName === 'SELECT' || tagName === 'TEXTAREA' ||
(element && tagName === 'DIV' && 'editorHtmlArea' === element.className && element.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));
},{"../External/$doc.js":11,"../External/$window.js":13,"../External/NotificationClass.js":16,"../External/jquery.js":19,"../External/key.js":20,"../External/ko.js":21,"../External/underscore.js":24,"../External/window.js":25,"../Knoin/Knoin.js":26,"../Storages/LocalStorage.js":36,"./Enums.js":5,"./Globals.js":6}],10:[function(require,module,exports){
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
'use strict';
module.exports = require('./jquery.js')('
');
},{"./jquery.js":19}],11:[function(require,module,exports){
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
'use strict';
module.exports = require('./jquery.js')(window.document);
},{"./jquery.js":19}],12:[function(require,module,exports){
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
'use strict';
module.exports = require('./jquery.js')('html');
},{"./jquery.js":19}],13:[function(require,module,exports){
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
'use strict';
module.exports = require('./jquery.js')(window);
},{"./jquery.js":19}],14:[function(require,module,exports){
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
'use strict';
module.exports = require('./window.js')['rainloopAppData'] || {};
},{"./window.js":25}],15:[function(require,module,exports){
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
'use strict';
module.exports = JSON;
},{}],16:[function(require,module,exports){
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
'use strict';
var
window = require('./window.js')
;
module.exports = window.Notification && window.Notification.requestPermission ? window.Notification : null;
},{"./window.js":25}],17:[function(require,module,exports){
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
'use strict';
module.exports = crossroads;
},{}],18:[function(require,module,exports){
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
'use strict';
module.exports = hasher;
},{}],19:[function(require,module,exports){
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
'use strict';
module.exports = $;
},{}],20:[function(require,module,exports){
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
'use strict';
module.exports = key;
},{}],21:[function(require,module,exports){
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module) {
'use strict';
var
$ = require('./jquery.js'),
_ = require('./underscore.js'),
window = require('./window.js'),
$window = require('./$window.js'),
$doc = require('./$doc.js'),
Globals = require('../Common/Globals.js'),
Utils = require('../Common/Utils.js'),
RL = require('../RL.js')
;
ko.bindingHandlers.tooltip = {
'init': function (oElement, fValueAccessor) {
if (!Globals.bMobileDevice)
{
var
$oEl = $(oElement),
sClass = $oEl.data('tooltip-class') || '',
sPlacement = $oEl.data('tooltip-placement') || 'top'
;
$oEl.tooltip({
'delay': {
'show': 500,
'hide': 100
},
'html': true,
'container': 'body',
'placement': sPlacement,
'trigger': 'hover',
'title': function () {
return $oEl.is('.disabled') || Globals.dropdownVisibility() ? '' : '
' +
Utils.i18n(ko.utils.unwrapObservable(fValueAccessor())) + '';
}
}).click(function () {
$oEl.tooltip('hide');
});
Globals.tooltipTrigger.subscribe(function () {
$oEl.tooltip('hide');
});
}
}
};
ko.bindingHandlers.tooltip2 = {
'init': function (oElement, fValueAccessor) {
var
$oEl = $(oElement),
sClass = $oEl.data('tooltip-class') || '',
sPlacement = $oEl.data('tooltip-placement') || 'top'
;
$oEl.tooltip({
'delay': {
'show': 500,
'hide': 100
},
'html': true,
'container': 'body',
'placement': sPlacement,
'title': function () {
return $oEl.is('.disabled') || Globals.dropdownVisibility() ? '' :
'
' + fValueAccessor()() + '';
}
}).click(function () {
$oEl.tooltip('hide');
});
Globals.tooltipTrigger.subscribe(function () {
$oEl.tooltip('hide');
});
}
};
ko.bindingHandlers.tooltip3 = {
'init': function (oElement) {
var $oEl = $(oElement);
$oEl.tooltip({
'container': 'body',
'trigger': 'hover manual',
'title': function () {
return $oEl.data('tooltip3-data') || '';
}
});
$doc.click(function () {
$oEl.tooltip('hide');
});
Globals.tooltipTrigger.subscribe(function () {
$oEl.tooltip('hide');
});
},
'update': function (oElement, fValueAccessor) {
var sValue = ko.utils.unwrapObservable(fValueAccessor());
if ('' === sValue)
{
$(oElement).data('tooltip3-data', '').tooltip('hide');
}
else
{
$(oElement).data('tooltip3-data', sValue).tooltip('show');
}
}
};
ko.bindingHandlers.registrateBootstrapDropdown = {
'init': function (oElement) {
Globals.aBootstrapDropdowns.push($(oElement));
}
};
ko.bindingHandlers.openDropdownTrigger = {
'update': function (oElement, fValueAccessor) {
if (ko.utils.unwrapObservable(fValueAccessor()))
{
var $el = $(oElement);
if (!$el.hasClass('open'))
{
$el.find('.dropdown-toggle').dropdown('toggle');
Utils.detectDropdownVisibility();
}
fValueAccessor()(false);
}
}
};
ko.bindingHandlers.dropdownCloser = {
'init': function (oElement) {
$(oElement).closest('.dropdown').on('click', '.e-item', function () {
$(oElement).dropdown('toggle');
});
}
};
ko.bindingHandlers.popover = {
'init': function (oElement, fValueAccessor) {
$(oElement).popover(ko.utils.unwrapObservable(fValueAccessor()));
}
};
ko.bindingHandlers.csstext = {
'init': function (oElement, fValueAccessor) {
if (oElement && oElement.styleSheet && !Utils.isUnd(oElement.styleSheet.cssText))
{
oElement.styleSheet.cssText = ko.utils.unwrapObservable(fValueAccessor());
}
else
{
$(oElement).text(ko.utils.unwrapObservable(fValueAccessor()));
}
},
'update': function (oElement, fValueAccessor) {
if (oElement && oElement.styleSheet && !Utils.isUnd(oElement.styleSheet.cssText))
{
oElement.styleSheet.cssText = ko.utils.unwrapObservable(fValueAccessor());
}
else
{
$(oElement).text(ko.utils.unwrapObservable(fValueAccessor()));
}
}
};
ko.bindingHandlers.resizecrop = {
'init': function (oElement) {
$(oElement).addClass('resizecrop').resizecrop({
'width': '100',
'height': '100',
'wrapperCSS': {
'border-radius': '10px'
}
});
},
'update': function (oElement, fValueAccessor) {
fValueAccessor()();
$(oElement).resizecrop({
'width': '100',
'height': '100'
});
}
};
ko.bindingHandlers.onEnter = {
'init': function (oElement, fValueAccessor, fAllBindingsAccessor, oViewModel) {
$(oElement).on('keypress', function (oEvent) {
if (oEvent && 13 === window.parseInt(oEvent.keyCode, 10))
{
$(oElement).trigger('change');
fValueAccessor().call(oViewModel);
}
});
}
};
ko.bindingHandlers.onEsc = {
'init': function (oElement, fValueAccessor, fAllBindingsAccessor, oViewModel) {
$(oElement).on('keypress', function (oEvent) {
if (oEvent && 27 === window.parseInt(oEvent.keyCode, 10))
{
$(oElement).trigger('change');
fValueAccessor().call(oViewModel);
}
});
}
};
ko.bindingHandlers.clickOnTrue = {
'update': function (oElement, fValueAccessor) {
if (ko.utils.unwrapObservable(fValueAccessor()))
{
$(oElement).click();
}
}
};
ko.bindingHandlers.modal = {
'init': function (oElement, fValueAccessor) {
$(oElement).toggleClass('fade', !Globals.bMobileDevice).modal({
'keyboard': false,
'show': ko.utils.unwrapObservable(fValueAccessor())
})
.on('shown', function () {
Utils.windowResize();
})
.find('.close').click(function () {
fValueAccessor()(false);
});
},
'update': function (oElement, fValueAccessor) {
$(oElement).modal(ko.utils.unwrapObservable(fValueAccessor()) ? 'show' : 'hide');
}
};
ko.bindingHandlers.i18nInit = {
'init': function (oElement) {
Utils.i18nToNode(oElement);
}
};
ko.bindingHandlers.i18nUpdate = {
'update': function (oElement, fValueAccessor) {
ko.utils.unwrapObservable(fValueAccessor());
Utils.i18nToNode(oElement);
}
};
ko.bindingHandlers.link = {
'update': function (oElement, fValueAccessor) {
$(oElement).attr('href', ko.utils.unwrapObservable(fValueAccessor()));
}
};
ko.bindingHandlers.title = {
'update': function (oElement, fValueAccessor) {
$(oElement).attr('title', ko.utils.unwrapObservable(fValueAccessor()));
}
};
ko.bindingHandlers.textF = {
'init': function (oElement, fValueAccessor) {
$(oElement).text(ko.utils.unwrapObservable(fValueAccessor()));
}
};
ko.bindingHandlers.initDom = {
'init': function (oElement, fValueAccessor) {
fValueAccessor()(oElement);
}
};
ko.bindingHandlers.initResizeTrigger = {
'init': function (oElement, fValueAccessor) {
var aValues = ko.utils.unwrapObservable(fValueAccessor());
$(oElement).css({
'height': aValues[1],
'min-height': aValues[1]
});
},
'update': function (oElement, fValueAccessor) {
var
aValues = ko.utils.unwrapObservable(fValueAccessor()),
iValue = Utils.pInt(aValues[1]),
iSize = 0,
iOffset = $(oElement).offset().top
;
if (0 < iOffset)
{
iOffset += Utils.pInt(aValues[2]);
iSize = $window.height() - iOffset;
if (iValue < iSize)
{
iValue = iSize;
}
$(oElement).css({
'height': iValue,
'min-height': iValue
});
}
}
};
ko.bindingHandlers.appendDom = {
'update': function (oElement, fValueAccessor) {
$(oElement).hide().empty().append(ko.utils.unwrapObservable(fValueAccessor())).show();
}
};
ko.bindingHandlers.draggable = {
'init': function (oElement, fValueAccessor, fAllBindingsAccessor) {
if (!Globals.bMobileDevice)
{
var
iTriggerZone = 100,
iScrollSpeed = 3,
fAllValueFunc = fAllBindingsAccessor(),
sDroppableSelector = fAllValueFunc && fAllValueFunc['droppableSelector'] ? fAllValueFunc['droppableSelector'] : '',
oConf = {
'distance': 20,
'handle': '.dragHandle',
'cursorAt': {'top': 22, 'left': 3},
'refreshPositions': true,
'scroll': true
}
;
if (sDroppableSelector)
{
oConf['drag'] = function (oEvent) {
$(sDroppableSelector).each(function () {
var
moveUp = null,
moveDown = null,
$this = $(this),
oOffset = $this.offset(),
bottomPos = oOffset.top + $this.height()
;
window.clearInterval($this.data('timerScroll'));
$this.data('timerScroll', false);
if (oEvent.pageX >= oOffset.left && oEvent.pageX <= oOffset.left + $this.width())
{
if (oEvent.pageY >= bottomPos - iTriggerZone && oEvent.pageY <= bottomPos)
{
moveUp = function() {
$this.scrollTop($this.scrollTop() + iScrollSpeed);
Utils.windowResize();
};
$this.data('timerScroll', window.setInterval(moveUp, 10));
moveUp();
}
if (oEvent.pageY >= oOffset.top && oEvent.pageY <= oOffset.top + iTriggerZone)
{
moveDown = function() {
$this.scrollTop($this.scrollTop() - iScrollSpeed);
Utils.windowResize();
};
$this.data('timerScroll', window.setInterval(moveDown, 10));
moveDown();
}
}
});
};
oConf['stop'] = function() {
$(sDroppableSelector).each(function () {
window.clearInterval($(this).data('timerScroll'));
$(this).data('timerScroll', false);
});
};
}
oConf['helper'] = function (oEvent) {
return fValueAccessor()(oEvent && oEvent.target ? ko.dataFor(oEvent.target) : null);
};
$(oElement).draggable(oConf).on('mousedown', function () {
Utils.removeInFocus();
});
}
}
};
ko.bindingHandlers.droppable = {
'init': function (oElement, fValueAccessor, fAllBindingsAccessor) {
if (!Globals.bMobileDevice)
{
var
fValueFunc = fValueAccessor(),
fAllValueFunc = fAllBindingsAccessor(),
fOverCallback = fAllValueFunc && fAllValueFunc['droppableOver'] ? fAllValueFunc['droppableOver'] : null,
fOutCallback = fAllValueFunc && fAllValueFunc['droppableOut'] ? fAllValueFunc['droppableOut'] : null,
oConf = {
'tolerance': 'pointer',
'hoverClass': 'droppableHover'
}
;
if (fValueFunc)
{
oConf['drop'] = function (oEvent, oUi) {
fValueFunc(oEvent, oUi);
};
if (fOverCallback)
{
oConf['over'] = function (oEvent, oUi) {
fOverCallback(oEvent, oUi);
};
}
if (fOutCallback)
{
oConf['out'] = function (oEvent, oUi) {
fOutCallback(oEvent, oUi);
};
}
$(oElement).droppable(oConf);
}
}
}
};
ko.bindingHandlers.nano = {
'init': function (oElement) {
if (!Globals.bDisableNanoScroll)
{
$(oElement)
.addClass('nano')
.nanoScroller({
'iOSNativeScrolling': false,
'preventPageScrolling': true
})
;
}
}
};
ko.bindingHandlers.saveTrigger = {
'init': function (oElement) {
var $oEl = $(oElement);
$oEl.data('save-trigger-type', $oEl.is('input[type=text],input[type=email],input[type=password],select,textarea') ? 'input' : 'custom');
if ('custom' === $oEl.data('save-trigger-type'))
{
$oEl.append(
'
'
).addClass('settings-saved-trigger');
}
else
{
$oEl.addClass('settings-saved-trigger-input');
}
},
'update': function (oElement, fValueAccessor) {
var
mValue = ko.utils.unwrapObservable(fValueAccessor()),
$oEl = $(oElement)
;
if ('custom' === $oEl.data('save-trigger-type'))
{
switch (mValue.toString())
{
case '1':
$oEl
.find('.animated,.error').hide().removeClass('visible')
.end()
.find('.success').show().addClass('visible')
;
break;
case '0':
$oEl
.find('.animated,.success').hide().removeClass('visible')
.end()
.find('.error').show().addClass('visible')
;
break;
case '-2':
$oEl
.find('.error,.success').hide().removeClass('visible')
.end()
.find('.animated').show().addClass('visible')
;
break;
default:
$oEl
.find('.animated').hide()
.end()
.find('.error,.success').removeClass('visible')
;
break;
}
}
else
{
switch (mValue.toString())
{
case '1':
$oEl.addClass('success').removeClass('error');
break;
case '0':
$oEl.addClass('error').removeClass('success');
break;
case '-2':
// $oEl;
break;
default:
$oEl.removeClass('error success');
break;
}
}
}
};
ko.bindingHandlers.emailsTags = {
'init': function(oElement, fValueAccessor) {
var
$oEl = $(oElement),
fValue = fValueAccessor(),
fFocusCallback = function (bValue) {
if (fValue && fValue.focusTrigger)
{
fValue.focusTrigger(bValue);
}
}
;
$oEl.inputosaurus({
'parseOnBlur': true,
'allowDragAndDrop': true,
'focusCallback': fFocusCallback,
'inputDelimiters': [',', ';'],
'autoCompleteSource': function (oData, fResponse) {
RL().getAutocomplete(oData.term, function (aData) {
fResponse(_.map(aData, function (oEmailItem) {
return oEmailItem.toLine(false);
}));
});
},
'parseHook': function (aInput) {
return _.map(aInput, function (sInputValue) {
var
sValue = Utils.trim(sInputValue),
oEmail = null
;
if ('' !== sValue)
{
oEmail = new EmailModel();
oEmail.mailsoParse(sValue);
oEmail.clearDuplicateName();
return [oEmail.toLine(false), oEmail];
}
return [sValue, null];
});
},
'change': _.bind(function (oEvent) {
$oEl.data('EmailsTagsValue', oEvent.target.value);
fValue(oEvent.target.value);
}, this)
});
},
'update': function (oElement, fValueAccessor, fAllBindingsAccessor) {
var
$oEl = $(oElement),
fAllValueFunc = fAllBindingsAccessor(),
fEmailsTagsFilter = fAllValueFunc['emailsTagsFilter'] || null,
sValue = ko.utils.unwrapObservable(fValueAccessor())
;
if ($oEl.data('EmailsTagsValue') !== sValue)
{
$oEl.val(sValue);
$oEl.data('EmailsTagsValue', sValue);
$oEl.inputosaurus('refresh');
}
if (fEmailsTagsFilter && ko.utils.unwrapObservable(fEmailsTagsFilter))
{
$oEl.inputosaurus('focus');
}
}
};
ko.bindingHandlers.contactTags = {
'init': function(oElement, fValueAccessor) {
var
$oEl = $(oElement),
fValue = fValueAccessor(),
fFocusCallback = function (bValue) {
if (fValue && fValue.focusTrigger)
{
fValue.focusTrigger(bValue);
}
}
;
$oEl.inputosaurus({
'parseOnBlur': true,
'allowDragAndDrop': false,
'focusCallback': fFocusCallback,
'inputDelimiters': [',', ';'],
'outputDelimiter': ',',
'autoCompleteSource': function (oData, fResponse) {
RL().getContactTagsAutocomplete(oData.term, function (aData) {
fResponse(_.map(aData, function (oTagItem) {
return oTagItem.toLine(false);
}));
});
},
'parseHook': function (aInput) {
return _.map(aInput, function (sInputValue) {
var
sValue = Utils.trim(sInputValue),
oTag = null
;
if ('' !== sValue)
{
oTag = new ContactTagModel();
oTag.name(sValue);
return [oTag.toLine(false), oTag];
}
return [sValue, null];
});
},
'change': _.bind(function (oEvent) {
$oEl.data('ContactTagsValue', oEvent.target.value);
fValue(oEvent.target.value);
}, this)
});
},
'update': function (oElement, fValueAccessor, fAllBindingsAccessor) {
var
$oEl = $(oElement),
fAllValueFunc = fAllBindingsAccessor(),
fContactTagsFilter = fAllValueFunc['contactTagsFilter'] || null,
sValue = ko.utils.unwrapObservable(fValueAccessor())
;
if ($oEl.data('ContactTagsValue') !== sValue)
{
$oEl.val(sValue);
$oEl.data('ContactTagsValue', sValue);
$oEl.inputosaurus('refresh');
}
if (fContactTagsFilter && ko.utils.unwrapObservable(fContactTagsFilter))
{
$oEl.inputosaurus('focus');
}
}
};
ko.bindingHandlers.command = {
'init': function (oElement, fValueAccessor, fAllBindingsAccessor, oViewModel) {
var
jqElement = $(oElement),
oCommand = fValueAccessor()
;
if (!oCommand || !oCommand.enabled || !oCommand.canExecute)
{
throw new Error('You are not using command function');
}
jqElement.addClass('command');
ko.bindingHandlers[jqElement.is('form') ? 'submit' : 'click'].init.apply(oViewModel, arguments);
},
'update': function (oElement, fValueAccessor) {
var
bResult = true,
jqElement = $(oElement),
oCommand = fValueAccessor()
;
bResult = oCommand.enabled();
jqElement.toggleClass('command-not-enabled', !bResult);
if (bResult)
{
bResult = oCommand.canExecute();
jqElement.toggleClass('command-can-not-be-execute', !bResult);
}
jqElement.toggleClass('command-disabled disable disabled', !bResult).toggleClass('no-disabled', !!bResult);
if (jqElement.is('input') || jqElement.is('button'))
{
jqElement.prop('disabled', !bResult);
}
}
};
ko.extenders.trimmer = function (oTarget)
{
var oResult = ko.computed({
'read': oTarget,
'write': function (sNewValue) {
oTarget(Utils.trim(sNewValue.toString()));
},
'owner': this
});
oResult(oTarget());
return oResult;
};
ko.extenders.posInterer = function (oTarget, iDefault)
{
var oResult = ko.computed({
'read': oTarget,
'write': function (sNewValue) {
var iNew = Utils.pInt(sNewValue.toString(), iDefault);
if (0 >= iNew)
{
iNew = iDefault;
}
if (iNew === oTarget() && '' + iNew !== '' + sNewValue)
{
oTarget(iNew + 1);
}
oTarget(iNew);
}
});
oResult(oTarget());
return oResult;
};
ko.extenders.reversible = function (oTarget)
{
var mValue = oTarget();
oTarget.commit = function ()
{
mValue = oTarget();
};
oTarget.reverse = function ()
{
oTarget(mValue);
};
oTarget.commitedValue = function ()
{
return mValue;
};
return oTarget;
};
ko.extenders.toggleSubscribe = function (oTarget, oOptions)
{
oTarget.subscribe(oOptions[1], oOptions[0], 'beforeChange');
oTarget.subscribe(oOptions[2], oOptions[0]);
return oTarget;
};
ko.extenders.falseTimeout = function (oTarget, iOption)
{
oTarget.iTimeout = 0;
oTarget.subscribe(function (bValue) {
if (bValue)
{
window.clearTimeout(oTarget.iTimeout);
oTarget.iTimeout = window.setTimeout(function () {
oTarget(false);
oTarget.iTimeout = 0;
}, Utils.pInt(iOption));
}
});
return oTarget;
};
ko.observable.fn.validateNone = function ()
{
this.hasError = ko.observable(false);
return this;
};
ko.observable.fn.validateEmail = function ()
{
this.hasError = ko.observable(false);
this.subscribe(function (sValue) {
sValue = Utils.trim(sValue);
this.hasError('' !== sValue && !(/^[^@\s]+@[^@\s]+$/.test(sValue)));
}, this);
this.valueHasMutated();
return this;
};
ko.observable.fn.validateSimpleEmail = function ()
{
this.hasError = ko.observable(false);
this.subscribe(function (sValue) {
sValue = Utils.trim(sValue);
this.hasError('' !== sValue && !(/^.+@.+$/.test(sValue)));
}, this);
this.valueHasMutated();
return this;
};
ko.observable.fn.validateFunc = function (fFunc)
{
this.hasFuncError = ko.observable(false);
if (Utils.isFunc(fFunc))
{
this.subscribe(function (sValue) {
this.hasFuncError(!fFunc(sValue));
}, this);
this.valueHasMutated();
}
return this;
};
module.exports = ko;
}(module));
},{"../Common/Globals.js":6,"../Common/Utils.js":9,"../RL.js":32,"./$doc.js":11,"./$window.js":13,"./jquery.js":19,"./underscore.js":24,"./window.js":25}],22:[function(require,module,exports){
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
'use strict';
module.exports = moment;
},{}],23:[function(require,module,exports){
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
'use strict';
module.exports = ssm;
},{}],24:[function(require,module,exports){
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
'use strict';
module.exports = window;
},{}],25:[function(require,module,exports){
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
'use strict';
module.exports = window;
},{}],26:[function(require,module,exports){
/* 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'),
hasher = require('../External/hasher.js'),
crossroads = require('../External/crossroads.js'),
$html = require('../External/$html.js'),
Globals = require('../Common/Globals.js'),
Enums = require('../Common/Enums.js'),
Plugins = require('../Common/Plugins.js'),
Utils = require('../Common/Utils.js'),
KnoinAbstractViewModel = require('../Knoin/KnoinAbstractViewModel.js')
;
/**
* @constructor
*/
function Knoin()
{
this.sDefaultScreenName = '';
this.oScreens = {};
this.oBoot = 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.oCurrentScreen = null;
Knoin.prototype.hideLoading = function ()
{
$('#rl-loading').hide();
};
Knoin.prototype.rl = function ()
{
return this.oBoot;
};
Knoin.prototype.remote = function ()
{
return this.oRemote;
};
/**
* @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
oViewModel = new ViewModelClass(oScreen),
sPosition = oViewModel.viewModelPosition(),
oViewModelPlace = $('#rl-content #rl-' + sPosition.toLowerCase()),
oViewModelDom = null
;
ViewModelClass.__builded = true;
ViewModelClass.__vm = oViewModel;
oViewModel.data = RL.data(); // TODO cjs
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); // TODO cjs
});
oViewModel.modalVisibility.subscribe(function (bValue) {
var self = this;
if (bValue)
{
this.viewModelDom.show();
this.storeAndSetKeyScope();
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();
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)
{
this.oBoot = RL;
this.oRemote = Remote;
var
window = require('../External/window.js'),
$window = require('../External/$window.js'),
$html = require('../External/$html.js'),
Plugins = require('../Common/Plugins.js'),
EmailModel = require('../Models/EmailModel.js')
;
$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'] = EmailModel;
window['rl']['Enums'] = Enums;
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));
},{"../Common/Enums.js":5,"../Common/Globals.js":6,"../Common/Plugins.js":8,"../Common/Utils.js":9,"../External/$html.js":12,"../External/$window.js":13,"../External/crossroads.js":17,"../External/hasher.js":18,"../External/jquery.js":19,"../External/ko.js":21,"../External/underscore.js":24,"../External/window.js":25,"../Knoin/KnoinAbstractViewModel.js":28,"../Models/EmailModel.js":30}],27:[function(require,module,exports){
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module) {
'use strict';
/**
* @constructor
*/
function KnoinAbstractBoot()
{
}
KnoinAbstractBoot.prototype.bootstart = function ()
{
};
module.exports = KnoinAbstractBoot;
}(module));
},{}],28:[function(require,module,exports){
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module) {
'use strict';
var
ko = require('../External/ko.js'),
$window = require('../External/$window.js'),
Utils = require('../Common/Utils.js'),
Enums = require('../Common/Enums.js')
;
/**
* @param {string=} sPosition = ''
* @param {string=} sTemplate = ''
* @constructor
*/
function KnoinAbstractViewModel(sPosition, sTemplate)
{
this.bDisabeCloseOnEsc = false;
this.sPosition = Utils.pString(sPosition);
this.sTemplate = Utils.pString(sTemplate);
this.sDefaultKeyScope = Enums.KeyState.None;
this.sCurrentKeyScope = this.sDefaultKeyScope;
this.viewModelName = '';
this.viewModelVisibility = ko.observable(false);
this.modalVisibility = ko.observable(false).extend({'rateLimit': 0});
this.viewModelDom = null;
}
/**
* @type {string}
*/
KnoinAbstractViewModel.prototype.sPosition = '';
/**
* @type {string}
*/
KnoinAbstractViewModel.prototype.sTemplate = '';
/**
* @type {string}
*/
KnoinAbstractViewModel.prototype.viewModelName = '';
/**
* @type {?}
*/
KnoinAbstractViewModel.prototype.viewModelDom = null;
/**
* @return {string}
*/
KnoinAbstractViewModel.prototype.viewModelTemplate = function ()
{
return this.sTemplate;
};
/**
* @return {string}
*/
KnoinAbstractViewModel.prototype.viewModelPosition = function ()
{
return this.sPosition;
};
KnoinAbstractViewModel.prototype.cancelCommand = KnoinAbstractViewModel.prototype.closeCommand = function ()
{
};
KnoinAbstractViewModel.prototype.storeAndSetKeyScope = function ()
{
this.sCurrentKeyScope = RL.data().keyScope(); // TODO cjs
RL.data().keyScope(this.sDefaultKeyScope); // TODO cjs
};
KnoinAbstractViewModel.prototype.restoreKeyScope = function ()
{
RL.data().keyScope(this.sCurrentKeyScope); // TODO cjs
};
KnoinAbstractViewModel.prototype.registerPopupKeyDown = function ()
{
var self = this;
$window.on('keydown', function (oEvent) {
if (oEvent && self.modalVisibility && self.modalVisibility())
{
if (!this.bDisabeCloseOnEsc && Enums.EventKeyCode.Esc === oEvent.keyCode)
{
Utils.delegateRun(self, 'cancelCommand');
return false;
}
else if (Enums.EventKeyCode.Backspace === oEvent.keyCode && !Utils.inFocus())
{
return false;
}
}
return true;
});
};
module.exports = KnoinAbstractViewModel;
}(module));
},{"../Common/Enums.js":5,"../Common/Utils.js":9,"../External/$window.js":13,"../External/ko.js":21}],29:[function(require,module,exports){
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module) {
'use strict';
var
window = require('../External/window.js'),
Globals = require('../Common/Globals.js'),
Utils = require('../Common/Utils.js'),
LinkBuilder = require('../Common/LinkBuilder.js')
;
/**
* @constructor
*/
function AttachmentModel()
{
this.mimeType = '';
this.fileName = '';
this.estimatedSize = 0;
this.friendlySize = '';
this.isInline = false;
this.isLinked = false;
this.cid = '';
this.cidWithOutTags = '';
this.contentLocation = '';
this.download = '';
this.folder = '';
this.uid = '';
this.mimeIndex = '';
}
/**
* @static
* @param {AjaxJsonAttachment} oJsonAttachment
* @return {?AttachmentModel}
*/
AttachmentModel.newInstanceFromJson = function (oJsonAttachment)
{
var oAttachmentModel = new AttachmentModel();
return oAttachmentModel.initByJson(oJsonAttachment) ? oAttachmentModel : null;
};
AttachmentModel.prototype.mimeType = '';
AttachmentModel.prototype.fileName = '';
AttachmentModel.prototype.estimatedSize = 0;
AttachmentModel.prototype.friendlySize = '';
AttachmentModel.prototype.isInline = false;
AttachmentModel.prototype.isLinked = false;
AttachmentModel.prototype.cid = '';
AttachmentModel.prototype.cidWithOutTags = '';
AttachmentModel.prototype.contentLocation = '';
AttachmentModel.prototype.download = '';
AttachmentModel.prototype.folder = '';
AttachmentModel.prototype.uid = '';
AttachmentModel.prototype.mimeIndex = '';
/**
* @param {AjaxJsonAttachment} oJsonAttachment
*/
AttachmentModel.prototype.initByJson = function (oJsonAttachment)
{
var bResult = false;
if (oJsonAttachment && 'Object/Attachment' === oJsonAttachment['@Object'])
{
this.mimeType = (oJsonAttachment.MimeType || '').toLowerCase();
this.fileName = oJsonAttachment.FileName;
this.estimatedSize = Utils.pInt(oJsonAttachment.EstimatedSize);
this.isInline = !!oJsonAttachment.IsInline;
this.isLinked = !!oJsonAttachment.IsLinked;
this.cid = oJsonAttachment.CID;
this.contentLocation = oJsonAttachment.ContentLocation;
this.download = oJsonAttachment.Download;
this.folder = oJsonAttachment.Folder;
this.uid = oJsonAttachment.Uid;
this.mimeIndex = oJsonAttachment.MimeIndex;
this.friendlySize = Utils.friendlySize(this.estimatedSize);
this.cidWithOutTags = this.cid.replace(/^<+/, '').replace(/>+$/, '');
bResult = true;
}
return bResult;
};
/**
* @return {boolean}
*/
AttachmentModel.prototype.isImage = function ()
{
return -1 < Utils.inArray(this.mimeType.toLowerCase(),
['image/png', 'image/jpg', 'image/jpeg', 'image/gif']
);
};
/**
* @return {boolean}
*/
AttachmentModel.prototype.isText = function ()
{
return 'text/' === this.mimeType.substr(0, 5) &&
-1 === Utils.inArray(this.mimeType, ['text/html']);
};
/**
* @return {boolean}
*/
AttachmentModel.prototype.isPdf = function ()
{
return Globals.bAllowPdfPreview && 'application/pdf' === this.mimeType;
};
/**
* @return {string}
*/
AttachmentModel.prototype.linkDownload = function ()
{
return LinkBuilder.attachmentDownload(this.download); // TODO cjs
};
/**
* @return {string}
*/
AttachmentModel.prototype.linkPreview = function ()
{
return LinkBuilder.attachmentPreview(this.download); // TODO cjs
};
/**
* @return {string}
*/
AttachmentModel.prototype.linkPreviewAsPlain = function ()
{
return LinkBuilder.attachmentPreviewAsPlain(this.download);
};
/**
* @return {string}
*/
AttachmentModel.prototype.generateTransferDownloadUrl = function ()
{
var sLink = this.linkDownload();
if ('http' !== sLink.substr(0, 4))
{
sLink = window.location.protocol + '//' + window.location.host + window.location.pathname + sLink;
}
return this.mimeType + ':' + this.fileName + ':' + sLink;
};
/**
* @param {AttachmentModel} oAttachment
* @param {*} oEvent
* @return {boolean}
*/
AttachmentModel.prototype.eventDragStart = function (oAttachment, oEvent)
{
var oLocalEvent = oEvent.originalEvent || oEvent;
if (oAttachment && oLocalEvent && oLocalEvent.dataTransfer && oLocalEvent.dataTransfer.setData)
{
oLocalEvent.dataTransfer.setData('DownloadURL', this.generateTransferDownloadUrl());
}
return true;
};
AttachmentModel.prototype.iconClass = function ()
{
var
aParts = this.mimeType.toLocaleString().split('/'),
sClass = 'icon-file'
;
if (aParts && aParts[1])
{
if ('image' === aParts[0])
{
sClass = 'icon-file-image';
}
else if ('text' === aParts[0])
{
sClass = 'icon-file-text';
}
else if ('audio' === aParts[0])
{
sClass = 'icon-file-music';
}
else if ('video' === aParts[0])
{
sClass = 'icon-file-movie';
}
else if (-1 < Utils.inArray(aParts[1],
['zip', '7z', 'tar', 'rar', 'gzip', 'bzip', 'bzip2', 'x-zip', 'x-7z', 'x-rar', 'x-tar', 'x-gzip', 'x-bzip', 'x-bzip2', 'x-zip-compressed', 'x-7z-compressed', 'x-rar-compressed']))
{
sClass = 'icon-file-zip';
}
// else if (-1 < Utils.inArray(aParts[1],
// ['pdf', 'x-pdf']))
// {
// sClass = 'icon-file-pdf';
// }
// else if (-1 < Utils.inArray(aParts[1], [
// 'exe', 'x-exe', 'x-winexe', 'bat'
// ]))
// {
// sClass = 'icon-console';
// }
else if (-1 < Utils.inArray(aParts[1], [
'rtf', 'msword', 'vnd.msword', 'vnd.openxmlformats-officedocument.wordprocessingml.document',
'vnd.openxmlformats-officedocument.wordprocessingml.template',
'vnd.ms-word.document.macroEnabled.12',
'vnd.ms-word.template.macroEnabled.12'
]))
{
sClass = 'icon-file-text';
}
else if (-1 < Utils.inArray(aParts[1], [
'excel', 'ms-excel', 'vnd.ms-excel',
'vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'vnd.openxmlformats-officedocument.spreadsheetml.template',
'vnd.ms-excel.sheet.macroEnabled.12',
'vnd.ms-excel.template.macroEnabled.12',
'vnd.ms-excel.addin.macroEnabled.12',
'vnd.ms-excel.sheet.binary.macroEnabled.12'
]))
{
sClass = 'icon-file-excel';
}
else if (-1 < Utils.inArray(aParts[1], [
'powerpoint', 'ms-powerpoint', 'vnd.ms-powerpoint',
'vnd.openxmlformats-officedocument.presentationml.presentation',
'vnd.openxmlformats-officedocument.presentationml.template',
'vnd.openxmlformats-officedocument.presentationml.slideshow',
'vnd.ms-powerpoint.addin.macroEnabled.12',
'vnd.ms-powerpoint.presentation.macroEnabled.12',
'vnd.ms-powerpoint.template.macroEnabled.12',
'vnd.ms-powerpoint.slideshow.macroEnabled.12'
]))
{
sClass = 'icon-file-chart-graph';
}
}
return sClass;
};
module.exports = AttachmentModel;
}(module));
},{"../Common/Globals.js":6,"../Common/LinkBuilder.js":7,"../Common/Utils.js":9,"../External/window.js":25}],30:[function(require,module,exports){
/* 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));
},{"../Common/Enums.js":5,"../Common/Utils.js":9}],31:[function(require,module,exports){
/* 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'),
moment = require('../External/moment.js'),
$window = require('../External/$window.js'),
$div = require('../External/$div.js'),
Enums = require('../Common/Enums.js'),
Utils = require('../Common/Utils.js'),
LinkBuilder = require('../Common/LinkBuilder.js'),
EmailModel = require('./EmailModel.js'),
AttachmentModel = require('./AttachmentModel.js')
;
/**
* @constructor
*/
function MessageModel()
{
this.folderFullNameRaw = '';
this.uid = '';
this.hash = '';
this.requestHash = '';
this.subject = ko.observable('');
this.subjectPrefix = ko.observable('');
this.subjectSuffix = ko.observable('');
this.size = ko.observable(0);
this.dateTimeStampInUTC = ko.observable(0);
this.priority = ko.observable(Enums.MessagePriority.Normal);
this.proxy = false;
this.fromEmailString = ko.observable('');
this.fromClearEmailString = ko.observable('');
this.toEmailsString = ko.observable('');
this.toClearEmailsString = ko.observable('');
this.senderEmailsString = ko.observable('');
this.senderClearEmailsString = ko.observable('');
this.emails = [];
this.from = [];
this.to = [];
this.cc = [];
this.bcc = [];
this.replyTo = [];
this.deliveredTo = [];
this.newForAnimation = ko.observable(false);
this.deleted = ko.observable(false);
this.unseen = ko.observable(false);
this.flagged = ko.observable(false);
this.answered = ko.observable(false);
this.forwarded = ko.observable(false);
this.isReadReceipt = ko.observable(false);
this.focused = ko.observable(false);
this.selected = ko.observable(false);
this.checked = ko.observable(false);
this.hasAttachments = ko.observable(false);
this.attachmentsMainType = ko.observable('');
this.moment = ko.observable(moment(moment.unix(0)));
this.attachmentIconClass = ko.computed(function () {
var sClass = '';
if (this.hasAttachments())
{
sClass = 'icon-attachment';
switch (this.attachmentsMainType())
{
case 'image':
sClass = 'icon-image';
break;
case 'archive':
sClass = 'icon-file-zip';
break;
case 'doc':
sClass = 'icon-file-text';
break;
// case 'pdf':
// sClass = 'icon-file-pdf';
// break;
}
}
return sClass;
}, this);
this.fullFormatDateValue = ko.computed(function () {
return MessageModel.calculateFullFromatDateValue(this.dateTimeStampInUTC());
}, this);
this.momentDate = Utils.createMomentDate(this);
this.momentShortDate = Utils.createMomentShortDate(this);
this.dateTimeStampInUTC.subscribe(function (iValue) {
var iNow = moment().unix();
this.moment(moment.unix(iNow < iValue ? iNow : iValue));
}, this);
this.body = null;
this.plainRaw = '';
this.isHtml = ko.observable(false);
this.hasImages = ko.observable(false);
this.attachments = ko.observableArray([]);
this.isPgpSigned = ko.observable(false);
this.isPgpEncrypted = ko.observable(false);
this.pgpSignedVerifyStatus = ko.observable(Enums.SignedVerifyStatus.None);
this.pgpSignedVerifyUser = ko.observable('');
this.priority = ko.observable(Enums.MessagePriority.Normal);
this.readReceipt = ko.observable('');
this.aDraftInfo = [];
this.sMessageId = '';
this.sInReplyTo = '';
this.sReferences = '';
this.parentUid = ko.observable(0);
this.threads = ko.observableArray([]);
this.threadsLen = ko.observable(0);
this.hasUnseenSubMessage = ko.observable(false);
this.hasFlaggedSubMessage = ko.observable(false);
this.lastInCollapsedThread = ko.observable(false);
this.lastInCollapsedThreadLoading = ko.observable(false);
this.threadsLenResult = ko.computed(function () {
var iCount = this.threadsLen();
return 0 === this.parentUid() && 0 < iCount ? iCount + 1 : '';
}, this);
}
/**
* @static
* @param {AjaxJsonMessage} oJsonMessage
* @return {?MessageModel}
*/
MessageModel.newInstanceFromJson = function (oJsonMessage)
{
var oMessageModel = new MessageModel();
return oMessageModel.initByJson(oJsonMessage) ? oMessageModel : null;
};
/**
* @static
* @param {number} iTimeStampInUTC
* @return {string}
*/
MessageModel.calculateFullFromatDateValue = function (iTimeStampInUTC)
{
return 0 < iTimeStampInUTC ? moment.unix(iTimeStampInUTC).format('LLL') : '';
};
/**
* @static
* @param {Array} aEmail
* @param {boolean=} bFriendlyView
* @param {boolean=} bWrapWithLink = false
* @return {string}
*/
MessageModel.emailsToLine = function (aEmail, bFriendlyView, bWrapWithLink)
{
var
aResult = [],
iIndex = 0,
iLen = 0
;
if (Utils.isNonEmptyArray(aEmail))
{
for (iIndex = 0, iLen = aEmail.length; iIndex < iLen; iIndex++)
{
aResult.push(aEmail[iIndex].toLine(bFriendlyView, bWrapWithLink));
}
}
return aResult.join(', ');
};
/**
* @static
* @param {Array} aEmail
* @return {string}
*/
MessageModel.emailsToLineClear = function (aEmail)
{
var
aResult = [],
iIndex = 0,
iLen = 0
;
if (Utils.isNonEmptyArray(aEmail))
{
for (iIndex = 0, iLen = aEmail.length; iIndex < iLen; iIndex++)
{
if (aEmail[iIndex] && aEmail[iIndex].email && '' !== aEmail[iIndex].name)
{
aResult.push(aEmail[iIndex].email);
}
}
}
return aResult.join(', ');
};
/**
* @static
* @param {?Array} aJsonEmails
* @return {Array.
}
*/
MessageModel.initEmailsFromJson = function (aJsonEmails)
{
var
iIndex = 0,
iLen = 0,
oEmailModel = null,
aResult = []
;
if (Utils.isNonEmptyArray(aJsonEmails))
{
for (iIndex = 0, iLen = aJsonEmails.length; iIndex < iLen; iIndex++)
{
oEmailModel = EmailModel.newInstanceFromJson(aJsonEmails[iIndex]);
if (oEmailModel)
{
aResult.push(oEmailModel);
}
}
}
return aResult;
};
/**
* @static
* @param {Array.} aMessageEmails
* @param {Object} oLocalUnic
* @param {Array} aLocalEmails
*/
MessageModel.replyHelper = function (aMessageEmails, oLocalUnic, aLocalEmails)
{
if (aMessageEmails && 0 < aMessageEmails.length)
{
var
iIndex = 0,
iLen = aMessageEmails.length
;
for (; iIndex < iLen; iIndex++)
{
if (Utils.isUnd(oLocalUnic[aMessageEmails[iIndex].email]))
{
oLocalUnic[aMessageEmails[iIndex].email] = true;
aLocalEmails.push(aMessageEmails[iIndex]);
}
}
}
};
MessageModel.prototype.clear = function ()
{
this.folderFullNameRaw = '';
this.uid = '';
this.hash = '';
this.requestHash = '';
this.subject('');
this.subjectPrefix('');
this.subjectSuffix('');
this.size(0);
this.dateTimeStampInUTC(0);
this.priority(Enums.MessagePriority.Normal);
this.proxy = false;
this.fromEmailString('');
this.fromClearEmailString('');
this.toEmailsString('');
this.toClearEmailsString('');
this.senderEmailsString('');
this.senderClearEmailsString('');
this.emails = [];
this.from = [];
this.to = [];
this.cc = [];
this.bcc = [];
this.replyTo = [];
this.deliveredTo = [];
this.newForAnimation(false);
this.deleted(false);
this.unseen(false);
this.flagged(false);
this.answered(false);
this.forwarded(false);
this.isReadReceipt(false);
this.selected(false);
this.checked(false);
this.hasAttachments(false);
this.attachmentsMainType('');
this.body = null;
this.isHtml(false);
this.hasImages(false);
this.attachments([]);
this.isPgpSigned(false);
this.isPgpEncrypted(false);
this.pgpSignedVerifyStatus(Enums.SignedVerifyStatus.None);
this.pgpSignedVerifyUser('');
this.priority(Enums.MessagePriority.Normal);
this.readReceipt('');
this.aDraftInfo = [];
this.sMessageId = '';
this.sInReplyTo = '';
this.sReferences = '';
this.parentUid(0);
this.threads([]);
this.threadsLen(0);
this.hasUnseenSubMessage(false);
this.hasFlaggedSubMessage(false);
this.lastInCollapsedThread(false);
this.lastInCollapsedThreadLoading(false);
};
MessageModel.prototype.computeSenderEmail = function ()
{
var
sSent = RL.data().sentFolder(),
sDraft = RL.data().draftFolder()
;
this.senderEmailsString(this.folderFullNameRaw === sSent || this.folderFullNameRaw === sDraft ?
this.toEmailsString() : this.fromEmailString());
this.senderClearEmailsString(this.folderFullNameRaw === sSent || this.folderFullNameRaw === sDraft ?
this.toClearEmailsString() : this.fromClearEmailString());
};
/**
* @param {AjaxJsonMessage} oJsonMessage
* @return {boolean}
*/
MessageModel.prototype.initByJson = function (oJsonMessage)
{
var bResult = false;
if (oJsonMessage && 'Object/Message' === oJsonMessage['@Object'])
{
this.folderFullNameRaw = oJsonMessage.Folder;
this.uid = oJsonMessage.Uid;
this.hash = oJsonMessage.Hash;
this.requestHash = oJsonMessage.RequestHash;
this.proxy = !!oJsonMessage.ExternalProxy;
this.size(Utils.pInt(oJsonMessage.Size));
this.from = MessageModel.initEmailsFromJson(oJsonMessage.From);
this.to = MessageModel.initEmailsFromJson(oJsonMessage.To);
this.cc = MessageModel.initEmailsFromJson(oJsonMessage.Cc);
this.bcc = MessageModel.initEmailsFromJson(oJsonMessage.Bcc);
this.replyTo = MessageModel.initEmailsFromJson(oJsonMessage.ReplyTo);
this.deliveredTo = MessageModel.initEmailsFromJson(oJsonMessage.DeliveredTo);
this.subject(oJsonMessage.Subject);
if (Utils.isArray(oJsonMessage.SubjectParts))
{
this.subjectPrefix(oJsonMessage.SubjectParts[0]);
this.subjectSuffix(oJsonMessage.SubjectParts[1]);
}
else
{
this.subjectPrefix('');
this.subjectSuffix(this.subject());
}
this.dateTimeStampInUTC(Utils.pInt(oJsonMessage.DateTimeStampInUTC));
this.hasAttachments(!!oJsonMessage.HasAttachments);
this.attachmentsMainType(oJsonMessage.AttachmentsMainType);
this.fromEmailString(MessageModel.emailsToLine(this.from, true));
this.fromClearEmailString(MessageModel.emailsToLineClear(this.from));
this.toEmailsString(MessageModel.emailsToLine(this.to, true));
this.toClearEmailsString(MessageModel.emailsToLineClear(this.to));
this.parentUid(Utils.pInt(oJsonMessage.ParentThread));
this.threads(Utils.isArray(oJsonMessage.Threads) ? oJsonMessage.Threads : []);
this.threadsLen(Utils.pInt(oJsonMessage.ThreadsLen));
this.initFlagsByJson(oJsonMessage);
this.computeSenderEmail();
bResult = true;
}
return bResult;
};
/**
* @param {AjaxJsonMessage} oJsonMessage
* @return {boolean}
*/
MessageModel.prototype.initUpdateByMessageJson = function (oJsonMessage)
{
var
bResult = false,
iPriority = Enums.MessagePriority.Normal
;
if (oJsonMessage && 'Object/Message' === oJsonMessage['@Object'])
{
iPriority = Utils.pInt(oJsonMessage.Priority);
this.priority(-1 < Utils.inArray(iPriority, [Enums.MessagePriority.High, Enums.MessagePriority.Low]) ?
iPriority : Enums.MessagePriority.Normal);
this.aDraftInfo = oJsonMessage.DraftInfo;
this.sMessageId = oJsonMessage.MessageId;
this.sInReplyTo = oJsonMessage.InReplyTo;
this.sReferences = oJsonMessage.References;
this.proxy = !!oJsonMessage.ExternalProxy;
if (RL.data().capaOpenPGP()) // TODO cjs
{
this.isPgpSigned(!!oJsonMessage.PgpSigned);
this.isPgpEncrypted(!!oJsonMessage.PgpEncrypted);
}
this.hasAttachments(!!oJsonMessage.HasAttachments);
this.attachmentsMainType(oJsonMessage.AttachmentsMainType);
this.foundedCIDs = Utils.isArray(oJsonMessage.FoundedCIDs) ? oJsonMessage.FoundedCIDs : [];
this.attachments(this.initAttachmentsFromJson(oJsonMessage.Attachments));
this.readReceipt(oJsonMessage.ReadReceipt || '');
this.computeSenderEmail();
bResult = true;
}
return bResult;
};
/**
* @param {(AjaxJsonAttachment|null)} oJsonAttachments
* @return {Array}
*/
MessageModel.prototype.initAttachmentsFromJson = function (oJsonAttachments)
{
var
iIndex = 0,
iLen = 0,
oAttachmentModel = null,
aResult = []
;
if (oJsonAttachments && 'Collection/AttachmentCollection' === oJsonAttachments['@Object'] &&
Utils.isNonEmptyArray(oJsonAttachments['@Collection']))
{
for (iIndex = 0, iLen = oJsonAttachments['@Collection'].length; iIndex < iLen; iIndex++)
{
oAttachmentModel = AttachmentModel.newInstanceFromJson(oJsonAttachments['@Collection'][iIndex]);
if (oAttachmentModel)
{
if ('' !== oAttachmentModel.cidWithOutTags && 0 < this.foundedCIDs.length &&
0 <= Utils.inArray(oAttachmentModel.cidWithOutTags, this.foundedCIDs))
{
oAttachmentModel.isLinked = true;
}
aResult.push(oAttachmentModel);
}
}
}
return aResult;
};
/**
* @param {AjaxJsonMessage} oJsonMessage
* @return {boolean}
*/
MessageModel.prototype.initFlagsByJson = function (oJsonMessage)
{
var bResult = false;
if (oJsonMessage && 'Object/Message' === oJsonMessage['@Object'])
{
this.unseen(!oJsonMessage.IsSeen);
this.flagged(!!oJsonMessage.IsFlagged);
this.answered(!!oJsonMessage.IsAnswered);
this.forwarded(!!oJsonMessage.IsForwarded);
this.isReadReceipt(!!oJsonMessage.IsReadReceipt);
bResult = true;
}
return bResult;
};
/**
* @param {boolean} bFriendlyView
* @param {boolean=} bWrapWithLink = false
* @return {string}
*/
MessageModel.prototype.fromToLine = function (bFriendlyView, bWrapWithLink)
{
return MessageModel.emailsToLine(this.from, bFriendlyView, bWrapWithLink);
};
/**
* @param {boolean} bFriendlyView
* @param {boolean=} bWrapWithLink = false
* @return {string}
*/
MessageModel.prototype.toToLine = function (bFriendlyView, bWrapWithLink)
{
return MessageModel.emailsToLine(this.to, bFriendlyView, bWrapWithLink);
};
/**
* @param {boolean} bFriendlyView
* @param {boolean=} bWrapWithLink = false
* @return {string}
*/
MessageModel.prototype.ccToLine = function (bFriendlyView, bWrapWithLink)
{
return MessageModel.emailsToLine(this.cc, bFriendlyView, bWrapWithLink);
};
/**
* @param {boolean} bFriendlyView
* @param {boolean=} bWrapWithLink = false
* @return {string}
*/
MessageModel.prototype.bccToLine = function (bFriendlyView, bWrapWithLink)
{
return MessageModel.emailsToLine(this.bcc, bFriendlyView, bWrapWithLink);
};
/**
* @return string
*/
MessageModel.prototype.lineAsCcc = function ()
{
var aResult = [];
if (this.deleted())
{
aResult.push('deleted');
}
if (this.selected())
{
aResult.push('selected');
}
if (this.checked())
{
aResult.push('checked');
}
if (this.flagged())
{
aResult.push('flagged');
}
if (this.unseen())
{
aResult.push('unseen');
}
if (this.answered())
{
aResult.push('answered');
}
if (this.forwarded())
{
aResult.push('forwarded');
}
if (this.focused())
{
aResult.push('focused');
}
if (this.hasAttachments())
{
aResult.push('withAttachments');
switch (this.attachmentsMainType())
{
case 'image':
aResult.push('imageOnlyAttachments');
break;
case 'archive':
aResult.push('archiveOnlyAttachments');
break;
}
}
if (this.newForAnimation())
{
aResult.push('new');
}
if ('' === this.subject())
{
aResult.push('emptySubject');
}
if (0 < this.parentUid())
{
aResult.push('hasParentMessage');
}
if (0 < this.threadsLen() && 0 === this.parentUid())
{
aResult.push('hasChildrenMessage');
}
if (this.hasUnseenSubMessage())
{
aResult.push('hasUnseenSubMessage');
}
if (this.hasFlaggedSubMessage())
{
aResult.push('hasFlaggedSubMessage');
}
return aResult.join(' ');
};
/**
* @return {boolean}
*/
MessageModel.prototype.hasVisibleAttachments = function ()
{
return !!_.find(this.attachments(), function (oAttachment) {
return !oAttachment.isLinked;
});
};
/**
* @param {string} sCid
* @return {*}
*/
MessageModel.prototype.findAttachmentByCid = function (sCid)
{
var
oResult = null,
aAttachments = this.attachments()
;
if (Utils.isNonEmptyArray(aAttachments))
{
sCid = sCid.replace(/^<+/, '').replace(/>+$/, '');
oResult = _.find(aAttachments, function (oAttachment) {
return sCid === oAttachment.cidWithOutTags;
});
}
return oResult || null;
};
/**
* @param {string} sContentLocation
* @return {*}
*/
MessageModel.prototype.findAttachmentByContentLocation = function (sContentLocation)
{
var
oResult = null,
aAttachments = this.attachments()
;
if (Utils.isNonEmptyArray(aAttachments))
{
oResult = _.find(aAttachments, function (oAttachment) {
return sContentLocation === oAttachment.contentLocation;
});
}
return oResult || null;
};
/**
* @return {string}
*/
MessageModel.prototype.messageId = function ()
{
return this.sMessageId;
};
/**
* @return {string}
*/
MessageModel.prototype.inReplyTo = function ()
{
return this.sInReplyTo;
};
/**
* @return {string}
*/
MessageModel.prototype.references = function ()
{
return this.sReferences;
};
/**
* @return {string}
*/
MessageModel.prototype.fromAsSingleEmail = function ()
{
return Utils.isArray(this.from) && this.from[0] ? this.from[0].email : '';
};
/**
* @return {string}
*/
MessageModel.prototype.viewLink = function ()
{
return LinkBuilder.messageViewLink(this.requestHash);// TODO cjs
};
/**
* @return {string}
*/
MessageModel.prototype.downloadLink = function ()
{
return LinkBuilder.messageDownloadLink(this.requestHash);// TODO cjs
};
/**
* @param {Object} oExcludeEmails
* @return {Array}
*/
MessageModel.prototype.replyEmails = function (oExcludeEmails)
{
var
aResult = [],
oUnic = Utils.isUnd(oExcludeEmails) ? {} : oExcludeEmails
;
MessageModel.replyHelper(this.replyTo, oUnic, aResult);
if (0 === aResult.length)
{
MessageModel.replyHelper(this.from, oUnic, aResult);
}
return aResult;
};
/**
* @param {Object} oExcludeEmails
* @return {Array.}
*/
MessageModel.prototype.replyAllEmails = function (oExcludeEmails)
{
var
aToResult = [],
aCcResult = [],
oUnic = Utils.isUnd(oExcludeEmails) ? {} : oExcludeEmails
;
MessageModel.replyHelper(this.replyTo, oUnic, aToResult);
if (0 === aToResult.length)
{
MessageModel.replyHelper(this.from, oUnic, aToResult);
}
MessageModel.replyHelper(this.to, oUnic, aToResult);
MessageModel.replyHelper(this.cc, oUnic, aCcResult);
return [aToResult, aCcResult];
};
/**
* @return {string}
*/
MessageModel.prototype.textBodyToString = function ()
{
return this.body ? this.body.html() : '';
};
/**
* @return {string}
*/
MessageModel.prototype.attachmentsToStringLine = function ()
{
var aAttachLines = _.map(this.attachments(), function (oItem) {
return oItem.fileName + ' (' + oItem.friendlySize + ')';
});
return aAttachLines && 0 < aAttachLines.length ? aAttachLines.join(', ') : '';
};
/**
* @return {Object}
*/
MessageModel.prototype.getDataForWindowPopup = function ()
{
return {
'popupFrom': this.fromToLine(false),
'popupTo': this.toToLine(false),
'popupCc': this.ccToLine(false),
'popupBcc': this.bccToLine(false),
'popupSubject': this.subject(),
'popupDate': this.fullFormatDateValue(),
'popupAttachments': this.attachmentsToStringLine(),
'popupBody': this.textBodyToString()
};
};
/**
* @param {boolean=} bPrint = false
*/
MessageModel.prototype.viewPopupMessage = function (bPrint)
{
Utils.windowPopupKnockout(this.getDataForWindowPopup(), 'PopupsWindowSimpleMessage', this.subject(), function (oPopupWin) {
if (oPopupWin && oPopupWin.document && oPopupWin.document.body)
{
$('img.lazy', oPopupWin.document.body).each(function (iIndex, oImg) {
var
$oImg = $(oImg),
sOrig = $oImg.data('original'),
sSrc = $oImg.attr('src')
;
if (0 <= iIndex && sOrig && !sSrc)
{
$oImg.attr('src', sOrig);
}
});
if (bPrint)
{
window.setTimeout(function () {
oPopupWin.print();
}, 100);
}
}
});
};
MessageModel.prototype.printMessage = function ()
{
this.viewPopupMessage(true);
};
/**
* @returns {string}
*/
MessageModel.prototype.generateUid = function ()
{
return this.folderFullNameRaw + '/' + this.uid;
};
/**
* @param {MessageModel} oMessage
* @return {MessageModel}
*/
MessageModel.prototype.populateByMessageListItem = function (oMessage)
{
this.folderFullNameRaw = oMessage.folderFullNameRaw;
this.uid = oMessage.uid;
this.hash = oMessage.hash;
this.requestHash = oMessage.requestHash;
this.subject(oMessage.subject());
this.subjectPrefix(this.subjectPrefix());
this.subjectSuffix(this.subjectSuffix());
this.size(oMessage.size());
this.dateTimeStampInUTC(oMessage.dateTimeStampInUTC());
this.priority(oMessage.priority());
this.proxy = oMessage.proxy;
this.fromEmailString(oMessage.fromEmailString());
this.fromClearEmailString(oMessage.fromClearEmailString());
this.toEmailsString(oMessage.toEmailsString());
this.toClearEmailsString(oMessage.toClearEmailsString());
this.emails = oMessage.emails;
this.from = oMessage.from;
this.to = oMessage.to;
this.cc = oMessage.cc;
this.bcc = oMessage.bcc;
this.replyTo = oMessage.replyTo;
this.deliveredTo = oMessage.deliveredTo;
this.unseen(oMessage.unseen());
this.flagged(oMessage.flagged());
this.answered(oMessage.answered());
this.forwarded(oMessage.forwarded());
this.isReadReceipt(oMessage.isReadReceipt());
this.selected(oMessage.selected());
this.checked(oMessage.checked());
this.hasAttachments(oMessage.hasAttachments());
this.attachmentsMainType(oMessage.attachmentsMainType());
this.moment(oMessage.moment());
this.body = null;
this.priority(Enums.MessagePriority.Normal);
this.aDraftInfo = [];
this.sMessageId = '';
this.sInReplyTo = '';
this.sReferences = '';
this.parentUid(oMessage.parentUid());
this.threads(oMessage.threads());
this.threadsLen(oMessage.threadsLen());
this.computeSenderEmail();
return this;
};
MessageModel.prototype.showExternalImages = function (bLazy)
{
if (this.body && this.body.data('rl-has-images'))
{
var sAttr = '';
bLazy = Utils.isUnd(bLazy) ? false : bLazy;
this.hasImages(false);
this.body.data('rl-has-images', false);
sAttr = this.proxy ? 'data-x-additional-src' : 'data-x-src';
$('[' + sAttr + ']', this.body).each(function () {
if (bLazy && $(this).is('img'))
{
$(this)
.addClass('lazy')
.attr('data-original', $(this).attr(sAttr))
.removeAttr(sAttr)
;
}
else
{
$(this).attr('src', $(this).attr(sAttr)).removeAttr(sAttr);
}
});
sAttr = this.proxy ? 'data-x-additional-style-url' : 'data-x-style-url';
$('[' + sAttr + ']', this.body).each(function () {
var sStyle = Utils.trim($(this).attr('style'));
sStyle = '' === sStyle ? '' : (';' === sStyle.substr(-1) ? sStyle + ' ' : sStyle + '; ');
$(this).attr('style', sStyle + $(this).attr(sAttr)).removeAttr(sAttr);
});
if (bLazy)
{
$('img.lazy', this.body).addClass('lazy-inited').lazyload({
'threshold' : 400,
'effect' : 'fadeIn',
'skip_invisible' : false,
'container': $('.RL-MailMessageView .messageView .messageItem .content')[0]
});
$window.resize();
}
Utils.windowResize(500);
}
};
MessageModel.prototype.showInternalImages = function (bLazy)
{
if (this.body && !this.body.data('rl-init-internal-images'))
{
this.body.data('rl-init-internal-images', true);
bLazy = Utils.isUnd(bLazy) ? false : bLazy;
var self = this;
$('[data-x-src-cid]', this.body).each(function () {
var oAttachment = self.findAttachmentByCid($(this).attr('data-x-src-cid'));
if (oAttachment && oAttachment.download)
{
if (bLazy && $(this).is('img'))
{
$(this)
.addClass('lazy')
.attr('data-original', oAttachment.linkPreview());
}
else
{
$(this).attr('src', oAttachment.linkPreview());
}
}
});
$('[data-x-src-location]', this.body).each(function () {
var oAttachment = self.findAttachmentByContentLocation($(this).attr('data-x-src-location'));
if (!oAttachment)
{
oAttachment = self.findAttachmentByCid($(this).attr('data-x-src-location'));
}
if (oAttachment && oAttachment.download)
{
if (bLazy && $(this).is('img'))
{
$(this)
.addClass('lazy')
.attr('data-original', oAttachment.linkPreview());
}
else
{
$(this).attr('src', oAttachment.linkPreview());
}
}
});
$('[data-x-style-cid]', this.body).each(function () {
var
sStyle = '',
sName = '',
oAttachment = self.findAttachmentByCid($(this).attr('data-x-style-cid'))
;
if (oAttachment && oAttachment.linkPreview)
{
sName = $(this).attr('data-x-style-cid-name');
if ('' !== sName)
{
sStyle = Utils.trim($(this).attr('style'));
sStyle = '' === sStyle ? '' : (';' === sStyle.substr(-1) ? sStyle + ' ' : sStyle + '; ');
$(this).attr('style', sStyle + sName + ': url(\'' + oAttachment.linkPreview() + '\')');
}
}
});
if (bLazy)
{
(function ($oImg, oContainer) {
_.delay(function () {
$oImg.addClass('lazy-inited').lazyload({
'threshold' : 400,
'effect' : 'fadeIn',
'skip_invisible' : false,
'container': oContainer
});
}, 300);
}($('img.lazy', self.body), $('.RL-MailMessageView .messageView .messageItem .content')[0]));
}
Utils.windowResize(500);
}
};
MessageModel.prototype.storeDataToDom = function ()
{
if (this.body)
{
this.body.data('rl-is-html', !!this.isHtml());
this.body.data('rl-has-images', !!this.hasImages());
this.body.data('rl-plain-raw', this.plainRaw);
if (RL.data().capaOpenPGP()) // TODO cjs
{
this.body.data('rl-plain-pgp-signed', !!this.isPgpSigned());
this.body.data('rl-plain-pgp-encrypted', !!this.isPgpEncrypted());
this.body.data('rl-pgp-verify-status', this.pgpSignedVerifyStatus());
this.body.data('rl-pgp-verify-user', this.pgpSignedVerifyUser());
}
}
};
MessageModel.prototype.storePgpVerifyDataToDom = function ()
{
if (this.body && RL.data().capaOpenPGP()) // TODO cjs
{
this.body.data('rl-pgp-verify-status', this.pgpSignedVerifyStatus());
this.body.data('rl-pgp-verify-user', this.pgpSignedVerifyUser());
}
};
MessageModel.prototype.fetchDataToDom = function ()
{
if (this.body)
{
this.isHtml(!!this.body.data('rl-is-html'));
this.hasImages(!!this.body.data('rl-has-images'));
this.plainRaw = Utils.pString(this.body.data('rl-plain-raw'));
if (RL.data().capaOpenPGP()) // TODO cjs
{
this.isPgpSigned(!!this.body.data('rl-plain-pgp-signed'));
this.isPgpEncrypted(!!this.body.data('rl-plain-pgp-encrypted'));
this.pgpSignedVerifyStatus(this.body.data('rl-pgp-verify-status'));
this.pgpSignedVerifyUser(this.body.data('rl-pgp-verify-user'));
}
else
{
this.isPgpSigned(false);
this.isPgpEncrypted(false);
this.pgpSignedVerifyStatus(Enums.SignedVerifyStatus.None);
this.pgpSignedVerifyUser('');
}
}
};
MessageModel.prototype.verifyPgpSignedClearMessage = function ()
{
if (this.isPgpSigned())
{
var
aRes = [],
mPgpMessage = null,
sFrom = this.from && this.from[0] && this.from[0].email ? this.from[0].email : '',
aPublicKeys = RL.data().findPublicKeysByEmail(sFrom), // TODO cjs
oValidKey = null,
oValidSysKey = null,
sPlain = ''
;
this.pgpSignedVerifyStatus(Enums.SignedVerifyStatus.Error);
this.pgpSignedVerifyUser('');
try
{
mPgpMessage = window.openpgp.cleartext.readArmored(this.plainRaw);
if (mPgpMessage && mPgpMessage.getText)
{
this.pgpSignedVerifyStatus(
aPublicKeys.length ? Enums.SignedVerifyStatus.Unverified : Enums.SignedVerifyStatus.UnknownPublicKeys);
aRes = mPgpMessage.verify(aPublicKeys);
if (aRes && 0 < aRes.length)
{
oValidKey = _.find(aRes, function (oItem) {
return oItem && oItem.keyid && oItem.valid;
});
if (oValidKey)
{
oValidSysKey = RL.data().findPublicKeyByHex(oValidKey.keyid.toHex()); // TODO cjs
if (oValidSysKey)
{
sPlain = mPgpMessage.getText();
this.pgpSignedVerifyStatus(Enums.SignedVerifyStatus.Success);
this.pgpSignedVerifyUser(oValidSysKey.user);
sPlain =
$div.empty().append(
$('').text(sPlain)
).html()
;
$div.empty();
this.replacePlaneTextBody(sPlain);
}
}
}
}
}
catch (oExc) {}
this.storePgpVerifyDataToDom();
}
};
MessageModel.prototype.decryptPgpEncryptedMessage = function (sPassword)
{
if (this.isPgpEncrypted())
{
var
aRes = [],
mPgpMessage = null,
mPgpMessageDecrypted = null,
sFrom = this.from && this.from[0] && this.from[0].email ? this.from[0].email : '',
aPublicKey = RL.data().findPublicKeysByEmail(sFrom), // TODO cjs
oPrivateKey = RL.data().findSelfPrivateKey(sPassword), // TODO cjs
oValidKey = null,
oValidSysKey = null,
sPlain = ''
;
this.pgpSignedVerifyStatus(Enums.SignedVerifyStatus.Error);
this.pgpSignedVerifyUser('');
if (!oPrivateKey)
{
this.pgpSignedVerifyStatus(Enums.SignedVerifyStatus.UnknownPrivateKey);
}
try
{
mPgpMessage = window.openpgp.message.readArmored(this.plainRaw);
if (mPgpMessage && oPrivateKey && mPgpMessage.decrypt)
{
this.pgpSignedVerifyStatus(Enums.SignedVerifyStatus.Unverified);
mPgpMessageDecrypted = mPgpMessage.decrypt(oPrivateKey);
if (mPgpMessageDecrypted)
{
aRes = mPgpMessageDecrypted.verify(aPublicKey);
if (aRes && 0 < aRes.length)
{
oValidKey = _.find(aRes, function (oItem) {
return oItem && oItem.keyid && oItem.valid;
});
if (oValidKey)
{
oValidSysKey = RL.data().findPublicKeyByHex(oValidKey.keyid.toHex()); // TODO cjs
if (oValidSysKey)
{
this.pgpSignedVerifyStatus(Enums.SignedVerifyStatus.Success);
this.pgpSignedVerifyUser(oValidSysKey.user);
}
}
}
sPlain = mPgpMessageDecrypted.getText();
sPlain =
$div.empty().append(
$('').text(sPlain)
).html()
;
$div.empty();
this.replacePlaneTextBody(sPlain);
}
}
}
catch (oExc) {}
this.storePgpVerifyDataToDom();
}
};
MessageModel.prototype.replacePlaneTextBody = function (sPlain)
{
if (this.body)
{
this.body.html(sPlain).addClass('b-text-part plain');
}
};
/**
* @return {string}
*/
MessageModel.prototype.flagHash = function ()
{
return [this.deleted(), this.unseen(), this.flagged(), this.answered(), this.forwarded(),
this.isReadReceipt()].join('');
};
module.exports = MessageModel;
}(module));
},{"../Common/Enums.js":5,"../Common/LinkBuilder.js":7,"../Common/Utils.js":9,"../External/$div.js":10,"../External/$window.js":13,"../External/jquery.js":19,"../External/ko.js":21,"../External/moment.js":22,"../External/underscore.js":24,"../External/window.js":25,"./AttachmentModel.js":29,"./EmailModel.js":30}],32:[function(require,module,exports){
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
'use strict';
module.exports = function () {
return require('./Knoin/Knoin.js').rl();
};
},{"./Knoin/Knoin.js":26}],33:[function(require,module,exports){
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
'use strict';
module.exports = function () {
return require('./Knoin/Knoin.js').remote();
};
},{"./Knoin/Knoin.js":26}],34:[function(require,module,exports){
/* 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'),
Consts = require('../Common/Consts.js'),
Enums = require('../Common/Enums.js'),
Globals = require('../Common/Globals.js'),
Utils = require('../Common/Utils.js'),
Plugins = require('../Common/Plugins.js'),
LinkBuilder = require('../Common/LinkBuilder.js'),
RL = require('../RL.js')
;
/**
* @constructor
*/
function AbstractAjaxRemoteStorage()
{
this.oRequests = {};
}
AbstractAjaxRemoteStorage.prototype.oRequests = {};
/**
* @param {?Function} fCallback
* @param {string} sRequestAction
* @param {string} sType
* @param {?AjaxJsonDefaultResponse} oData
* @param {boolean} bCached
* @param {*=} oRequestParameters
*/
AbstractAjaxRemoteStorage.prototype.defaultResponse = function (fCallback, sRequestAction, sType, oData, bCached, oRequestParameters)
{
var
fCall = function () {
if (Enums.StorageResultType.Success !== sType && Globals.bUnload)
{
sType = Enums.StorageResultType.Unload;
}
if (Enums.StorageResultType.Success === sType && oData && !oData.Result)
{
if (oData && -1 < Utils.inArray(oData.ErrorCode, [
Enums.Notification.AuthError, Enums.Notification.AccessError,
Enums.Notification.ConnectionError, Enums.Notification.DomainNotAllowed, Enums.Notification.AccountNotAllowed,
Enums.Notification.MailServerError, Enums.Notification.UnknownNotification, Enums.Notification.UnknownError
]))
{
Globals.iAjaxErrorCount++;
}
if (oData && Enums.Notification.InvalidToken === oData.ErrorCode)
{
Globals.iTokenErrorCount++;
}
if (Consts.Values.TokenErrorLimit < Globals.iTokenErrorCount)
{
RL().loginAndLogoutReload(true);
}
if (oData.Logout || Consts.Values.AjaxErrorLimit < Globals.iAjaxErrorCount)
{
if (window.__rlah_clear)
{
window.__rlah_clear();
}
RL().loginAndLogoutReload(true);
}
}
else if (Enums.StorageResultType.Success === sType && oData && oData.Result)
{
Globals.iAjaxErrorCount = 0;
Globals.iTokenErrorCount = 0;
}
if (fCallback)
{
Plugins.runHook('ajax-default-response', [sRequestAction, Enums.StorageResultType.Success === sType ? oData : null, sType, bCached, oRequestParameters]);
fCallback(
sType,
Enums.StorageResultType.Success === sType ? oData : null,
bCached,
sRequestAction,
oRequestParameters
);
}
}
;
switch (sType)
{
case 'success':
sType = Enums.StorageResultType.Success;
break;
case 'abort':
sType = Enums.StorageResultType.Abort;
break;
default:
sType = Enums.StorageResultType.Error;
break;
}
if (Enums.StorageResultType.Error === sType)
{
_.delay(fCall, 300);
}
else
{
fCall();
}
};
/**
* @param {?Function} fResultCallback
* @param {Object} oParameters
* @param {?number=} iTimeOut = 20000
* @param {string=} sGetAdd = ''
* @param {Array=} aAbortActions = []
* @return {jQuery.jqXHR}
*/
AbstractAjaxRemoteStorage.prototype.ajaxRequest = function (fResultCallback, oParameters, iTimeOut, sGetAdd, aAbortActions)
{
var
self = this,
bPost = '' === sGetAdd,
oHeaders = {},
iStart = (new window.Date()).getTime(),
oDefAjax = null,
sAction = ''
;
oParameters = oParameters || {};
iTimeOut = Utils.isNormal(iTimeOut) ? iTimeOut : 20000;
sGetAdd = Utils.isUnd(sGetAdd) ? '' : Utils.pString(sGetAdd);
aAbortActions = Utils.isArray(aAbortActions) ? aAbortActions : [];
sAction = oParameters.Action || '';
if (sAction && 0 < aAbortActions.length)
{
_.each(aAbortActions, function (sActionToAbort) {
if (self.oRequests[sActionToAbort])
{
self.oRequests[sActionToAbort].__aborted = true;
if (self.oRequests[sActionToAbort].abort)
{
self.oRequests[sActionToAbort].abort();
}
self.oRequests[sActionToAbort] = null;
}
});
}
if (bPost)
{
oParameters['XToken'] = RL.settingsGet('Token'); // TODO cjs
}
oDefAjax = $.ajax({
'type': bPost ? 'POST' : 'GET',
'url': LinkBuilder.ajax(sGetAdd),
'async': true,
'dataType': 'json',
'data': bPost ? oParameters : {},
'headers': oHeaders,
'timeout': iTimeOut,
'global': true
});
oDefAjax.always(function (oData, sType) {
var bCached = false;
if (oData && oData['Time'])
{
bCached = Utils.pInt(oData['Time']) > (new window.Date()).getTime() - iStart;
}
if (sAction && self.oRequests[sAction])
{
if (self.oRequests[sAction].__aborted)
{
sType = 'abort';
}
self.oRequests[sAction] = null;
}
self.defaultResponse(fResultCallback, sAction, sType, oData, bCached, oParameters);
});
if (sAction && 0 < aAbortActions.length && -1 < Utils.inArray(sAction, aAbortActions))
{
if (this.oRequests[sAction])
{
this.oRequests[sAction].__aborted = true;
if (this.oRequests[sAction].abort)
{
this.oRequests[sAction].abort();
}
this.oRequests[sAction] = null;
}
this.oRequests[sAction] = oDefAjax;
}
return oDefAjax;
};
/**
* @param {?Function} fCallback
* @param {string} sAction
* @param {Object=} oParameters
* @param {?number=} iTimeout
* @param {string=} sGetAdd = ''
* @param {Array=} aAbortActions = []
*/
AbstractAjaxRemoteStorage.prototype.defaultRequest = function (fCallback, sAction, oParameters, iTimeout, sGetAdd, aAbortActions)
{
oParameters = oParameters || {};
oParameters.Action = sAction;
sGetAdd = Utils.pString(sGetAdd);
Plugins.runHook('ajax-default-request', [sAction, oParameters, sGetAdd]);
this.ajaxRequest(fCallback, oParameters,
Utils.isUnd(iTimeout) ? Consts.Defaults.DefaultAjaxTimeout : Utils.pInt(iTimeout), sGetAdd, aAbortActions);
};
/**
* @param {?Function} fCallback
*/
AbstractAjaxRemoteStorage.prototype.noop = function (fCallback)
{
this.defaultRequest(fCallback, 'Noop');
};
/**
* @param {?Function} fCallback
* @param {string} sMessage
* @param {string} sFileName
* @param {number} iLineNo
* @param {string} sLocation
* @param {string} sHtmlCapa
* @param {number} iTime
*/
AbstractAjaxRemoteStorage.prototype.jsError = function (fCallback, sMessage, sFileName, iLineNo, sLocation, sHtmlCapa, iTime)
{
this.defaultRequest(fCallback, 'JsError', {
'Message': sMessage,
'FileName': sFileName,
'LineNo': iLineNo,
'Location': sLocation,
'HtmlCapa': sHtmlCapa,
'TimeOnPage': iTime
});
};
/**
* @param {?Function} fCallback
* @param {string} sType
* @param {Array=} mData = null
* @param {boolean=} bIsError = false
*/
AbstractAjaxRemoteStorage.prototype.jsInfo = function (fCallback, sType, mData, bIsError)
{
this.defaultRequest(fCallback, 'JsInfo', {
'Type': sType,
'Data': mData,
'IsError': (Utils.isUnd(bIsError) ? false : !!bIsError) ? '1' : '0'
});
};
/**
* @param {?Function} fCallback
*/
AbstractAjaxRemoteStorage.prototype.getPublicKey = function (fCallback)
{
this.defaultRequest(fCallback, 'GetPublicKey');
};
/**
* @param {?Function} fCallback
* @param {string} sVersion
*/
AbstractAjaxRemoteStorage.prototype.jsVersion = function (fCallback, sVersion)
{
this.defaultRequest(fCallback, 'Version', {
'Version': sVersion
});
};
module.exports = AbstractAjaxRemoteStorage;
}(module));
},{"../Common/Consts.js":4,"../Common/Enums.js":5,"../Common/Globals.js":6,"../Common/LinkBuilder.js":7,"../Common/Plugins.js":8,"../Common/Utils.js":9,"../External/jquery.js":19,"../External/window.js":25,"../RL.js":32}],35:[function(require,module,exports){
/* 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')
;
/**
* @constructor
*/
function AbstractData()
{
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();
}
else
{
Utils.restoreKeyFilter();
}
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')); // TODO cjs
});
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));
},{"../Common/Enums.js":5,"../Common/Globals.js":6,"../Common/Utils.js":9,"../External/key.js":20,"../External/ko.js":21}],36:[function(require,module,exports){
/* 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));
},{"../External/underscore.js":24,"./LocalStorages/CookieDriver.js":37,"./LocalStorages/LocalStorageDriver.js":38}],37:[function(require,module,exports){
/* 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));
},{"../../Common/Consts.js":4,"../../Common/Utils.js":9,"../../External/JSON.js":15,"../../External/jquery.js":19}],38:[function(require,module,exports){
/* 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));
},{"../../Common/Consts.js":4,"../../Common/Utils.js":9,"../../External/JSON.js":15,"../../External/window.js":25}],39:[function(require,module,exports){
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module) {
'use strict';
var
_ = require('../External/underscore.js'),
Utils = require('../Common/Utils.js'),
Cache = require('../Storages/WebMailCacheStorage.js'),
AbstractAjaxRemoteStorage = require('./AbstractAjaxRemoteStorage.js')
;
/**
* @constructor
* @extends AbstractAjaxRemoteStorage
*/
function WebMailAjaxRemoteStorage()
{
AbstractAjaxRemoteStorage.call(this);
this.oRequests = {};
}
_.extend(WebMailAjaxRemoteStorage.prototype, AbstractAjaxRemoteStorage.prototype);
/**
* @param {?Function} fCallback
*/
WebMailAjaxRemoteStorage.prototype.folders = function (fCallback)
{
this.defaultRequest(fCallback, 'Folders', {
'SentFolder': RL.settingsGet('SentFolder'),
'DraftFolder': RL.settingsGet('DraftFolder'),
'SpamFolder': RL.settingsGet('SpamFolder'),
'TrashFolder': RL.settingsGet('TrashFolder'),
'ArchiveFolder': RL.settingsGet('ArchiveFolder')
}, null, '', ['Folders']);
};
/**
* @param {?Function} fCallback
* @param {string} sEmail
* @param {string} sLogin
* @param {string} sPassword
* @param {boolean} bSignMe
* @param {string=} sLanguage
* @param {string=} sAdditionalCode
* @param {boolean=} bAdditionalCodeSignMe
*/
WebMailAjaxRemoteStorage.prototype.login = function (fCallback, sEmail, sLogin, sPassword, bSignMe, sLanguage, sAdditionalCode, bAdditionalCodeSignMe)
{
this.defaultRequest(fCallback, 'Login', {
'Email': sEmail,
'Login': sLogin,
'Password': sPassword,
'Language': sLanguage || '',
'AdditionalCode': sAdditionalCode || '',
'AdditionalCodeSignMe': bAdditionalCodeSignMe ? '1' : '0',
'SignMe': bSignMe ? '1' : '0'
});
};
/**
* @param {?Function} fCallback
*/
WebMailAjaxRemoteStorage.prototype.getTwoFactor = function (fCallback)
{
this.defaultRequest(fCallback, 'GetTwoFactorInfo');
};
/**
* @param {?Function} fCallback
*/
WebMailAjaxRemoteStorage.prototype.createTwoFactor = function (fCallback)
{
this.defaultRequest(fCallback, 'CreateTwoFactorSecret');
};
/**
* @param {?Function} fCallback
*/
WebMailAjaxRemoteStorage.prototype.clearTwoFactor = function (fCallback)
{
this.defaultRequest(fCallback, 'ClearTwoFactorInfo');
};
/**
* @param {?Function} fCallback
*/
WebMailAjaxRemoteStorage.prototype.showTwoFactorSecret = function (fCallback)
{
this.defaultRequest(fCallback, 'ShowTwoFactorSecret');
};
/**
* @param {?Function} fCallback
* @param {string} sCode
*/
WebMailAjaxRemoteStorage.prototype.testTwoFactor = function (fCallback, sCode)
{
this.defaultRequest(fCallback, 'TestTwoFactorInfo', {
'Code': sCode
});
};
/**
* @param {?Function} fCallback
* @param {boolean} bEnable
*/
WebMailAjaxRemoteStorage.prototype.enableTwoFactor = function (fCallback, bEnable)
{
this.defaultRequest(fCallback, 'EnableTwoFactor', {
'Enable': bEnable ? '1' : '0'
});
};
/**
* @param {?Function} fCallback
*/
WebMailAjaxRemoteStorage.prototype.clearTwoFactorInfo = function (fCallback)
{
this.defaultRequest(fCallback, 'ClearTwoFactorInfo');
};
/**
* @param {?Function} fCallback
*/
WebMailAjaxRemoteStorage.prototype.contactsSync = function (fCallback)
{
this.defaultRequest(fCallback, 'ContactsSync', null, Consts.Defaults.ContactsSyncAjaxTimeout);
};
/**
* @param {?Function} fCallback
* @param {boolean} bEnable
* @param {string} sUrl
* @param {string} sUser
* @param {string} sPassword
*/
WebMailAjaxRemoteStorage.prototype.saveContactsSyncData = function (fCallback, bEnable, sUrl, sUser, sPassword)
{
this.defaultRequest(fCallback, 'SaveContactsSyncData', {
'Enable': bEnable ? '1' : '0',
'Url': sUrl,
'User': sUser,
'Password': sPassword
});
};
/**
* @param {?Function} fCallback
* @param {string} sEmail
* @param {string} sLogin
* @param {string} sPassword
*/
WebMailAjaxRemoteStorage.prototype.accountAdd = function (fCallback, sEmail, sLogin, sPassword)
{
this.defaultRequest(fCallback, 'AccountAdd', {
'Email': sEmail,
'Login': sLogin,
'Password': sPassword
});
};
/**
* @param {?Function} fCallback
* @param {string} sEmailToDelete
*/
WebMailAjaxRemoteStorage.prototype.accountDelete = function (fCallback, sEmailToDelete)
{
this.defaultRequest(fCallback, 'AccountDelete', {
'EmailToDelete': sEmailToDelete
});
};
/**
* @param {?Function} fCallback
* @param {string} sId
* @param {string} sEmail
* @param {string} sName
* @param {string} sReplyTo
* @param {string} sBcc
*/
WebMailAjaxRemoteStorage.prototype.identityUpdate = function (fCallback, sId, sEmail, sName, sReplyTo, sBcc)
{
this.defaultRequest(fCallback, 'IdentityUpdate', {
'Id': sId,
'Email': sEmail,
'Name': sName,
'ReplyTo': sReplyTo,
'Bcc': sBcc
});
};
/**
* @param {?Function} fCallback
* @param {string} sIdToDelete
*/
WebMailAjaxRemoteStorage.prototype.identityDelete = function (fCallback, sIdToDelete)
{
this.defaultRequest(fCallback, 'IdentityDelete', {
'IdToDelete': sIdToDelete
});
};
/**
* @param {?Function} fCallback
*/
WebMailAjaxRemoteStorage.prototype.accountsAndIdentities = function (fCallback)
{
this.defaultRequest(fCallback, 'AccountsAndIdentities');
};
/**
* @param {?Function} fCallback
* @param {string} sFolderFullNameRaw
* @param {number=} iOffset = 0
* @param {number=} iLimit = 20
* @param {string=} sSearch = ''
* @param {boolean=} bSilent = false
*/
WebMailAjaxRemoteStorage.prototype.messageList = function (fCallback, sFolderFullNameRaw, iOffset, iLimit, sSearch, bSilent)
{
sFolderFullNameRaw = Utils.pString(sFolderFullNameRaw);
var
oData = RL.data(),
sFolderHash = Cache.getFolderHash(sFolderFullNameRaw)
;
bSilent = Utils.isUnd(bSilent) ? false : !!bSilent;
iOffset = Utils.isUnd(iOffset) ? 0 : Utils.pInt(iOffset);
iLimit = Utils.isUnd(iOffset) ? 20 : Utils.pInt(iLimit);
sSearch = Utils.pString(sSearch);
if ('' !== sFolderHash && ('' === sSearch || -1 === sSearch.indexOf('is:')))
{
this.defaultRequest(fCallback, 'MessageList', {},
'' === sSearch ? Consts.Defaults.DefaultAjaxTimeout : Consts.Defaults.SearchAjaxTimeout,
'MessageList/' + Base64.urlsafe_encode([
sFolderFullNameRaw,
iOffset,
iLimit,
sSearch,
oData.projectHash(),
sFolderHash,
'INBOX' === sFolderFullNameRaw ? Cache.getFolderUidNext(sFolderFullNameRaw) : '',
oData.threading() && oData.useThreads() ? '1' : '0',
oData.threading() && sFolderFullNameRaw === oData.messageListThreadFolder() ? oData.messageListThreadUids().join(',') : ''
].join(String.fromCharCode(0))), bSilent ? [] : ['MessageList']);
}
else
{
this.defaultRequest(fCallback, 'MessageList', {
'Folder': sFolderFullNameRaw,
'Offset': iOffset,
'Limit': iLimit,
'Search': sSearch,
'UidNext': 'INBOX' === sFolderFullNameRaw ? Cache.getFolderUidNext(sFolderFullNameRaw) : '',
'UseThreads': RL.data().threading() && RL.data().useThreads() ? '1' : '0',
'ExpandedThreadUid': oData.threading() && sFolderFullNameRaw === oData.messageListThreadFolder() ? oData.messageListThreadUids().join(',') : ''
}, '' === sSearch ? Consts.Defaults.DefaultAjaxTimeout : Consts.Defaults.SearchAjaxTimeout, '', bSilent ? [] : ['MessageList']);
}
};
/**
* @param {?Function} fCallback
* @param {Array} aDownloads
*/
WebMailAjaxRemoteStorage.prototype.messageUploadAttachments = function (fCallback, aDownloads)
{
this.defaultRequest(fCallback, 'MessageUploadAttachments', {
'Attachments': aDownloads
}, 999000);
};
/**
* @param {?Function} fCallback
* @param {string} sFolderFullNameRaw
* @param {number} iUid
* @return {boolean}
*/
WebMailAjaxRemoteStorage.prototype.message = function (fCallback, sFolderFullNameRaw, iUid)
{
sFolderFullNameRaw = Utils.pString(sFolderFullNameRaw);
iUid = Utils.pInt(iUid);
if (Cache.getFolderFromCacheList(sFolderFullNameRaw) && 0 < iUid)
{
this.defaultRequest(fCallback, 'Message', {}, null,
'Message/' + Base64.urlsafe_encode([
sFolderFullNameRaw,
iUid,
RL.data().projectHash(),
RL.data().threading() && RL.data().useThreads() ? '1' : '0'
].join(String.fromCharCode(0))), ['Message']);
return true;
}
return false;
};
/**
* @param {?Function} fCallback
* @param {Array} aExternals
*/
WebMailAjaxRemoteStorage.prototype.composeUploadExternals = function (fCallback, aExternals)
{
this.defaultRequest(fCallback, 'ComposeUploadExternals', {
'Externals': aExternals
}, 999000);
};
/**
* @param {?Function} fCallback
* @param {string} sUrl
* @param {string} sAccessToken
*/
WebMailAjaxRemoteStorage.prototype.composeUploadDrive = function (fCallback, sUrl, sAccessToken)
{
this.defaultRequest(fCallback, 'ComposeUploadDrive', {
'AccessToken': sAccessToken,
'Url': sUrl
}, 999000);
};
/**
* @param {?Function} fCallback
* @param {string} sFolder
* @param {Array=} aList = []
*/
WebMailAjaxRemoteStorage.prototype.folderInformation = function (fCallback, sFolder, aList)
{
var
bRequest = true,
aUids = []
;
if (Utils.isArray(aList) && 0 < aList.length)
{
bRequest = false;
_.each(aList, function (oMessageListItem) {
if (!Cache.getMessageFlagsFromCache(oMessageListItem.folderFullNameRaw, oMessageListItem.uid))
{
aUids.push(oMessageListItem.uid);
}
if (0 < oMessageListItem.threads().length)
{
_.each(oMessageListItem.threads(), function (sUid) {
if (!Cache.getMessageFlagsFromCache(oMessageListItem.folderFullNameRaw, sUid))
{
aUids.push(sUid);
}
});
}
});
if (0 < aUids.length)
{
bRequest = true;
}
}
if (bRequest)
{
this.defaultRequest(fCallback, 'FolderInformation', {
'Folder': sFolder,
'FlagsUids': Utils.isArray(aUids) ? aUids.join(',') : '',
'UidNext': 'INBOX' === sFolder ? Cache.getFolderUidNext(sFolder) : ''
});
}
else if (RL.data().useThreads())
{
RL.reloadFlagsCurrentMessageListAndMessageFromCache();
}
};
/**
* @param {?Function} fCallback
* @param {Array} aFolders
*/
WebMailAjaxRemoteStorage.prototype.folderInformationMultiply = function (fCallback, aFolders)
{
this.defaultRequest(fCallback, 'FolderInformationMultiply', {
'Folders': aFolders
});
};
/**
* @param {?Function} fCallback
*/
WebMailAjaxRemoteStorage.prototype.logout = function (fCallback)
{
this.defaultRequest(fCallback, 'Logout');
};
/**
* @param {?Function} fCallback
* @param {string} sFolderFullNameRaw
* @param {Array} aUids
* @param {boolean} bSetFlagged
*/
WebMailAjaxRemoteStorage.prototype.messageSetFlagged = function (fCallback, sFolderFullNameRaw, aUids, bSetFlagged)
{
this.defaultRequest(fCallback, 'MessageSetFlagged', {
'Folder': sFolderFullNameRaw,
'Uids': aUids.join(','),
'SetAction': bSetFlagged ? '1' : '0'
});
};
/**
* @param {?Function} fCallback
* @param {string} sFolderFullNameRaw
* @param {Array} aUids
* @param {boolean} bSetSeen
*/
WebMailAjaxRemoteStorage.prototype.messageSetSeen = function (fCallback, sFolderFullNameRaw, aUids, bSetSeen)
{
this.defaultRequest(fCallback, 'MessageSetSeen', {
'Folder': sFolderFullNameRaw,
'Uids': aUids.join(','),
'SetAction': bSetSeen ? '1' : '0'
});
};
/**
* @param {?Function} fCallback
* @param {string} sFolderFullNameRaw
* @param {boolean} bSetSeen
*/
WebMailAjaxRemoteStorage.prototype.messageSetSeenToAll = function (fCallback, sFolderFullNameRaw, bSetSeen)
{
this.defaultRequest(fCallback, 'MessageSetSeenToAll', {
'Folder': sFolderFullNameRaw,
'SetAction': bSetSeen ? '1' : '0'
});
};
/**
* @param {?Function} fCallback
* @param {string} sMessageFolder
* @param {string} sMessageUid
* @param {string} sDraftFolder
* @param {string} sFrom
* @param {string} sTo
* @param {string} sCc
* @param {string} sBcc
* @param {string} sSubject
* @param {boolean} bTextIsHtml
* @param {string} sText
* @param {Array} aAttachments
* @param {(Array|null)} aDraftInfo
* @param {string} sInReplyTo
* @param {string} sReferences
*/
WebMailAjaxRemoteStorage.prototype.saveMessage = function (fCallback, sMessageFolder, sMessageUid, sDraftFolder,
sFrom, sTo, sCc, sBcc, sSubject, bTextIsHtml, sText, aAttachments, aDraftInfo, sInReplyTo, sReferences)
{
this.defaultRequest(fCallback, 'SaveMessage', {
'MessageFolder': sMessageFolder,
'MessageUid': sMessageUid,
'DraftFolder': sDraftFolder,
'From': sFrom,
'To': sTo,
'Cc': sCc,
'Bcc': sBcc,
'Subject': sSubject,
'TextIsHtml': bTextIsHtml ? '1' : '0',
'Text': sText,
'DraftInfo': aDraftInfo,
'InReplyTo': sInReplyTo,
'References': sReferences,
'Attachments': aAttachments
}, Consts.Defaults.SaveMessageAjaxTimeout);
};
/**
* @param {?Function} fCallback
* @param {string} sMessageFolder
* @param {string} sMessageUid
* @param {string} sReadReceipt
* @param {string} sSubject
* @param {string} sText
*/
WebMailAjaxRemoteStorage.prototype.sendReadReceiptMessage = function (fCallback, sMessageFolder, sMessageUid, sReadReceipt, sSubject, sText)
{
this.defaultRequest(fCallback, 'SendReadReceiptMessage', {
'MessageFolder': sMessageFolder,
'MessageUid': sMessageUid,
'ReadReceipt': sReadReceipt,
'Subject': sSubject,
'Text': sText
});
};
/**
* @param {?Function} fCallback
* @param {string} sMessageFolder
* @param {string} sMessageUid
* @param {string} sSentFolder
* @param {string} sFrom
* @param {string} sTo
* @param {string} sCc
* @param {string} sBcc
* @param {string} sSubject
* @param {boolean} bTextIsHtml
* @param {string} sText
* @param {Array} aAttachments
* @param {(Array|null)} aDraftInfo
* @param {string} sInReplyTo
* @param {string} sReferences
* @param {boolean} bRequestReadReceipt
*/
WebMailAjaxRemoteStorage.prototype.sendMessage = function (fCallback, sMessageFolder, sMessageUid, sSentFolder,
sFrom, sTo, sCc, sBcc, sSubject, bTextIsHtml, sText, aAttachments, aDraftInfo, sInReplyTo, sReferences, bRequestReadReceipt)
{
this.defaultRequest(fCallback, 'SendMessage', {
'MessageFolder': sMessageFolder,
'MessageUid': sMessageUid,
'SentFolder': sSentFolder,
'From': sFrom,
'To': sTo,
'Cc': sCc,
'Bcc': sBcc,
'Subject': sSubject,
'TextIsHtml': bTextIsHtml ? '1' : '0',
'Text': sText,
'DraftInfo': aDraftInfo,
'InReplyTo': sInReplyTo,
'References': sReferences,
'ReadReceiptRequest': bRequestReadReceipt ? '1' : '0',
'Attachments': aAttachments
}, Consts.Defaults.SendMessageAjaxTimeout);
};
/**
* @param {?Function} fCallback
* @param {Object} oData
*/
WebMailAjaxRemoteStorage.prototype.saveSystemFolders = function (fCallback, oData)
{
this.defaultRequest(fCallback, 'SystemFoldersUpdate', oData);
};
/**
* @param {?Function} fCallback
* @param {Object} oData
*/
WebMailAjaxRemoteStorage.prototype.saveSettings = function (fCallback, oData)
{
this.defaultRequest(fCallback, 'SettingsUpdate', oData);
};
/**
* @param {?Function} fCallback
* @param {string} sPrevPassword
* @param {string} sNewPassword
*/
WebMailAjaxRemoteStorage.prototype.changePassword = function (fCallback, sPrevPassword, sNewPassword)
{
this.defaultRequest(fCallback, 'ChangePassword', {
'PrevPassword': sPrevPassword,
'NewPassword': sNewPassword
});
};
/**
* @param {?Function} fCallback
* @param {string} sNewFolderName
* @param {string} sParentName
*/
WebMailAjaxRemoteStorage.prototype.folderCreate = function (fCallback, sNewFolderName, sParentName)
{
this.defaultRequest(fCallback, 'FolderCreate', {
'Folder': sNewFolderName,
'Parent': sParentName
}, null, '', ['Folders']);
};
/**
* @param {?Function} fCallback
* @param {string} sFolderFullNameRaw
*/
WebMailAjaxRemoteStorage.prototype.folderDelete = function (fCallback, sFolderFullNameRaw)
{
this.defaultRequest(fCallback, 'FolderDelete', {
'Folder': sFolderFullNameRaw
}, null, '', ['Folders']);
};
/**
* @param {?Function} fCallback
* @param {string} sPrevFolderFullNameRaw
* @param {string} sNewFolderName
*/
WebMailAjaxRemoteStorage.prototype.folderRename = function (fCallback, sPrevFolderFullNameRaw, sNewFolderName)
{
this.defaultRequest(fCallback, 'FolderRename', {
'Folder': sPrevFolderFullNameRaw,
'NewFolderName': sNewFolderName
}, null, '', ['Folders']);
};
/**
* @param {?Function} fCallback
* @param {string} sFolderFullNameRaw
*/
WebMailAjaxRemoteStorage.prototype.folderClear = function (fCallback, sFolderFullNameRaw)
{
this.defaultRequest(fCallback, 'FolderClear', {
'Folder': sFolderFullNameRaw
});
};
/**
* @param {?Function} fCallback
* @param {string} sFolderFullNameRaw
* @param {boolean} bSubscribe
*/
WebMailAjaxRemoteStorage.prototype.folderSetSubscribe = function (fCallback, sFolderFullNameRaw, bSubscribe)
{
this.defaultRequest(fCallback, 'FolderSubscribe', {
'Folder': sFolderFullNameRaw,
'Subscribe': bSubscribe ? '1' : '0'
});
};
/**
* @param {?Function} fCallback
* @param {string} sFolder
* @param {string} sToFolder
* @param {Array} aUids
* @param {string=} sLearning
*/
WebMailAjaxRemoteStorage.prototype.messagesMove = function (fCallback, sFolder, sToFolder, aUids, sLearning)
{
this.defaultRequest(fCallback, 'MessageMove', {
'FromFolder': sFolder,
'ToFolder': sToFolder,
'Uids': aUids.join(','),
'Learning': sLearning || ''
}, null, '', ['MessageList']);
};
/**
* @param {?Function} fCallback
* @param {string} sFolder
* @param {string} sToFolder
* @param {Array} aUids
*/
WebMailAjaxRemoteStorage.prototype.messagesCopy = function (fCallback, sFolder, sToFolder, aUids)
{
this.defaultRequest(fCallback, 'MessageCopy', {
'FromFolder': sFolder,
'ToFolder': sToFolder,
'Uids': aUids.join(',')
});
};
/**
* @param {?Function} fCallback
* @param {string} sFolder
* @param {Array} aUids
*/
WebMailAjaxRemoteStorage.prototype.messagesDelete = function (fCallback, sFolder, aUids)
{
this.defaultRequest(fCallback, 'MessageDelete', {
'Folder': sFolder,
'Uids': aUids.join(',')
}, null, '', ['MessageList']);
};
/**
* @param {?Function} fCallback
*/
WebMailAjaxRemoteStorage.prototype.appDelayStart = function (fCallback)
{
this.defaultRequest(fCallback, 'AppDelayStart');
};
/**
* @param {?Function} fCallback
*/
WebMailAjaxRemoteStorage.prototype.quota = function (fCallback)
{
this.defaultRequest(fCallback, 'Quota');
};
/**
* @param {?Function} fCallback
* @param {number} iOffset
* @param {number} iLimit
* @param {string} sSearch
*/
WebMailAjaxRemoteStorage.prototype.contacts = function (fCallback, iOffset, iLimit, sSearch)
{
this.defaultRequest(fCallback, 'Contacts', {
'Offset': iOffset,
'Limit': iLimit,
'Search': sSearch
}, null, '', ['Contacts']);
};
/**
* @param {?Function} fCallback
*/
WebMailAjaxRemoteStorage.prototype.contactSave = function (fCallback, sRequestUid, sUid, sTags, aProperties)
{
this.defaultRequest(fCallback, 'ContactSave', {
'RequestUid': sRequestUid,
'Uid': Utils.trim(sUid),
'Tags': Utils.trim(sTags),
'Properties': aProperties
});
};
/**
* @param {?Function} fCallback
* @param {Array} aUids
*/
WebMailAjaxRemoteStorage.prototype.contactsDelete = function (fCallback, aUids)
{
this.defaultRequest(fCallback, 'ContactsDelete', {
'Uids': aUids.join(',')
});
};
/**
* @param {?Function} fCallback
* @param {string} sQuery
* @param {number} iPage
*/
WebMailAjaxRemoteStorage.prototype.suggestions = function (fCallback, sQuery, iPage)
{
this.defaultRequest(fCallback, 'Suggestions', {
'Query': sQuery,
'Page': iPage
}, null, '', ['Suggestions']);
};
/**
* @param {?Function} fCallback
*/
WebMailAjaxRemoteStorage.prototype.facebookUser = function (fCallback)
{
this.defaultRequest(fCallback, 'SocialFacebookUserInformation');
};
/**
* @param {?Function} fCallback
*/
WebMailAjaxRemoteStorage.prototype.facebookDisconnect = function (fCallback)
{
this.defaultRequest(fCallback, 'SocialFacebookDisconnect');
};
/**
* @param {?Function} fCallback
*/
WebMailAjaxRemoteStorage.prototype.twitterUser = function (fCallback)
{
this.defaultRequest(fCallback, 'SocialTwitterUserInformation');
};
/**
* @param {?Function} fCallback
*/
WebMailAjaxRemoteStorage.prototype.twitterDisconnect = function (fCallback)
{
this.defaultRequest(fCallback, 'SocialTwitterDisconnect');
};
/**
* @param {?Function} fCallback
*/
WebMailAjaxRemoteStorage.prototype.googleUser = function (fCallback)
{
this.defaultRequest(fCallback, 'SocialGoogleUserInformation');
};
/**
* @param {?Function} fCallback
*/
WebMailAjaxRemoteStorage.prototype.googleDisconnect = function (fCallback)
{
this.defaultRequest(fCallback, 'SocialGoogleDisconnect');
};
/**
* @param {?Function} fCallback
*/
WebMailAjaxRemoteStorage.prototype.socialUsers = function (fCallback)
{
this.defaultRequest(fCallback, 'SocialUsers');
};
module.exports = new WebMailAjaxRemoteStorage();
}(module));
},{"../Common/Utils.js":9,"../External/underscore.js":24,"../Storages/WebMailCacheStorage.js":40,"./AbstractAjaxRemoteStorage.js":34}],40:[function(require,module,exports){
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module) {
'use strict';
var
_ = require('../External/underscore.js'),
Enums = require('../Common/Enums.js'),
Utils = require('../Common/Utils.js'),
LinkBuilder = require('../Common/LinkBuilder.js'),
RL = require('../RL.js')
;
/**
* @constructor
*/
function WebMailCacheStorage()
{
this.oFoldersCache = {};
this.oFoldersNamesCache = {};
this.oFolderHashCache = {};
this.oFolderUidNextCache = {};
this.oMessageListHashCache = {};
this.oMessageFlagsCache = {};
this.oNewMessage = {};
this.oRequestedMessage = {};
this.bCapaGravatar = RL().capa(Enums.Capa.Gravatar);
}
/**
* @type {boolean}
*/
WebMailCacheStorage.prototype.bCapaGravatar = false;
/**
* @type {Object}
*/
WebMailCacheStorage.prototype.oFoldersCache = {};
/**
* @type {Object}
*/
WebMailCacheStorage.prototype.oFoldersNamesCache = {};
/**
* @type {Object}
*/
WebMailCacheStorage.prototype.oFolderHashCache = {};
/**
* @type {Object}
*/
WebMailCacheStorage.prototype.oFolderUidNextCache = {};
/**
* @type {Object}
*/
WebMailCacheStorage.prototype.oMessageListHashCache = {};
/**
* @type {Object}
*/
WebMailCacheStorage.prototype.oMessageFlagsCache = {};
/**
* @type {Object}
*/
WebMailCacheStorage.prototype.oBodies = {};
/**
* @type {Object}
*/
WebMailCacheStorage.prototype.oNewMessage = {};
/**
* @type {Object}
*/
WebMailCacheStorage.prototype.oRequestedMessage = {};
WebMailCacheStorage.prototype.clear = function ()
{
this.oFoldersCache = {};
this.oFoldersNamesCache = {};
this.oFolderHashCache = {};
this.oFolderUidNextCache = {};
this.oMessageListHashCache = {};
this.oMessageFlagsCache = {};
this.oBodies = {};
};
/**
* @param {string} sEmail
* @param {Function} fCallback
* @return {string}
*/
WebMailCacheStorage.prototype.getUserPic = function (sEmail, fCallback)
{
sEmail = Utils.trim(sEmail);
fCallback(this.bCapaGravatar && '' !== sEmail ? LinkBuilder.avatarLink(sEmail) : '', sEmail);
};
/**
* @param {string} sFolderFullNameRaw
* @param {string} sUid
* @return {string}
*/
WebMailCacheStorage.prototype.getMessageKey = function (sFolderFullNameRaw, sUid)
{
return sFolderFullNameRaw + '#' + sUid;
};
/**
* @param {string} sFolder
* @param {string} sUid
*/
WebMailCacheStorage.prototype.addRequestedMessage = function (sFolder, sUid)
{
this.oRequestedMessage[this.getMessageKey(sFolder, sUid)] = true;
};
/**
* @param {string} sFolder
* @param {string} sUid
* @return {boolean}
*/
WebMailCacheStorage.prototype.hasRequestedMessage = function (sFolder, sUid)
{
return true === this.oRequestedMessage[this.getMessageKey(sFolder, sUid)];
};
/**
* @param {string} sFolderFullNameRaw
* @param {string} sUid
*/
WebMailCacheStorage.prototype.addNewMessageCache = function (sFolderFullNameRaw, sUid)
{
this.oNewMessage[this.getMessageKey(sFolderFullNameRaw, sUid)] = true;
};
/**
* @param {string} sFolderFullNameRaw
* @param {string} sUid
*/
WebMailCacheStorage.prototype.hasNewMessageAndRemoveFromCache = function (sFolderFullNameRaw, sUid)
{
if (this.oNewMessage[this.getMessageKey(sFolderFullNameRaw, sUid)])
{
this.oNewMessage[this.getMessageKey(sFolderFullNameRaw, sUid)] = null;
return true;
}
return false;
};
WebMailCacheStorage.prototype.clearNewMessageCache = function ()
{
this.oNewMessage = {};
};
/**
* @param {string} sFolderHash
* @return {string}
*/
WebMailCacheStorage.prototype.getFolderFullNameRaw = function (sFolderHash)
{
return '' !== sFolderHash && this.oFoldersNamesCache[sFolderHash] ? this.oFoldersNamesCache[sFolderHash] : '';
};
/**
* @param {string} sFolderHash
* @param {string} sFolderFullNameRaw
*/
WebMailCacheStorage.prototype.setFolderFullNameRaw = function (sFolderHash, sFolderFullNameRaw)
{
this.oFoldersNamesCache[sFolderHash] = sFolderFullNameRaw;
};
/**
* @param {string} sFolderFullNameRaw
* @return {string}
*/
WebMailCacheStorage.prototype.getFolderHash = function (sFolderFullNameRaw)
{
return '' !== sFolderFullNameRaw && this.oFolderHashCache[sFolderFullNameRaw] ? this.oFolderHashCache[sFolderFullNameRaw] : '';
};
/**
* @param {string} sFolderFullNameRaw
* @param {string} sFolderHash
*/
WebMailCacheStorage.prototype.setFolderHash = function (sFolderFullNameRaw, sFolderHash)
{
this.oFolderHashCache[sFolderFullNameRaw] = sFolderHash;
};
/**
* @param {string} sFolderFullNameRaw
* @return {string}
*/
WebMailCacheStorage.prototype.getFolderUidNext = function (sFolderFullNameRaw)
{
return '' !== sFolderFullNameRaw && this.oFolderUidNextCache[sFolderFullNameRaw] ? this.oFolderUidNextCache[sFolderFullNameRaw] : '';
};
/**
* @param {string} sFolderFullNameRaw
* @param {string} sUidNext
*/
WebMailCacheStorage.prototype.setFolderUidNext = function (sFolderFullNameRaw, sUidNext)
{
this.oFolderUidNextCache[sFolderFullNameRaw] = sUidNext;
};
/**
* @param {string} sFolderFullNameRaw
* @return {?FolderModel}
*/
WebMailCacheStorage.prototype.getFolderFromCacheList = function (sFolderFullNameRaw)
{
return '' !== sFolderFullNameRaw && this.oFoldersCache[sFolderFullNameRaw] ? this.oFoldersCache[sFolderFullNameRaw] : null;
};
/**
* @param {string} sFolderFullNameRaw
* @param {?FolderModel} oFolder
*/
WebMailCacheStorage.prototype.setFolderToCacheList = function (sFolderFullNameRaw, oFolder)
{
this.oFoldersCache[sFolderFullNameRaw] = oFolder;
};
/**
* @param {string} sFolderFullNameRaw
*/
WebMailCacheStorage.prototype.removeFolderFromCacheList = function (sFolderFullNameRaw)
{
this.setFolderToCacheList(sFolderFullNameRaw, null);
};
/**
* @param {string} sFolderFullName
* @param {string} sUid
* @return {?Array}
*/
WebMailCacheStorage.prototype.getMessageFlagsFromCache = function (sFolderFullName, sUid)
{
return this.oMessageFlagsCache[sFolderFullName] && this.oMessageFlagsCache[sFolderFullName][sUid] ?
this.oMessageFlagsCache[sFolderFullName][sUid] : null;
};
/**
* @param {string} sFolderFullName
* @param {string} sUid
* @param {Array} aFlagsCache
*/
WebMailCacheStorage.prototype.setMessageFlagsToCache = function (sFolderFullName, sUid, aFlagsCache)
{
if (!this.oMessageFlagsCache[sFolderFullName])
{
this.oMessageFlagsCache[sFolderFullName] = {};
}
this.oMessageFlagsCache[sFolderFullName][sUid] = aFlagsCache;
};
/**
* @param {string} sFolderFullName
*/
WebMailCacheStorage.prototype.clearMessageFlagsFromCacheByFolder = function (sFolderFullName)
{
this.oMessageFlagsCache[sFolderFullName] = {};
};
/**
* @param {(MessageModel|null)} oMessage
*/
WebMailCacheStorage.prototype.initMessageFlagsFromCache = function (oMessage)
{
if (oMessage)
{
var
self = this,
aFlags = this.getMessageFlagsFromCache(oMessage.folderFullNameRaw, oMessage.uid),
mUnseenSubUid = null,
mFlaggedSubUid = null
;
if (aFlags && 0 < aFlags.length)
{
oMessage.unseen(!!aFlags[0]);
oMessage.flagged(!!aFlags[1]);
oMessage.answered(!!aFlags[2]);
oMessage.forwarded(!!aFlags[3]);
oMessage.isReadReceipt(!!aFlags[4]);
}
if (0 < oMessage.threads().length)
{
mUnseenSubUid = _.find(oMessage.threads(), function (iSubUid) {
var aFlags = self.getMessageFlagsFromCache(oMessage.folderFullNameRaw, iSubUid);
return aFlags && 0 < aFlags.length && !!aFlags[0];
});
mFlaggedSubUid = _.find(oMessage.threads(), function (iSubUid) {
var aFlags = self.getMessageFlagsFromCache(oMessage.folderFullNameRaw, iSubUid);
return aFlags && 0 < aFlags.length && !!aFlags[1];
});
oMessage.hasUnseenSubMessage(mUnseenSubUid && 0 < Utils.pInt(mUnseenSubUid));
oMessage.hasFlaggedSubMessage(mFlaggedSubUid && 0 < Utils.pInt(mFlaggedSubUid));
}
}
};
/**
* @param {(MessageModel|null)} oMessage
*/
WebMailCacheStorage.prototype.storeMessageFlagsToCache = function (oMessage)
{
if (oMessage)
{
this.setMessageFlagsToCache(
oMessage.folderFullNameRaw,
oMessage.uid,
[oMessage.unseen(), oMessage.flagged(), oMessage.answered(), oMessage.forwarded(), oMessage.isReadReceipt()]
);
}
};
/**
* @param {string} sFolder
* @param {string} sUid
* @param {Array} aFlags
*/
WebMailCacheStorage.prototype.storeMessageFlagsToCacheByFolderAndUid = function (sFolder, sUid, aFlags)
{
if (Utils.isArray(aFlags) && 0 < aFlags.length)
{
this.setMessageFlagsToCache(sFolder, sUid, aFlags);
}
};
module.exports = new WebMailCacheStorage();
}(module));
},{"../Common/Enums.js":5,"../Common/LinkBuilder.js":7,"../Common/Utils.js":9,"../External/underscore.js":24,"../RL.js":32}],41:[function(require,module,exports){
/* 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'),
moment = require('../External/moment.js'),
$div = require('../External/$div.js'),
NotificationClass = require('../External/NotificationClass.js'),
Consts = require('../Common/Consts.js'),
Enums = require('../Common/Enums.js'),
Globals = require('../Common/Globals.js'),
Utils = require('../Common/Utils.js'),
LinkBuilder = require('../Common/LinkBuilder.js'),
Cache = require('../Storages/WebMailCacheStorage.js'),
Remote = require('../Storages/WebMailAjaxRemoteStorage.js'),
kn = require('../Knoin/Knoin.js'),
MessageModel = require('../Models/MessageModel.js'),
LocalStorage = require('./LocalStorage.js'),
AbstractData = require('./AbstractData.js')
;
/**
* @constructor
* @extends AbstractData
*/
function WebMailDataStorage()
{
AbstractData.call(this);
var
fRemoveSystemFolderType = function (observable) {
return function () {
var oFolder = Cache.getFolderFromCacheList(observable()); // TODO cjs
if (oFolder)
{
oFolder.type(Enums.FolderType.User);
}
};
},
fSetSystemFolderType = function (iType) {
return function (sValue) {
var oFolder = Cache.getFolderFromCacheList(sValue); // TODO cjs
if (oFolder)
{
oFolder.type(iType);
}
};
}
;
this.devEmail = '';
this.devPassword = '';
this.accountEmail = ko.observable('');
this.accountIncLogin = ko.observable('');
this.accountOutLogin = ko.observable('');
this.projectHash = ko.observable('');
this.threading = ko.observable(false);
this.lastFoldersHash = '';
this.remoteSuggestions = false;
// system folders
this.sentFolder = ko.observable('');
this.draftFolder = ko.observable('');
this.spamFolder = ko.observable('');
this.trashFolder = ko.observable('');
this.archiveFolder = ko.observable('');
this.sentFolder.subscribe(fRemoveSystemFolderType(this.sentFolder), this, 'beforeChange');
this.draftFolder.subscribe(fRemoveSystemFolderType(this.draftFolder), this, 'beforeChange');
this.spamFolder.subscribe(fRemoveSystemFolderType(this.spamFolder), this, 'beforeChange');
this.trashFolder.subscribe(fRemoveSystemFolderType(this.trashFolder), this, 'beforeChange');
this.archiveFolder.subscribe(fRemoveSystemFolderType(this.archiveFolder), this, 'beforeChange');
this.sentFolder.subscribe(fSetSystemFolderType(Enums.FolderType.SentItems), this);
this.draftFolder.subscribe(fSetSystemFolderType(Enums.FolderType.Draft), this);
this.spamFolder.subscribe(fSetSystemFolderType(Enums.FolderType.Spam), this);
this.trashFolder.subscribe(fSetSystemFolderType(Enums.FolderType.Trash), this);
this.archiveFolder.subscribe(fSetSystemFolderType(Enums.FolderType.Archive), this);
this.draftFolderNotEnabled = ko.computed(function () {
return '' === this.draftFolder() || Consts.Values.UnuseOptionValue === this.draftFolder();
}, this);
// personal
this.displayName = ko.observable('');
this.signature = ko.observable('');
this.signatureToAll = ko.observable(false);
this.replyTo = ko.observable('');
// security
this.enableTwoFactor = ko.observable(false);
// accounts
this.accounts = ko.observableArray([]);
this.accountsLoading = ko.observable(false).extend({'throttle': 100});
// identities
this.defaultIdentityID = ko.observable('');
this.identities = ko.observableArray([]);
this.identitiesLoading = ko.observable(false).extend({'throttle': 100});
// contacts
this.contactTags = ko.observableArray([]);
this.contacts = ko.observableArray([]);
this.contacts.loading = ko.observable(false).extend({'throttle': 200});
this.contacts.importing = ko.observable(false).extend({'throttle': 200});
this.contacts.syncing = ko.observable(false).extend({'throttle': 200});
this.contacts.exportingVcf = ko.observable(false).extend({'throttle': 200});
this.contacts.exportingCsv = ko.observable(false).extend({'throttle': 200});
this.allowContactsSync = ko.observable(false);
this.enableContactsSync = ko.observable(false);
this.contactsSyncUrl = ko.observable('');
this.contactsSyncUser = ko.observable('');
this.contactsSyncPass = ko.observable('');
this.allowContactsSync = ko.observable(!!RL.settingsGet('ContactsSyncIsAllowed')); // TODO cjs
this.enableContactsSync = ko.observable(!!RL.settingsGet('EnableContactsSync'));
this.contactsSyncUrl = ko.observable(RL.settingsGet('ContactsSyncUrl'));
this.contactsSyncUser = ko.observable(RL.settingsGet('ContactsSyncUser'));
this.contactsSyncPass = ko.observable(RL.settingsGet('ContactsSyncPassword'));
// folders
this.namespace = '';
this.folderList = ko.observableArray([]);
this.folderList.focused = ko.observable(false);
this.foldersListError = ko.observable('');
this.foldersLoading = ko.observable(false);
this.foldersCreating = ko.observable(false);
this.foldersDeleting = ko.observable(false);
this.foldersRenaming = ko.observable(false);
this.foldersChanging = ko.computed(function () {
var
bLoading = this.foldersLoading(),
bCreating = this.foldersCreating(),
bDeleting = this.foldersDeleting(),
bRenaming = this.foldersRenaming()
;
return bLoading || bCreating || bDeleting || bRenaming;
}, this);
this.foldersInboxUnreadCount = ko.observable(0);
this.currentFolder = ko.observable(null).extend({'toggleSubscribe': [null,
function (oPrev) {
if (oPrev)
{
oPrev.selected(false);
}
}, function (oNext) {
if (oNext)
{
oNext.selected(true);
}
}
]});
this.currentFolderFullNameRaw = ko.computed(function () {
return this.currentFolder() ? this.currentFolder().fullNameRaw : '';
}, this);
this.currentFolderFullName = ko.computed(function () {
return this.currentFolder() ? this.currentFolder().fullName : '';
}, this);
this.currentFolderFullNameHash = ko.computed(function () {
return this.currentFolder() ? this.currentFolder().fullNameHash : '';
}, this);
this.currentFolderName = ko.computed(function () {
return this.currentFolder() ? this.currentFolder().name() : '';
}, this);
this.folderListSystemNames = ko.computed(function () {
var
aList = ['INBOX'],
aFolders = this.folderList(),
sSentFolder = this.sentFolder(),
sDraftFolder = this.draftFolder(),
sSpamFolder = this.spamFolder(),
sTrashFolder = this.trashFolder(),
sArchiveFolder = this.archiveFolder()
;
if (Utils.isArray(aFolders) && 0 < aFolders.length)
{
if ('' !== sSentFolder && Consts.Values.UnuseOptionValue !== sSentFolder)
{
aList.push(sSentFolder);
}
if ('' !== sDraftFolder && Consts.Values.UnuseOptionValue !== sDraftFolder)
{
aList.push(sDraftFolder);
}
if ('' !== sSpamFolder && Consts.Values.UnuseOptionValue !== sSpamFolder)
{
aList.push(sSpamFolder);
}
if ('' !== sTrashFolder && Consts.Values.UnuseOptionValue !== sTrashFolder)
{
aList.push(sTrashFolder);
}
if ('' !== sArchiveFolder && Consts.Values.UnuseOptionValue !== sArchiveFolder)
{
aList.push(sArchiveFolder);
}
}
return aList;
}, this);
this.folderListSystem = ko.computed(function () {
return _.compact(_.map(this.folderListSystemNames(), function (sName) {
return Cache.getFolderFromCacheList(sName); // TODO cjs
}));
}, this);
this.folderMenuForMove = ko.computed(function () {
return RL.folderListOptionsBuilder(this.folderListSystem(), this.folderList(), [// TODO cjs
this.currentFolderFullNameRaw()
], null, null, null, null, function (oItem) {
return oItem ? oItem.localName() : '';
});
}, this);
// message list
this.staticMessageList = [];
this.messageList = ko.observableArray([]).extend({'rateLimit': 0});
this.messageListCount = ko.observable(0);
this.messageListSearch = ko.observable('');
this.messageListPage = ko.observable(1);
this.messageListThreadFolder = ko.observable('');
this.messageListThreadUids = ko.observableArray([]);
this.messageListThreadFolder.subscribe(function () {
this.messageListThreadUids([]);
}, this);
this.messageListEndFolder = ko.observable('');
this.messageListEndSearch = ko.observable('');
this.messageListEndPage = ko.observable(1);
this.messageListEndHash = ko.computed(function () {
return this.messageListEndFolder() + '|' + this.messageListEndSearch() + '|' + this.messageListEndPage();
}, this);
this.messageListPageCount = ko.computed(function () {
var iPage = window.Math.ceil(this.messageListCount() / this.messagesPerPage());
return 0 >= iPage ? 1 : iPage;
}, this);
this.mainMessageListSearch = ko.computed({
'read': this.messageListSearch,
'write': function (sValue) {
kn.setHash(LinkBuilder.mailBox( // TODO cjs
this.currentFolderFullNameHash(), 1, Utils.trim(sValue.toString())
));
},
'owner': this
});
this.messageListError = ko.observable('');
this.messageListLoading = ko.observable(false);
this.messageListIsNotCompleted = ko.observable(false);
this.messageListCompleteLoadingThrottle = ko.observable(false).extend({'throttle': 200});
this.messageListCompleteLoading = ko.computed(function () {
var
bOne = this.messageListLoading(),
bTwo = this.messageListIsNotCompleted()
;
return bOne || bTwo;
}, this);
this.messageListCompleteLoading.subscribe(function (bValue) {
this.messageListCompleteLoadingThrottle(bValue);
}, this);
this.messageList.subscribe(_.debounce(function (aList) {
_.each(aList, function (oItem) {
if (oItem.newForAnimation())
{
oItem.newForAnimation(false);
}
});
}, 500));
// message preview
this.staticMessageList = new MessageModel();// TODO cjs
this.message = ko.observable(null);
this.messageLoading = ko.observable(false);
this.messageLoadingThrottle = ko.observable(false).extend({'throttle': 50});
this.message.focused = ko.observable(false);
this.message.subscribe(function (oMessage) {
if (!oMessage)
{
this.message.focused(false);
this.messageFullScreenMode(false);
this.hideMessageBodies();
if (Enums.Layout.NoPreview === RL.data().layout() &&// TODO cjs
-1 < window.location.hash.indexOf('message-preview'))
{
RL.historyBack();// TODO cjs
}
}
else if (Enums.Layout.NoPreview === this.layout())
{
this.message.focused(true);
}
}, this);
this.message.focused.subscribe(function (bValue) {
if (bValue)
{
this.folderList.focused(false);
this.keyScope(Enums.KeyState.MessageView);
}
else if (Enums.KeyState.MessageView === RL.data().keyScope())// TODO cjs
{
if (Enums.Layout.NoPreview === RL.data().layout() && this.message())// TODO cjs
{
this.keyScope(Enums.KeyState.MessageView);
}
else
{
this.keyScope(Enums.KeyState.MessageList);
}
}
}, this);
this.folderList.focused.subscribe(function (bValue) {
if (bValue)
{
RL.data().keyScope(Enums.KeyState.FolderList);// TODO cjs
}
else if (Enums.KeyState.FolderList === RL.data().keyScope())// TODO cjs
{
RL.data().keyScope(Enums.KeyState.MessageList);// TODO cjs
}
});
this.messageLoading.subscribe(function (bValue) {
this.messageLoadingThrottle(bValue);
}, this);
this.messageFullScreenMode = ko.observable(false);
this.messageError = ko.observable('');
this.messagesBodiesDom = ko.observable(null);
this.messagesBodiesDom.subscribe(function (oDom) {
if (oDom && !(oDom instanceof $))
{
this.messagesBodiesDom($(oDom));
}
}, this);
this.messageActiveDom = ko.observable(null);
this.isMessageSelected = ko.computed(function () {
return null !== this.message();
}, this);
this.currentMessage = ko.observable(null);
this.messageListChecked = ko.computed(function () {
return _.filter(this.messageList(), function (oItem) {
return oItem.checked();
});
}, this).extend({'rateLimit': 0});
this.hasCheckedMessages = ko.computed(function () {
return 0 < this.messageListChecked().length;
}, this).extend({'rateLimit': 0});
this.messageListCheckedOrSelected = ko.computed(function () {
var
aChecked = this.messageListChecked(),
oSelectedMessage = this.currentMessage()
;
return _.union(aChecked, oSelectedMessage ? [oSelectedMessage] : []);
}, this);
this.messageListCheckedOrSelectedUidsWithSubMails = ko.computed(function () {
var aList = [];
_.each(this.messageListCheckedOrSelected(), function (oMessage) {
if (oMessage)
{
aList.push(oMessage.uid);
if (0 < oMessage.threadsLen() && 0 === oMessage.parentUid() && oMessage.lastInCollapsedThread())
{
aList = _.union(aList, oMessage.threads());
}
}
});
return aList;
}, this);
// quota
this.userQuota = ko.observable(0);
this.userUsageSize = ko.observable(0);
this.userUsageProc = ko.computed(function () {
var
iQuota = this.userQuota(),
iUsed = this.userUsageSize()
;
return 0 < iQuota ? window.Math.ceil((iUsed / iQuota) * 100) : 0;
}, this);
// other
this.capaOpenPGP = ko.observable(false);
this.openpgpkeys = ko.observableArray([]);
this.openpgpKeyring = null;
this.openpgpkeysPublic = this.openpgpkeys.filter(function (oItem) {
return !!(oItem && !oItem.isPrivate);
});
this.openpgpkeysPrivate = this.openpgpkeys.filter(function (oItem) {
return !!(oItem && oItem.isPrivate);
});
// google
this.googleActions = ko.observable(false);
this.googleLoggined = ko.observable(false);
this.googleUserName = ko.observable('');
// facebook
this.facebookActions = ko.observable(false);
this.facebookLoggined = ko.observable(false);
this.facebookUserName = ko.observable('');
// twitter
this.twitterActions = ko.observable(false);
this.twitterLoggined = ko.observable(false);
this.twitterUserName = ko.observable('');
this.customThemeType = ko.observable(Enums.CustomThemeType.Light);
this.purgeMessageBodyCacheThrottle = _.throttle(this.purgeMessageBodyCache, 1000 * 30);
}
_.extend(WebMailDataStorage.prototype, AbstractData.prototype);
WebMailDataStorage.prototype.purgeMessageBodyCache = function()
{
var
iCount = 0,
oMessagesBodiesDom = null,
iEnd = Globals.iMessageBodyCacheCount - Consts.Values.MessageBodyCacheLimit
;
if (0 < iEnd)
{
oMessagesBodiesDom = this.messagesBodiesDom();
if (oMessagesBodiesDom)
{
oMessagesBodiesDom.find('.rl-cache-class').each(function () {
var oItem = $(this);
if (iEnd > oItem.data('rl-cache-count'))
{
oItem.addClass('rl-cache-purge');
iCount++;
}
});
if (0 < iCount)
{
_.delay(function () {
oMessagesBodiesDom.find('.rl-cache-purge').remove();
}, 300);
}
}
}
};
WebMailDataStorage.prototype.populateDataOnStart = function()
{
AbstractData.prototype.populateDataOnStart.call(this);
this.accountEmail(RL.settingsGet('Email'));// TODO cjs
this.accountIncLogin(RL.settingsGet('IncLogin'));
this.accountOutLogin(RL.settingsGet('OutLogin'));
this.projectHash(RL.settingsGet('ProjectHash'));
this.defaultIdentityID(RL.settingsGet('DefaultIdentityID'));
this.displayName(RL.settingsGet('DisplayName'));
this.replyTo(RL.settingsGet('ReplyTo'));
this.signature(RL.settingsGet('Signature'));
this.signatureToAll(!!RL.settingsGet('SignatureToAll'));
this.enableTwoFactor(!!RL.settingsGet('EnableTwoFactor'));
this.lastFoldersHash = LocalStorage.get(Enums.ClientSideKeyName.FoldersLashHash) || '';
this.remoteSuggestions = !!RL.settingsGet('RemoteSuggestions');
this.devEmail = RL.settingsGet('DevEmail');
this.devPassword = RL.settingsGet('DevPassword');
};
WebMailDataStorage.prototype.initUidNextAndNewMessages = function (sFolder, sUidNext, aNewMessages)
{
if ('INBOX' === sFolder && Utils.isNormal(sUidNext) && sUidNext !== '')
{
if (Utils.isArray(aNewMessages) && 0 < aNewMessages.length)
{
var
iIndex = 0,
iLen = aNewMessages.length,
fNotificationHelper = function (sImageSrc, sTitle, sText)
{
var oNotification = null;
if (NotificationClass && RL.data().useDesktopNotifications())
{
oNotification = new NotificationClass(sTitle, {
'body': sText,
'icon': sImageSrc
});
if (oNotification)
{
if (oNotification.show)
{
oNotification.show();
}
window.setTimeout((function (oLocalNotifications) {
return function () {
if (oLocalNotifications.cancel)
{
oLocalNotifications.cancel();
}
else if (oLocalNotifications.close)
{
oLocalNotifications.close();
}
};
}(oNotification)), 7000);
}
}
}
;
_.each(aNewMessages, function (oItem) {
Cache.addNewMessageCache(sFolder, oItem.Uid);
});
if (3 < iLen)
{
fNotificationHelper(
LinkBuilder.notificationMailIcon(),
RL.data().accountEmail(),
Utils.i18n('MESSAGE_LIST/NEW_MESSAGE_NOTIFICATION', {
'COUNT': iLen
})
);
}
else
{
for (; iIndex < iLen; iIndex++)
{
fNotificationHelper(
LinkBuilder.notificationMailIcon(),
MessageModel.emailsToLine(MessageModel.initEmailsFromJson(aNewMessages[iIndex].From), false),
aNewMessages[iIndex].Subject
);
}
}
}
Cache.setFolderUidNext(sFolder, sUidNext);
}
};
/**
* @param {string} sNamespace
* @param {Array} aFolders
* @return {Array}
*/
WebMailDataStorage.prototype.folderResponseParseRec = function (sNamespace, aFolders)
{
var
iIndex = 0,
iLen = 0,
oFolder = null,
oCacheFolder = null,
sFolderFullNameRaw = '',
aSubFolders = [],
aList = []
;
for (iIndex = 0, iLen = aFolders.length; iIndex < iLen; iIndex++)
{
oFolder = aFolders[iIndex];
if (oFolder)
{
sFolderFullNameRaw = oFolder.FullNameRaw;
oCacheFolder = Cache.getFolderFromCacheList(sFolderFullNameRaw);// TODO cjs
if (!oCacheFolder)
{
oCacheFolder = FolderModel.newInstanceFromJson(oFolder);// TODO cjs
if (oCacheFolder)
{
Cache.setFolderToCacheList(sFolderFullNameRaw, oCacheFolder);// TODO cjs
Cache.setFolderFullNameRaw(oCacheFolder.fullNameHash, sFolderFullNameRaw);// TODO cjs
}
}
if (oCacheFolder)
{
oCacheFolder.collapsed(!Utils.isFolderExpanded(oCacheFolder.fullNameHash));
if (oFolder.Extended)
{
if (oFolder.Extended.Hash)
{
Cache.setFolderHash(oCacheFolder.fullNameRaw, oFolder.Extended.Hash);// TODO cjs
}
if (Utils.isNormal(oFolder.Extended.MessageCount))
{
oCacheFolder.messageCountAll(oFolder.Extended.MessageCount);
}
if (Utils.isNormal(oFolder.Extended.MessageUnseenCount))
{
oCacheFolder.messageCountUnread(oFolder.Extended.MessageUnseenCount);
}
}
aSubFolders = oFolder['SubFolders'];
if (aSubFolders && 'Collection/FolderCollection' === aSubFolders['@Object'] &&
aSubFolders['@Collection'] && Utils.isArray(aSubFolders['@Collection']))
{
oCacheFolder.subFolders(
this.folderResponseParseRec(sNamespace, aSubFolders['@Collection']));
}
aList.push(oCacheFolder);
}
}
}
return aList;
};
/**
* @param {*} oData
*/
WebMailDataStorage.prototype.setFolders = function (oData)
{
var
aList = [],
bUpdate = false,
oRLData = RL.data(),// TODO cjs
fNormalizeFolder = function (sFolderFullNameRaw) {
return ('' === sFolderFullNameRaw || Consts.Values.UnuseOptionValue === sFolderFullNameRaw ||
null !== Cache.getFolderFromCacheList(sFolderFullNameRaw)) ? sFolderFullNameRaw : '';// TODO cjs
}
;
if (oData && oData.Result && 'Collection/FolderCollection' === oData.Result['@Object'] &&
oData.Result['@Collection'] && Utils.isArray(oData.Result['@Collection']))
{
if (!Utils.isUnd(oData.Result.Namespace))
{
oRLData.namespace = oData.Result.Namespace;
}
this.threading(!!RL.settingsGet('UseImapThread') && oData.Result.IsThreadsSupported && true);// TODO cjs
aList = this.folderResponseParseRec(oRLData.namespace, oData.Result['@Collection']);
oRLData.folderList(aList);
// TODO cjs
if (oData.Result['SystemFolders'] &&
'' === '' + RL.settingsGet('SentFolder') + RL.settingsGet('DraftFolder') +
RL.settingsGet('SpamFolder') + RL.settingsGet('TrashFolder') + RL.settingsGet('ArchiveFolder') +
RL.settingsGet('NullFolder'))
{
// TODO Magic Numbers
RL.settingsSet('SentFolder', oData.Result['SystemFolders'][2] || null);
RL.settingsSet('DraftFolder', oData.Result['SystemFolders'][3] || null);
RL.settingsSet('SpamFolder', oData.Result['SystemFolders'][4] || null);
RL.settingsSet('TrashFolder', oData.Result['SystemFolders'][5] || null);
RL.settingsSet('ArchiveFolder', oData.Result['SystemFolders'][12] || null);
bUpdate = true;
}
// TODO cjs
oRLData.sentFolder(fNormalizeFolder(RL.settingsGet('SentFolder')));
oRLData.draftFolder(fNormalizeFolder(RL.settingsGet('DraftFolder')));
oRLData.spamFolder(fNormalizeFolder(RL.settingsGet('SpamFolder')));
oRLData.trashFolder(fNormalizeFolder(RL.settingsGet('TrashFolder')));
oRLData.archiveFolder(fNormalizeFolder(RL.settingsGet('ArchiveFolder')));
if (bUpdate)
{
Remote.saveSystemFolders(Utils.emptyFunction, {
'SentFolder': oRLData.sentFolder(),
'DraftFolder': oRLData.draftFolder(),
'SpamFolder': oRLData.spamFolder(),
'TrashFolder': oRLData.trashFolder(),
'ArchiveFolder': oRLData.archiveFolder(),
'NullFolder': 'NullFolder'
});
}
LocalStorage.set(Enums.ClientSideKeyName.FoldersLashHash, oData.Result.FoldersHash);
}
};
WebMailDataStorage.prototype.hideMessageBodies = function ()
{
var oMessagesBodiesDom = this.messagesBodiesDom();
if (oMessagesBodiesDom)
{
oMessagesBodiesDom.find('.b-text-part').hide();
}
};
/**
* @param {boolean=} bBoot = false
* @returns {Array}
*/
WebMailDataStorage.prototype.getNextFolderNames = function (bBoot)
{
bBoot = Utils.isUnd(bBoot) ? false : !!bBoot;
var
aResult = [],
iLimit = 10,
iUtc = moment().unix(),
iTimeout = iUtc - 60 * 5,
aTimeouts = [],
fSearchFunction = function (aList) {
_.each(aList, function (oFolder) {
if (oFolder && 'INBOX' !== oFolder.fullNameRaw &&
oFolder.selectable && oFolder.existen &&
iTimeout > oFolder.interval &&
(!bBoot || oFolder.subScribed()))
{
aTimeouts.push([oFolder.interval, oFolder.fullNameRaw]);
}
if (oFolder && 0 < oFolder.subFolders().length)
{
fSearchFunction(oFolder.subFolders());
}
});
}
;
fSearchFunction(this.folderList());
aTimeouts.sort(function(a, b) {
if (a[0] < b[0])
{
return -1;
}
else if (a[0] > b[0])
{
return 1;
}
return 0;
});
_.find(aTimeouts, function (aItem) {
var oFolder = Cache.getFolderFromCacheList(aItem[1]);// TODO cjs
if (oFolder)
{
oFolder.interval = iUtc;
aResult.push(aItem[1]);
}
return iLimit <= aResult.length;
});
return _.uniq(aResult);
};
/**
* @param {string} sFromFolderFullNameRaw
* @param {Array} aUidForRemove
* @param {string=} sToFolderFullNameRaw = ''
* @param {bCopy=} bCopy = false
*/
WebMailDataStorage.prototype.removeMessagesFromList = function (
sFromFolderFullNameRaw, aUidForRemove, sToFolderFullNameRaw, bCopy)
{
sToFolderFullNameRaw = Utils.isNormal(sToFolderFullNameRaw) ? sToFolderFullNameRaw : '';
bCopy = Utils.isUnd(bCopy) ? false : !!bCopy;
aUidForRemove = _.map(aUidForRemove, function (mValue) {
return Utils.pInt(mValue);
});
var
iUnseenCount = 0,
oData = RL.data(),// TODO cjs
aMessageList = oData.messageList(),
oFromFolder = Cache.getFolderFromCacheList(sFromFolderFullNameRaw),
oToFolder = '' === sToFolderFullNameRaw ? null : Cache.getFolderFromCacheList(sToFolderFullNameRaw || ''),
sCurrentFolderFullNameRaw = oData.currentFolderFullNameRaw(),
oCurrentMessage = oData.message(),
aMessages = sCurrentFolderFullNameRaw === sFromFolderFullNameRaw ? _.filter(aMessageList, function (oMessage) {
return oMessage && -1 < Utils.inArray(Utils.pInt(oMessage.uid), aUidForRemove);
}) : []
;
_.each(aMessages, function (oMessage) {
if (oMessage && oMessage.unseen())
{
iUnseenCount++;
}
});
if (oFromFolder && !bCopy)
{
oFromFolder.messageCountAll(0 <= oFromFolder.messageCountAll() - aUidForRemove.length ?
oFromFolder.messageCountAll() - aUidForRemove.length : 0);
if (0 < iUnseenCount)
{
oFromFolder.messageCountUnread(0 <= oFromFolder.messageCountUnread() - iUnseenCount ?
oFromFolder.messageCountUnread() - iUnseenCount : 0);
}
}
if (oToFolder)
{
oToFolder.messageCountAll(oToFolder.messageCountAll() + aUidForRemove.length);
if (0 < iUnseenCount)
{
oToFolder.messageCountUnread(oToFolder.messageCountUnread() + iUnseenCount);
}
oToFolder.actionBlink(true);
}
if (0 < aMessages.length)
{
if (bCopy)
{
_.each(aMessages, function (oMessage) {
oMessage.checked(false);
});
}
else
{
oData.messageListIsNotCompleted(true);
_.each(aMessages, function (oMessage) {
if (oCurrentMessage && oCurrentMessage.hash === oMessage.hash)
{
oCurrentMessage = null;
oData.message(null);
}
oMessage.deleted(true);
});
_.delay(function () {
_.each(aMessages, function (oMessage) {
oData.messageList.remove(oMessage);
});
}, 400);
}
}
if ('' !== sFromFolderFullNameRaw)
{
Cache.setFolderHash(sFromFolderFullNameRaw, '');
}
if ('' !== sToFolderFullNameRaw)
{
Cache.setFolderHash(sToFolderFullNameRaw, '');
}
};
WebMailDataStorage.prototype.setMessage = function (oData, bCached)
{
var
bIsHtml = false,
bHasExternals = false,
bHasInternals = false,
oBody = null,
oTextBody = null,
sId = '',
sResultHtml = '',
bPgpSigned = false,
bPgpEncrypted = false,
oMessagesBodiesDom = this.messagesBodiesDom(),
oMessage = this.message()
;
if (oData && oMessage && oData.Result && 'Object/Message' === oData.Result['@Object'] &&
oMessage.folderFullNameRaw === oData.Result.Folder && oMessage.uid === oData.Result.Uid)
{
this.messageError('');
oMessage.initUpdateByMessageJson(oData.Result);
Cache.addRequestedMessage(oMessage.folderFullNameRaw, oMessage.uid);// TODO cjs
if (!bCached)
{
oMessage.initFlagsByJson(oData.Result);
}
oMessagesBodiesDom = oMessagesBodiesDom && oMessagesBodiesDom[0] ? oMessagesBodiesDom : null;
if (oMessagesBodiesDom)
{
sId = 'rl-mgs-' + oMessage.hash.replace(/[^a-zA-Z0-9]/g, '');
oTextBody = oMessagesBodiesDom.find('#' + sId);
if (!oTextBody || !oTextBody[0])
{
bHasExternals = !!oData.Result.HasExternals;
bHasInternals = !!oData.Result.HasInternals;
oBody = $('').hide().addClass('rl-cache-class');
oBody.data('rl-cache-count', ++Globals.iMessageBodyCacheCount);
if (Utils.isNormal(oData.Result.Html) && '' !== oData.Result.Html)
{
bIsHtml = true;
sResultHtml = oData.Result.Html.toString();
}
else if (Utils.isNormal(oData.Result.Plain) && '' !== oData.Result.Plain)
{
bIsHtml = false;
sResultHtml = Utils.plainToHtml(oData.Result.Plain.toString(), false);
if ((oMessage.isPgpSigned() || oMessage.isPgpEncrypted()) && RL.data().capaOpenPGP())
{
oMessage.plainRaw = Utils.pString(oData.Result.Plain);
bPgpEncrypted = /---BEGIN PGP MESSAGE---/.test(oMessage.plainRaw);
if (!bPgpEncrypted)
{
bPgpSigned = /-----BEGIN PGP SIGNED MESSAGE-----/.test(oMessage.plainRaw) &&
/-----BEGIN PGP SIGNATURE-----/.test(oMessage.plainRaw);
}
$div.empty();
if (bPgpSigned && oMessage.isPgpSigned())
{
sResultHtml =
$div.append(
$('').text(oMessage.plainRaw)
).html()
;
}
else if (bPgpEncrypted && oMessage.isPgpEncrypted())
{
sResultHtml =
$div.append(
$('').text(oMessage.plainRaw)
).html()
;
}
$div.empty();
oMessage.isPgpSigned(bPgpSigned);
oMessage.isPgpEncrypted(bPgpEncrypted);
}
}
else
{
bIsHtml = false;
}
oBody
.html(Utils.linkify(sResultHtml))
.addClass('b-text-part ' + (bIsHtml ? 'html' : 'plain'))
;
oMessage.isHtml(!!bIsHtml);
oMessage.hasImages(!!bHasExternals);
oMessage.pgpSignedVerifyStatus(Enums.SignedVerifyStatus.None);
oMessage.pgpSignedVerifyUser('');
oMessage.body = oBody;
if (oMessage.body)
{
oMessagesBodiesDom.append(oMessage.body);
}
oMessage.storeDataToDom();
if (bHasInternals)
{
oMessage.showInternalImages(true);
}
if (oMessage.hasImages() && this.showImages())
{
oMessage.showExternalImages(true);
}
this.purgeMessageBodyCacheThrottle();
}
else
{
oMessage.body = oTextBody;
if (oMessage.body)
{
oMessage.body.data('rl-cache-count', ++Globals.iMessageBodyCacheCount);
oMessage.fetchDataToDom();
}
}
this.messageActiveDom(oMessage.body);
this.hideMessageBodies();
oMessage.body.show();
if (oBody)
{
Utils.initBlockquoteSwitcher(oBody);
}
}
Cache.initMessageFlagsFromCache(oMessage);
if (oMessage.unseen())
{
RL.setMessageSeen(oMessage);
}
Utils.windowResize();
}
};
/**
* @param {Array} aList
* @returns {string}
*/
WebMailDataStorage.prototype.calculateMessageListHash = function (aList)
{
return _.map(aList, function (oMessage) {
return '' + oMessage.hash + '_' + oMessage.threadsLen() + '_' + oMessage.flagHash();
}).join('|');
};
WebMailDataStorage.prototype.setMessageList = function (oData, bCached)
{
if (oData && oData.Result && 'Collection/MessageCollection' === oData.Result['@Object'] &&
oData.Result['@Collection'] && Utils.isArray(oData.Result['@Collection']))
{
var
oRainLoopData = RL.data(),
mLastCollapsedThreadUids = null,
iIndex = 0,
iLen = 0,
iCount = 0,
iOffset = 0,
aList = [],
iUtc = moment().unix(),
aStaticList = oRainLoopData.staticMessageList,
oJsonMessage = null,
oMessage = null,
oFolder = null,
iNewCount = 0,
bUnreadCountChange = false
;
iCount = Utils.pInt(oData.Result.MessageResultCount);
iOffset = Utils.pInt(oData.Result.Offset);
if (Utils.isNonEmptyArray(oData.Result.LastCollapsedThreadUids))
{
mLastCollapsedThreadUids = oData.Result.LastCollapsedThreadUids;
}
oFolder = Cache.getFolderFromCacheList(
Utils.isNormal(oData.Result.Folder) ? oData.Result.Folder : '');
if (oFolder && !bCached)
{
oFolder.interval = iUtc;
Cache.setFolderHash(oData.Result.Folder, oData.Result.FolderHash);
if (Utils.isNormal(oData.Result.MessageCount))
{
oFolder.messageCountAll(oData.Result.MessageCount);
}
if (Utils.isNormal(oData.Result.MessageUnseenCount))
{
if (Utils.pInt(oFolder.messageCountUnread()) !== Utils.pInt(oData.Result.MessageUnseenCount))
{
bUnreadCountChange = true;
}
oFolder.messageCountUnread(oData.Result.MessageUnseenCount);
}
this.initUidNextAndNewMessages(oFolder.fullNameRaw, oData.Result.UidNext, oData.Result.NewMessages);
}
if (bUnreadCountChange && oFolder)
{
Cache.clearMessageFlagsFromCacheByFolder(oFolder.fullNameRaw);
}
for (iIndex = 0, iLen = oData.Result['@Collection'].length; iIndex < iLen; iIndex++)
{
oJsonMessage = oData.Result['@Collection'][iIndex];
if (oJsonMessage && 'Object/Message' === oJsonMessage['@Object'])
{
oMessage = aStaticList[iIndex];
if (!oMessage || !oMessage.initByJson(oJsonMessage))
{
oMessage = MessageModel.newInstanceFromJson(oJsonMessage);
}
if (oMessage)
{
if (Cache.hasNewMessageAndRemoveFromCache(oMessage.folderFullNameRaw, oMessage.uid) && 5 >= iNewCount)
{
iNewCount++;
oMessage.newForAnimation(true);
}
oMessage.deleted(false);
if (bCached)
{
Cache.initMessageFlagsFromCache(oMessage);
}
else
{
Cache.storeMessageFlagsToCache(oMessage);
}
oMessage.lastInCollapsedThread(mLastCollapsedThreadUids && -1 < Utils.inArray(Utils.pInt(oMessage.uid), mLastCollapsedThreadUids) ? true : false);
aList.push(oMessage);
}
}
}
oRainLoopData.messageListCount(iCount);
oRainLoopData.messageListSearch(Utils.isNormal(oData.Result.Search) ? oData.Result.Search : '');
oRainLoopData.messageListPage(Math.ceil((iOffset / oRainLoopData.messagesPerPage()) + 1));
oRainLoopData.messageListEndFolder(Utils.isNormal(oData.Result.Folder) ? oData.Result.Folder : '');
oRainLoopData.messageListEndSearch(Utils.isNormal(oData.Result.Search) ? oData.Result.Search : '');
oRainLoopData.messageListEndPage(oRainLoopData.messageListPage());
oRainLoopData.messageList(aList);
oRainLoopData.messageListIsNotCompleted(false);
if (aStaticList.length < aList.length)
{
oRainLoopData.staticMessageList = aList;
}
Cache.clearNewMessageCache();
if (oFolder && (bCached || bUnreadCountChange || RL.data().useThreads()))
{
RL.folderInformation(oFolder.fullNameRaw, aList);
}
}
else
{
RL.data().messageListCount(0);
RL.data().messageList([]);
RL.data().messageListError(Utils.getNotification(
oData && oData.ErrorCode ? oData.ErrorCode : Enums.Notification.CantGetMessageList
));
}
};
WebMailDataStorage.prototype.findPublicKeyByHex = function (sHash)
{
return _.find(this.openpgpkeysPublic(), function (oItem) {
return oItem && sHash === oItem.id;
});
};
WebMailDataStorage.prototype.findPublicKeysByEmail = function (sEmail)
{
return _.compact(_.map(this.openpgpkeysPublic(), function (oItem) {
var oKey = null;
if (oItem && sEmail === oItem.email)
{
try
{
oKey = window.openpgp.key.readArmored(oItem.armor);
if (oKey && !oKey.err && oKey.keys && oKey.keys[0])
{
return oKey.keys[0];
}
}
catch (e) {}
}
return null;
}));
};
/**
* @param {string} sEmail
* @param {string=} sPassword
* @returns {?}
*/
WebMailDataStorage.prototype.findPrivateKeyByEmail = function (sEmail, sPassword)
{
var
oPrivateKey = null,
oKey = _.find(this.openpgpkeysPrivate(), function (oItem) {
return oItem && sEmail === oItem.email;
})
;
if (oKey)
{
try
{
oPrivateKey = window.openpgp.key.readArmored(oKey.armor);
if (oPrivateKey && !oPrivateKey.err && oPrivateKey.keys && oPrivateKey.keys[0])
{
oPrivateKey = oPrivateKey.keys[0];
oPrivateKey.decrypt(Utils.pString(sPassword));
}
else
{
oPrivateKey = null;
}
}
catch (e)
{
oPrivateKey = null;
}
}
return oPrivateKey;
};
/**
* @param {string=} sPassword
* @returns {?}
*/
WebMailDataStorage.prototype.findSelfPrivateKey = function (sPassword)
{
return this.findPrivateKeyByEmail(this.accountEmail(), sPassword);
};
module.exports = new WebMailDataStorage();
}(module));
},{"../Common/Consts.js":4,"../Common/Enums.js":5,"../Common/Globals.js":6,"../Common/LinkBuilder.js":7,"../Common/Utils.js":9,"../External/$div.js":10,"../External/NotificationClass.js":16,"../External/jquery.js":19,"../External/ko.js":21,"../External/moment.js":22,"../External/underscore.js":24,"../External/window.js":25,"../Knoin/Knoin.js":26,"../Models/MessageModel.js":31,"../Storages/WebMailAjaxRemoteStorage.js":39,"../Storages/WebMailCacheStorage.js":40,"./AbstractData.js":35,"./LocalStorage.js":36}],42:[function(require,module,exports){
/* 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));
},{"../../Common/Enums.js":5,"../../Common/Utils.js":9,"../../External/key.js":20,"../../External/ko.js":21,"../../Knoin/Knoin.js":26,"../../Knoin/KnoinAbstractViewModel.js":28}]},{},[1]);