mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-04 06:57:03 +03:00
Code refactoring (v2)
This commit is contained in:
parent
90d95d3ca4
commit
80ab02363e
29 changed files with 858 additions and 857 deletions
|
|
@ -2,36 +2,23 @@
|
|||
import window from 'window';
|
||||
import progressJs from 'progressJs';
|
||||
|
||||
import RainLoopStorage from 'Storage/RainLoop';
|
||||
import STYLES_CSS from 'Styles/@Boot.css';
|
||||
import LAYOUT_HTML from 'Html/Layout.html';
|
||||
|
||||
let rlAppDataStorage = null;
|
||||
import {getHash, setHash, clearHash} from 'Storage/RainLoop';
|
||||
|
||||
window.__rlah = () => {
|
||||
return RainLoopStorage ? RainLoopStorage.getHash() : null;
|
||||
};
|
||||
let RL_APP_DATA_STORAGE = null;
|
||||
|
||||
window.__rlah_data = () => {
|
||||
return rlAppDataStorage;
|
||||
};
|
||||
|
||||
window.__rlah_set = () => {
|
||||
if (RainLoopStorage)
|
||||
{
|
||||
RainLoopStorage.setHash();
|
||||
}
|
||||
};
|
||||
|
||||
window.__rlah_clear = () => {
|
||||
if (RainLoopStorage)
|
||||
{
|
||||
RainLoopStorage.clearHash();
|
||||
}
|
||||
};
|
||||
window.__rlah = () => getHash();
|
||||
window.__rlah_set = () => setHash();
|
||||
window.__rlah_clear = () => clearHash();
|
||||
window.__rlah_data = () => RL_APP_DATA_STORAGE;
|
||||
|
||||
function getComputedStyle(id, name)
|
||||
{
|
||||
var element = window.document.getElementById(id);
|
||||
return element.currentStyle ? element.currentStyle[name] : (window.getComputedStyle ? window.getComputedStyle(element, null).getPropertyValue(name) : null);
|
||||
return element.currentStyle ? element.currentStyle[name] :
|
||||
(window.getComputedStyle ? window.getComputedStyle(element, null).getPropertyValue(name) : null);
|
||||
}
|
||||
|
||||
function includeStyle(styles)
|
||||
|
|
@ -46,20 +33,16 @@ function includeScr(src)
|
|||
|
||||
function includeLayout()
|
||||
{
|
||||
const
|
||||
css = require('Styles/@Boot.css'),
|
||||
layout = require('Html/Layout.html'),
|
||||
app = window.document.getElementById('rl-app')
|
||||
;
|
||||
const app = window.document.getElementById('rl-app');
|
||||
|
||||
if (css)
|
||||
if (STYLES_CSS)
|
||||
{
|
||||
includeStyle(css);
|
||||
includeStyle(STYLES_CSS);
|
||||
}
|
||||
|
||||
if (app && layout)
|
||||
if (app && LAYOUT_HTML)
|
||||
{
|
||||
app.innerHTML = layout.replace(/[\r\n\t]+/g, '');
|
||||
app.innerHTML = LAYOUT_HTML.replace(/[\r\n\t]+/g, '');
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -221,21 +204,24 @@ function runApp()
|
|||
|
||||
window.__initAppData = function(data) {
|
||||
|
||||
rlAppDataStorage = data;
|
||||
RL_APP_DATA_STORAGE = data;
|
||||
|
||||
window.__rlah_set();
|
||||
|
||||
if (rlAppDataStorage.NewThemeLink)
|
||||
if (RL_APP_DATA_STORAGE)
|
||||
{
|
||||
(window.document.getElementById('app-theme-link') || {}).href = rlAppDataStorage.NewThemeLink;
|
||||
}
|
||||
if (RL_APP_DATA_STORAGE.NewThemeLink)
|
||||
{
|
||||
(window.document.getElementById('app-theme-link') || {}).href = RL_APP_DATA_STORAGE.NewThemeLink;
|
||||
}
|
||||
|
||||
if (rlAppDataStorage.IncludeCss)
|
||||
{
|
||||
includeStyle(rlAppDataStorage.IncludeCss);
|
||||
}
|
||||
if (RL_APP_DATA_STORAGE.IncludeCss)
|
||||
{
|
||||
includeStyle(RL_APP_DATA_STORAGE.IncludeCss);
|
||||
}
|
||||
|
||||
showDescriptionAndLoading(rlAppDataStorage ? (rlAppDataStorage.LoadingDescriptionEsc || '') : '');
|
||||
showDescriptionAndLoading(RL_APP_DATA_STORAGE.LoadingDescriptionEsc || '');
|
||||
}
|
||||
|
||||
runApp();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -5,324 +5,339 @@ import {trim, pInt, isArray} from 'Common/Utils';
|
|||
import * as Links from 'Common/Links';
|
||||
import * as Settings from 'Storage/Settings';
|
||||
|
||||
class CacheUserStorage
|
||||
let FOLDERS_CACHE = {};
|
||||
let FOLDERS_NAME_CACHE = {};
|
||||
let FOLDERS_HASH_CACHE = {};
|
||||
let FOLDERS_UID_NEXT_CACHE = {};
|
||||
let MESSAGE_FLAGS_CACHE = {};
|
||||
|
||||
let NEW_MESSAGE_CACHE = {};
|
||||
let REQUESTED_MESSAGE_CACHE = {};
|
||||
|
||||
const capaGravatar = Settings.capa(Capa.Gravatar);
|
||||
let inboxFolderName = '';
|
||||
|
||||
export function clear()
|
||||
{
|
||||
oFoldersCache = {};
|
||||
oFoldersNamesCache = {};
|
||||
oFolderHashCache = {};
|
||||
oFolderUidNextCache = {};
|
||||
oMessageListHashCache = {};
|
||||
oMessageFlagsCache = {};
|
||||
oNewMessage = {};
|
||||
oRequestedMessage = {};
|
||||
bCapaGravatar = false;
|
||||
inboxFolderName = '';
|
||||
FOLDERS_CACHE = {};
|
||||
FOLDERS_NAME_CACHE = {};
|
||||
FOLDERS_HASH_CACHE = {};
|
||||
FOLDERS_UID_NEXT_CACHE = {};
|
||||
MESSAGE_FLAGS_CACHE = {};
|
||||
}
|
||||
|
||||
constructor()
|
||||
/**
|
||||
* @param {string} email
|
||||
* @param {Function} callback
|
||||
* @return {string}
|
||||
*/
|
||||
export function getUserPic(email, callback)
|
||||
{
|
||||
email = trim(email);
|
||||
callback(capaGravatar && '' !== email ? Links.avatarLink(email) : '', email);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folderFullNameRaw
|
||||
* @param {string} uid
|
||||
* @return {string}
|
||||
*/
|
||||
export function getMessageKey(folderFullNameRaw, uid)
|
||||
{
|
||||
return `${folderFullNameRaw}#${uid}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folder
|
||||
* @param {string} uid
|
||||
*/
|
||||
export function addRequestedMessage(folder, uid)
|
||||
{
|
||||
REQUESTED_MESSAGE_CACHE[getMessageKey(folder, uid)] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folder
|
||||
* @param {string} uid
|
||||
* @return {boolean}
|
||||
*/
|
||||
export function hasRequestedMessage(folder, uid)
|
||||
{
|
||||
return true === REQUESTED_MESSAGE_CACHE[getMessageKey(folder, uid)];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folderFullNameRaw
|
||||
* @param {string} uid
|
||||
*/
|
||||
export function addNewMessageCache(folderFullNameRaw, uid)
|
||||
{
|
||||
NEW_MESSAGE_CACHE[getMessageKey(folderFullNameRaw, uid)] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folderFullNameRaw
|
||||
* @param {string} uid
|
||||
*/
|
||||
export function hasNewMessageAndRemoveFromCache(folderFullNameRaw, uid)
|
||||
{
|
||||
if (NEW_MESSAGE_CACHE[getMessageKey(folderFullNameRaw, uid)])
|
||||
{
|
||||
this.bCapaGravatar = Settings.capa(Capa.Gravatar);
|
||||
NEW_MESSAGE_CACHE[getMessageKey(folderFullNameRaw, uid)] = null;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.oFoldersCache = {};
|
||||
this.oFoldersNamesCache = {};
|
||||
this.oFolderHashCache = {};
|
||||
this.oFolderUidNextCache = {};
|
||||
this.oMessageListHashCache = {};
|
||||
this.oMessageFlagsCache = {};
|
||||
}
|
||||
export function clearNewMessageCache()
|
||||
{
|
||||
NEW_MESSAGE_CACHE = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} email
|
||||
* @param {Function} callback
|
||||
* @return {string}
|
||||
*/
|
||||
getUserPic(email, callback) {
|
||||
email = trim(email);
|
||||
callback(this.bCapaGravatar && '' !== email ? Links.avatarLink(email) : '', email);
|
||||
}
|
||||
/**
|
||||
* @return {string}
|
||||
*/
|
||||
export function getFolderInboxName()
|
||||
{
|
||||
return '' === inboxFolderName ? 'INBOX' : inboxFolderName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folderFullNameRaw
|
||||
* @param {string} uid
|
||||
* @return {string}
|
||||
*/
|
||||
getMessageKey(folderFullNameRaw, uid) {
|
||||
return `${folderFullNameRaw}#${uid}`;
|
||||
}
|
||||
/**
|
||||
* @param {string} folderHash
|
||||
* @return {string}
|
||||
*/
|
||||
export function getFolderFullNameRaw(folderHash)
|
||||
{
|
||||
return '' !== folderHash && FOLDERS_NAME_CACHE[folderHash] ? FOLDERS_NAME_CACHE[folderHash] : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folder
|
||||
* @param {string} uid
|
||||
*/
|
||||
addRequestedMessage(folder, uid) {
|
||||
this.oRequestedMessage[this.getMessageKey(folder, uid)] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folder
|
||||
* @param {string} uid
|
||||
* @return {boolean}
|
||||
*/
|
||||
hasRequestedMessage(folder, uid) {
|
||||
return true === this.oRequestedMessage[this.getMessageKey(folder, uid)];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folderFullNameRaw
|
||||
* @param {string} uid
|
||||
*/
|
||||
addNewMessageCache(folderFullNameRaw, uid) {
|
||||
this.oNewMessage[this.getMessageKey(folderFullNameRaw, uid)] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folderFullNameRaw
|
||||
* @param {string} uid
|
||||
*/
|
||||
hasNewMessageAndRemoveFromCache(folderFullNameRaw, uid) {
|
||||
if (this.oNewMessage[this.getMessageKey(folderFullNameRaw, uid)])
|
||||
{
|
||||
this.oNewMessage[this.getMessageKey(folderFullNameRaw, uid)] = null;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
clearNewMessageCache() {
|
||||
this.oNewMessage = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {string}
|
||||
*/
|
||||
getFolderInboxName() {
|
||||
return '' === this.inboxFolderName ? 'INBOX' : this.inboxFolderName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folderHash
|
||||
* @return {string}
|
||||
*/
|
||||
getFolderFullNameRaw(folderHash) {
|
||||
return '' !== folderHash && this.oFoldersNamesCache[folderHash] ? this.oFoldersNamesCache[folderHash] : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folderHash
|
||||
* @param {string} folderFullNameRaw
|
||||
*/
|
||||
setFolderFullNameRaw(folderHash, folderFullNameRaw) {
|
||||
this.oFoldersNamesCache[folderHash] = folderFullNameRaw;
|
||||
if ('INBOX' === folderFullNameRaw || '' === this.inboxFolderName)
|
||||
{
|
||||
this.inboxFolderName = folderFullNameRaw;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folderFullNameRaw
|
||||
* @return {string}
|
||||
*/
|
||||
getFolderHash(folderFullNameRaw) {
|
||||
return '' !== folderFullNameRaw && this.oFolderHashCache[folderFullNameRaw] ? this.oFolderHashCache[folderFullNameRaw] : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folderFullNameRaw
|
||||
* @param {string} folderHash
|
||||
*/
|
||||
setFolderHash(folderFullNameRaw, folderHash) {
|
||||
if ('' !== folderFullNameRaw)
|
||||
{
|
||||
this.oFolderHashCache[folderFullNameRaw] = folderHash;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folderFullNameRaw
|
||||
* @return {string}
|
||||
*/
|
||||
getFolderUidNext(folderFullNameRaw) {
|
||||
return '' !== folderFullNameRaw && this.oFolderUidNextCache[folderFullNameRaw] ? this.oFolderUidNextCache[folderFullNameRaw] : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folderFullNameRaw
|
||||
* @param {string} uidNext
|
||||
*/
|
||||
setFolderUidNext(folderFullNameRaw, uidNext) {
|
||||
this.oFolderUidNextCache[folderFullNameRaw] = uidNext;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folderFullNameRaw
|
||||
* @return {?FolderModel}
|
||||
*/
|
||||
getFolderFromCacheList(folderFullNameRaw) {
|
||||
return '' !== folderFullNameRaw && this.oFoldersCache[folderFullNameRaw] ? this.oFoldersCache[folderFullNameRaw] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folderFullNameRaw
|
||||
* @param {?FolderModel} folder
|
||||
*/
|
||||
setFolderToCacheList(folderFullNameRaw, folder) {
|
||||
this.oFoldersCache[folderFullNameRaw] = folder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folderFullNameRaw
|
||||
*/
|
||||
removeFolderFromCacheList(folderFullNameRaw) {
|
||||
this.setFolderToCacheList(folderFullNameRaw, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folderFullName
|
||||
* @param {string} uid
|
||||
* @return {?Array}
|
||||
*/
|
||||
getMessageFlagsFromCache(folderFullName, uid) {
|
||||
return this.oMessageFlagsCache[folderFullName] && this.oMessageFlagsCache[folderFullName][uid] ?
|
||||
this.oMessageFlagsCache[folderFullName][uid] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folderFullName
|
||||
* @param {string} uid
|
||||
* @param {Array} flagsCache
|
||||
*/
|
||||
setMessageFlagsToCache(folderFullName, uid, flagsCache) {
|
||||
if (!this.oMessageFlagsCache[folderFullName])
|
||||
{
|
||||
this.oMessageFlagsCache[folderFullName] = {};
|
||||
}
|
||||
|
||||
this.oMessageFlagsCache[folderFullName][uid] = flagsCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folderFullName
|
||||
*/
|
||||
clearMessageFlagsFromCacheByFolder(folderFullName) {
|
||||
this.oMessageFlagsCache[folderFullName] = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {(MessageModel|null)} message
|
||||
*/
|
||||
initMessageFlagsFromCache(message) {
|
||||
|
||||
if (message)
|
||||
{
|
||||
const
|
||||
uid = message.uid,
|
||||
flags = this.getMessageFlagsFromCache(message.folderFullNameRaw, uid)
|
||||
;
|
||||
|
||||
if (flags && 0 < flags.length)
|
||||
{
|
||||
message.flagged(!!flags[1]);
|
||||
|
||||
if (!message.__simple_message__)
|
||||
{
|
||||
message.unseen(!!flags[0]);
|
||||
message.answered(!!flags[2]);
|
||||
message.forwarded(!!flags[3]);
|
||||
message.isReadReceipt(!!flags[4]);
|
||||
message.deletedMark(!!flags[5]);
|
||||
}
|
||||
}
|
||||
|
||||
if (0 < message.threads().length)
|
||||
{
|
||||
const unseenSubUid = _.find(message.threads(), (sSubUid) => {
|
||||
if (uid !== sSubUid) {
|
||||
const subFlags = this.getMessageFlagsFromCache(message.folderFullNameRaw, sSubUid);
|
||||
return subFlags && 0 < subFlags.length && !!subFlags[0];
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
const flaggedSubUid = _.find(message.threads(), (sSubUid) => {
|
||||
if (uid !== sSubUid) {
|
||||
const subFlags = this.getMessageFlagsFromCache(message.folderFullNameRaw, sSubUid);
|
||||
return subFlags && 0 < subFlags.length && !!subFlags[1];
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
message.hasUnseenSubMessage(unseenSubUid && 0 < pInt(unseenSubUid));
|
||||
message.hasFlaggedSubMessage(flaggedSubUid && 0 < pInt(flaggedSubUid));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {(MessageModel|null)} message
|
||||
*/
|
||||
storeMessageFlagsToCache(message) {
|
||||
if (message)
|
||||
{
|
||||
this.setMessageFlagsToCache(
|
||||
message.folderFullNameRaw, message.uid,
|
||||
[message.unseen(), message.flagged(), message.answered(), message.forwarded(),
|
||||
message.isReadReceipt(), message.deletedMark()]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folder
|
||||
* @param {string} uid
|
||||
* @param {Array} flags
|
||||
*/
|
||||
storeMessageFlagsToCacheByFolderAndUid(folder, uid, flags) {
|
||||
if (isArray(flags) && 0 < flags.length)
|
||||
{
|
||||
this.setMessageFlagsToCache(folder, uid, flags);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folder
|
||||
* @param {string} uid
|
||||
* @param {number} setAction
|
||||
*/
|
||||
storeMessageFlagsToCacheBySetAction(folder, uid, setAction) {
|
||||
|
||||
let unread = 0;
|
||||
const flags = this.getMessageFlagsFromCache(folder, uid);
|
||||
|
||||
if (isArray(flags) && 0 < flags.length)
|
||||
{
|
||||
if (flags[0])
|
||||
{
|
||||
unread = 1;
|
||||
}
|
||||
|
||||
switch (setAction)
|
||||
{
|
||||
case MessageSetAction.SetSeen:
|
||||
flags[0] = false;
|
||||
break;
|
||||
case MessageSetAction.UnsetSeen:
|
||||
flags[0] = true;
|
||||
break;
|
||||
case MessageSetAction.SetFlag:
|
||||
flags[1] = true;
|
||||
break;
|
||||
case MessageSetAction.UnsetFlag:
|
||||
flags[1] = false;
|
||||
break;
|
||||
}
|
||||
|
||||
this.setMessageFlagsToCache(folder, uid, flags);
|
||||
}
|
||||
|
||||
return unread;
|
||||
/**
|
||||
* @param {string} folderHash
|
||||
* @param {string} folderFullNameRaw
|
||||
*/
|
||||
export function setFolderFullNameRaw(folderHash, folderFullNameRaw)
|
||||
{
|
||||
FOLDERS_NAME_CACHE[folderHash] = folderFullNameRaw;
|
||||
if ('INBOX' === folderFullNameRaw || '' === inboxFolderName)
|
||||
{
|
||||
inboxFolderName = folderFullNameRaw;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new CacheUserStorage();
|
||||
/**
|
||||
* @param {string} folderFullNameRaw
|
||||
* @return {string}
|
||||
*/
|
||||
export function getFolderHash(folderFullNameRaw)
|
||||
{
|
||||
return '' !== folderFullNameRaw && FOLDERS_HASH_CACHE[folderFullNameRaw] ? FOLDERS_HASH_CACHE[folderFullNameRaw] : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folderFullNameRaw
|
||||
* @param {string} folderHash
|
||||
*/
|
||||
export function setFolderHash(folderFullNameRaw, folderHash)
|
||||
{
|
||||
if ('' !== folderFullNameRaw)
|
||||
{
|
||||
FOLDERS_HASH_CACHE[folderFullNameRaw] = folderHash;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folderFullNameRaw
|
||||
* @return {string}
|
||||
*/
|
||||
export function getFolderUidNext(folderFullNameRaw)
|
||||
{
|
||||
return '' !== folderFullNameRaw && FOLDERS_UID_NEXT_CACHE[folderFullNameRaw] ? FOLDERS_UID_NEXT_CACHE[folderFullNameRaw] : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folderFullNameRaw
|
||||
* @param {string} uidNext
|
||||
*/
|
||||
export function setFolderUidNext(folderFullNameRaw, uidNext)
|
||||
{
|
||||
FOLDERS_UID_NEXT_CACHE[folderFullNameRaw] = uidNext;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folderFullNameRaw
|
||||
* @return {?FolderModel}
|
||||
*/
|
||||
export function getFolderFromCacheList(folderFullNameRaw)
|
||||
{
|
||||
return '' !== folderFullNameRaw && FOLDERS_CACHE[folderFullNameRaw] ? FOLDERS_CACHE[folderFullNameRaw] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folderFullNameRaw
|
||||
* @param {?FolderModel} folder
|
||||
*/
|
||||
export function setFolderToCacheList(folderFullNameRaw, folder)
|
||||
{
|
||||
FOLDERS_CACHE[folderFullNameRaw] = folder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folderFullNameRaw
|
||||
*/
|
||||
export function removeFolderFromCacheList(folderFullNameRaw)
|
||||
{
|
||||
setFolderToCacheList(folderFullNameRaw, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folderFullName
|
||||
* @param {string} uid
|
||||
* @return {?Array}
|
||||
*/
|
||||
export function getMessageFlagsFromCache(folderFullName, uid)
|
||||
{
|
||||
return MESSAGE_FLAGS_CACHE[folderFullName] && MESSAGE_FLAGS_CACHE[folderFullName][uid] ?
|
||||
MESSAGE_FLAGS_CACHE[folderFullName][uid] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folderFullName
|
||||
* @param {string} uid
|
||||
* @param {Array} flagsCache
|
||||
*/
|
||||
export function setMessageFlagsToCache(folderFullName, uid, flagsCache)
|
||||
{
|
||||
if (!MESSAGE_FLAGS_CACHE[folderFullName])
|
||||
{
|
||||
MESSAGE_FLAGS_CACHE[folderFullName] = {};
|
||||
}
|
||||
|
||||
MESSAGE_FLAGS_CACHE[folderFullName][uid] = flagsCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folderFullName
|
||||
*/
|
||||
export function clearMessageFlagsFromCacheByFolder(folderFullName)
|
||||
{
|
||||
MESSAGE_FLAGS_CACHE[folderFullName] = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {(MessageModel|null)} message
|
||||
*/
|
||||
export function initMessageFlagsFromCache(message)
|
||||
{
|
||||
|
||||
if (message)
|
||||
{
|
||||
const
|
||||
uid = message.uid,
|
||||
flags = getMessageFlagsFromCache(message.folderFullNameRaw, uid)
|
||||
;
|
||||
|
||||
if (flags && 0 < flags.length)
|
||||
{
|
||||
message.flagged(!!flags[1]);
|
||||
|
||||
if (!message.__simple_message__)
|
||||
{
|
||||
message.unseen(!!flags[0]);
|
||||
message.answered(!!flags[2]);
|
||||
message.forwarded(!!flags[3]);
|
||||
message.isReadReceipt(!!flags[4]);
|
||||
message.deletedMark(!!flags[5]);
|
||||
}
|
||||
}
|
||||
|
||||
if (0 < message.threads().length)
|
||||
{
|
||||
const unseenSubUid = _.find(message.threads(), (sSubUid) => {
|
||||
if (uid !== sSubUid) {
|
||||
const subFlags = getMessageFlagsFromCache(message.folderFullNameRaw, sSubUid);
|
||||
return subFlags && 0 < subFlags.length && !!subFlags[0];
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
const flaggedSubUid = _.find(message.threads(), (sSubUid) => {
|
||||
if (uid !== sSubUid) {
|
||||
const subFlags = getMessageFlagsFromCache(message.folderFullNameRaw, sSubUid);
|
||||
return subFlags && 0 < subFlags.length && !!subFlags[1];
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
message.hasUnseenSubMessage(unseenSubUid && 0 < pInt(unseenSubUid));
|
||||
message.hasFlaggedSubMessage(flaggedSubUid && 0 < pInt(flaggedSubUid));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {(MessageModel|null)} message
|
||||
*/
|
||||
export function storeMessageFlagsToCache(message)
|
||||
{
|
||||
if (message)
|
||||
{
|
||||
setMessageFlagsToCache(
|
||||
message.folderFullNameRaw, message.uid,
|
||||
[message.unseen(), message.flagged(), message.answered(), message.forwarded(),
|
||||
message.isReadReceipt(), message.deletedMark()]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folder
|
||||
* @param {string} uid
|
||||
* @param {Array} flags
|
||||
*/
|
||||
export function storeMessageFlagsToCacheByFolderAndUid(folder, uid, flags)
|
||||
{
|
||||
if (isArray(flags) && 0 < flags.length)
|
||||
{
|
||||
setMessageFlagsToCache(folder, uid, flags);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} folder
|
||||
* @param {string} uid
|
||||
* @param {number} setAction
|
||||
*/
|
||||
export function storeMessageFlagsToCacheBySetAction(folder, uid, setAction)
|
||||
{
|
||||
|
||||
let unread = 0;
|
||||
const flags = getMessageFlagsFromCache(folder, uid);
|
||||
|
||||
if (isArray(flags) && 0 < flags.length)
|
||||
{
|
||||
if (flags[0])
|
||||
{
|
||||
unread = 1;
|
||||
}
|
||||
|
||||
switch (setAction)
|
||||
{
|
||||
case MessageSetAction.SetSeen:
|
||||
flags[0] = false;
|
||||
break;
|
||||
case MessageSetAction.UnsetSeen:
|
||||
flags[0] = true;
|
||||
break;
|
||||
case MessageSetAction.SetFlag:
|
||||
flags[1] = true;
|
||||
break;
|
||||
case MessageSetAction.UnsetFlag:
|
||||
flags[1] = false;
|
||||
break;
|
||||
}
|
||||
|
||||
setMessageFlagsToCache(folder, uid, flags);
|
||||
}
|
||||
|
||||
return unread;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -209,7 +209,8 @@ export const ClientSideKeyName = {
|
|||
'MessageListSize': 5,
|
||||
'LastReplyAction': 6,
|
||||
'LastSignMe': 7,
|
||||
'ComposeLastIdentityID': 8
|
||||
'ComposeLastIdentityID': 8,
|
||||
'MessageHeaderFullInfo': 9
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
import {window, $, _, moment} from 'common';
|
||||
import Translator from 'Common/Translator';
|
||||
import {i18n} from 'Common/Translator';
|
||||
|
||||
let _moment = null;
|
||||
let _momentNow = 0;
|
||||
|
|
@ -48,11 +48,11 @@ function formatCustomShortDate(m)
|
|||
case 4 >= now.diff(m, 'hours'):
|
||||
return m.fromNow();
|
||||
case now.format('L') === m.format('L'):
|
||||
return Translator.i18n('MESSAGE_LIST/TODAY_AT', {
|
||||
return i18n('MESSAGE_LIST/TODAY_AT', {
|
||||
TIME: m.format('LT')
|
||||
});
|
||||
case now.clone().subtract('days', 1).format('L') === m.format('L'):
|
||||
return Translator.i18n('MESSAGE_LIST/YESTERDAY_AT', {
|
||||
return i18n('MESSAGE_LIST/YESTERDAY_AT', {
|
||||
TIME: m.format('LT')
|
||||
});
|
||||
case now.year() === m.year():
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
import {$, _, key} from 'common';
|
||||
import ko from 'ko';
|
||||
import {EventKeyCode} from 'Common/Enums';
|
||||
import {isArray, inArray} from 'Common/Utils';
|
||||
import {isArray, inArray, noop, noopTrue} from 'Common/Utils';
|
||||
|
||||
class Selector
|
||||
{
|
||||
|
|
@ -118,9 +118,6 @@ class Selector
|
|||
this.sLastUid = '';
|
||||
this.oCallbacks = {};
|
||||
|
||||
this.emptyFunction = () => {};
|
||||
this.emptyTrueFunction = () => true;
|
||||
|
||||
this.focusedItem.subscribe((item) => {
|
||||
if (item)
|
||||
{
|
||||
|
|
@ -291,14 +288,14 @@ class Selector
|
|||
{
|
||||
if (!item)
|
||||
{
|
||||
(this.oCallbacks.onItemSelect || this.emptyFunction)(item || null);
|
||||
(this.oCallbacks.onItemSelect || noop)(item || null);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item)
|
||||
{
|
||||
(this.oCallbacks.onItemSelect || this.emptyFunction)(item);
|
||||
(this.oCallbacks.onItemSelect || noop)(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -416,14 +413,14 @@ class Selector
|
|||
* @return {boolean}
|
||||
*/
|
||||
autoSelect() {
|
||||
return !!(this.oCallbacks.onAutoSelect || this.emptyTrueFunction)();
|
||||
return !!(this.oCallbacks.onAutoSelect || noopTrue)();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {boolean} up
|
||||
*/
|
||||
doUpUpOrDownDown(up) {
|
||||
(this.oCallbacks.onUpUpOrDownDown || this.emptyTrueFunction)(!!up);
|
||||
(this.oCallbacks.onUpUpOrDownDown || noopTrue)(!!up);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -2,342 +2,332 @@
|
|||
import {window, $, _} from 'common';
|
||||
import ko from 'ko';
|
||||
import {Notification, UploadErrorCode} from 'Common/Enums';
|
||||
import {pInt, isUnd, isNull, has, bind, microtime, noop, inArray} from 'Common/Utils';
|
||||
import {pInt, isUnd, isNull, has, microtime, inArray} from 'Common/Utils';
|
||||
import {$html, bAnimationSupported} from 'Common/Globals';
|
||||
import {reload as momentorReload} from 'Common/Momentor';
|
||||
import {langLink} from 'Common/Links';
|
||||
import Promise from 'Promise';
|
||||
|
||||
class Translator
|
||||
let I18N_DATA = window.rainloopI18N || {};
|
||||
|
||||
const I18N_NOTIFICATION_DATA = {};
|
||||
const I18N_NOTIFICATION_MAP = [
|
||||
[Notification.InvalidToken, 'NOTIFICATIONS/INVALID_TOKEN'],
|
||||
[Notification.InvalidToken, 'NOTIFICATIONS/INVALID_TOKEN'],
|
||||
[Notification.AuthError, 'NOTIFICATIONS/AUTH_ERROR'],
|
||||
[Notification.AccessError, 'NOTIFICATIONS/ACCESS_ERROR'],
|
||||
[Notification.ConnectionError, 'NOTIFICATIONS/CONNECTION_ERROR'],
|
||||
[Notification.CaptchaError, 'NOTIFICATIONS/CAPTCHA_ERROR'],
|
||||
[Notification.SocialFacebookLoginAccessDisable, 'NOTIFICATIONS/SOCIAL_FACEBOOK_LOGIN_ACCESS_DISABLE'],
|
||||
[Notification.SocialTwitterLoginAccessDisable, 'NOTIFICATIONS/SOCIAL_TWITTER_LOGIN_ACCESS_DISABLE'],
|
||||
[Notification.SocialGoogleLoginAccessDisable, 'NOTIFICATIONS/SOCIAL_GOOGLE_LOGIN_ACCESS_DISABLE'],
|
||||
[Notification.DomainNotAllowed, 'NOTIFICATIONS/DOMAIN_NOT_ALLOWED'],
|
||||
[Notification.AccountNotAllowed, 'NOTIFICATIONS/ACCOUNT_NOT_ALLOWED'],
|
||||
|
||||
[Notification.AccountTwoFactorAuthRequired, 'NOTIFICATIONS/ACCOUNT_TWO_FACTOR_AUTH_REQUIRED'],
|
||||
[Notification.AccountTwoFactorAuthError, 'NOTIFICATIONS/ACCOUNT_TWO_FACTOR_AUTH_ERROR'],
|
||||
|
||||
[Notification.CouldNotSaveNewPassword, 'NOTIFICATIONS/COULD_NOT_SAVE_NEW_PASSWORD'],
|
||||
[Notification.CurrentPasswordIncorrect, 'NOTIFICATIONS/CURRENT_PASSWORD_INCORRECT'],
|
||||
[Notification.NewPasswordShort, 'NOTIFICATIONS/NEW_PASSWORD_SHORT'],
|
||||
[Notification.NewPasswordWeak, 'NOTIFICATIONS/NEW_PASSWORD_WEAK'],
|
||||
[Notification.NewPasswordForbidden, 'NOTIFICATIONS/NEW_PASSWORD_FORBIDDENT'],
|
||||
|
||||
[Notification.ContactsSyncError, 'NOTIFICATIONS/CONTACTS_SYNC_ERROR'],
|
||||
|
||||
[Notification.CantGetMessageList, 'NOTIFICATIONS/CANT_GET_MESSAGE_LIST'],
|
||||
[Notification.CantGetMessage, 'NOTIFICATIONS/CANT_GET_MESSAGE'],
|
||||
[Notification.CantDeleteMessage, 'NOTIFICATIONS/CANT_DELETE_MESSAGE'],
|
||||
[Notification.CantMoveMessage, 'NOTIFICATIONS/CANT_MOVE_MESSAGE'],
|
||||
[Notification.CantCopyMessage, 'NOTIFICATIONS/CANT_MOVE_MESSAGE'],
|
||||
|
||||
[Notification.CantSaveMessage, 'NOTIFICATIONS/CANT_SAVE_MESSAGE'],
|
||||
[Notification.CantSendMessage, 'NOTIFICATIONS/CANT_SEND_MESSAGE'],
|
||||
[Notification.InvalidRecipients, 'NOTIFICATIONS/INVALID_RECIPIENTS'],
|
||||
|
||||
[Notification.CantSaveFilters, 'NOTIFICATIONS/CANT_SAVE_FILTERS'],
|
||||
[Notification.CantGetFilters, 'NOTIFICATIONS/CANT_GET_FILTERS'],
|
||||
[Notification.FiltersAreNotCorrect, 'NOTIFICATIONS/FILTERS_ARE_NOT_CORRECT'],
|
||||
|
||||
[Notification.CantCreateFolder, 'NOTIFICATIONS/CANT_CREATE_FOLDER'],
|
||||
[Notification.CantRenameFolder, 'NOTIFICATIONS/CANT_RENAME_FOLDER'],
|
||||
[Notification.CantDeleteFolder, 'NOTIFICATIONS/CANT_DELETE_FOLDER'],
|
||||
[Notification.CantDeleteNonEmptyFolder, 'NOTIFICATIONS/CANT_DELETE_NON_EMPTY_FOLDER'],
|
||||
[Notification.CantSubscribeFolder, 'NOTIFICATIONS/CANT_SUBSCRIBE_FOLDER'],
|
||||
[Notification.CantUnsubscribeFolder, 'NOTIFICATIONS/CANT_UNSUBSCRIBE_FOLDER'],
|
||||
|
||||
[Notification.CantSaveSettings, 'NOTIFICATIONS/CANT_SAVE_SETTINGS'],
|
||||
[Notification.CantSavePluginSettings, 'NOTIFICATIONS/CANT_SAVE_PLUGIN_SETTINGS'],
|
||||
|
||||
[Notification.DomainAlreadyExists, 'NOTIFICATIONS/DOMAIN_ALREADY_EXISTS'],
|
||||
|
||||
[Notification.CantInstallPackage, 'NOTIFICATIONS/CANT_INSTALL_PACKAGE'],
|
||||
[Notification.CantDeletePackage, 'NOTIFICATIONS/CANT_DELETE_PACKAGE'],
|
||||
[Notification.InvalidPluginPackage, 'NOTIFICATIONS/INVALID_PLUGIN_PACKAGE'],
|
||||
[Notification.UnsupportedPluginPackage, 'NOTIFICATIONS/UNSUPPORTED_PLUGIN_PACKAGE'],
|
||||
|
||||
[Notification.LicensingServerIsUnavailable, 'NOTIFICATIONS/LICENSING_SERVER_IS_UNAVAILABLE'],
|
||||
[Notification.LicensingExpired, 'NOTIFICATIONS/LICENSING_EXPIRED'],
|
||||
[Notification.LicensingBanned, 'NOTIFICATIONS/LICENSING_BANNED'],
|
||||
|
||||
[Notification.DemoSendMessageError, 'NOTIFICATIONS/DEMO_SEND_MESSAGE_ERROR'],
|
||||
[Notification.DemoAccountError, 'NOTIFICATIONS/DEMO_ACCOUNT_ERROR'],
|
||||
|
||||
[Notification.AccountAlreadyExists, 'NOTIFICATIONS/ACCOUNT_ALREADY_EXISTS'],
|
||||
[Notification.AccountDoesNotExist, 'NOTIFICATIONS/ACCOUNT_DOES_NOT_EXIST'],
|
||||
|
||||
[Notification.MailServerError, 'NOTIFICATIONS/MAIL_SERVER_ERROR'],
|
||||
[Notification.InvalidInputArgument, 'NOTIFICATIONS/INVALID_INPUT_ARGUMENT'],
|
||||
[Notification.UnknownNotification, 'NOTIFICATIONS/UNKNOWN_ERROR'],
|
||||
[Notification.UnknownError, 'NOTIFICATIONS/UNKNOWN_ERROR']
|
||||
];
|
||||
|
||||
export const trigger = ko.observable(false);
|
||||
|
||||
/**
|
||||
* @param {string} key
|
||||
* @param {Object=} valueList
|
||||
* @param {string=} defaulValue
|
||||
* @return {string}
|
||||
*/
|
||||
export function i18n(key, valueList, defaulValue)
|
||||
{
|
||||
data = {};
|
||||
notificationI18N = {};
|
||||
let
|
||||
valueName = '',
|
||||
result = I18N_DATA[key]
|
||||
;
|
||||
|
||||
constructor() {
|
||||
this.data = window.rainloopI18N || {};
|
||||
this.trigger = ko.observable(false);
|
||||
this.i18n = bind(this.i18n, this);
|
||||
this.init();
|
||||
if (isUnd(result))
|
||||
{
|
||||
result = isUnd(defaulValue) ? key : defaulValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} key
|
||||
* @param {Object=} valueList
|
||||
* @param {string=} defaulValue
|
||||
* @return {string}
|
||||
*/
|
||||
i18n(key, valueList, defaulValue) {
|
||||
|
||||
let
|
||||
valueName = '',
|
||||
result = this.data[key]
|
||||
;
|
||||
|
||||
if (isUnd(result))
|
||||
if (!isUnd(valueList) && !isNull(valueList))
|
||||
{
|
||||
for (valueName in valueList)
|
||||
{
|
||||
result = isUnd(defaulValue) ? key : defaulValue;
|
||||
}
|
||||
|
||||
if (!isUnd(valueList) && !isNull(valueList))
|
||||
{
|
||||
for (valueName in valueList)
|
||||
if (has(valueList, valueName))
|
||||
{
|
||||
if (has(valueList, valueName))
|
||||
{
|
||||
result = result.replace('%' + valueName + '%', valueList[valueName]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} element
|
||||
*/
|
||||
i18nToNode(element) {
|
||||
|
||||
const
|
||||
$el = $(element),
|
||||
key = $el.data('i18n')
|
||||
;
|
||||
|
||||
if (key)
|
||||
{
|
||||
if ('[' === key.substr(0, 1))
|
||||
{
|
||||
switch (key.substr(0, 6))
|
||||
{
|
||||
case '[html]':
|
||||
$el.html(this.i18n(key.substr(6)));
|
||||
break;
|
||||
case '[place':
|
||||
$el.attr('placeholder', this.i18n(key.substr(13)));
|
||||
break;
|
||||
case '[title':
|
||||
$el.attr('title', this.i18n(key.substr(7)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$el.text(this.i18n(key));
|
||||
result = result.replace('%' + valueName + '%', valueList[valueName]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} elements
|
||||
* @param {boolean=} animate = false
|
||||
*/
|
||||
i18nToNodes(elements, animate = false) {
|
||||
_.defer(() => {
|
||||
return result;
|
||||
}
|
||||
|
||||
$('[data-i18n]', elements).each((index, item) => {
|
||||
this.i18nToNode(item);
|
||||
});
|
||||
const i18nToNode = (element) => {
|
||||
|
||||
if (animate && bAnimationSupported)
|
||||
const
|
||||
$el = $(element),
|
||||
key = $el.data('i18n')
|
||||
;
|
||||
|
||||
if (key)
|
||||
{
|
||||
if ('[' === key.substr(0, 1))
|
||||
{
|
||||
switch (key.substr(0, 6))
|
||||
{
|
||||
$('.i18n-animation[data-i18n]', elements).letterfx({
|
||||
fx: 'fall fade',
|
||||
backwards: false,
|
||||
timing: 50,
|
||||
fx_duration: '50ms',
|
||||
letter_end: 'restore',
|
||||
element_end: 'restore'
|
||||
});
|
||||
case '[html]':
|
||||
$el.html(i18n(key.substr(6)));
|
||||
break;
|
||||
case '[place':
|
||||
$el.attr('placeholder', i18n(key.substr(13)));
|
||||
break;
|
||||
case '[title':
|
||||
$el.attr('title', i18n(key.substr(7)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$el.text(i18n(key));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Object} elements
|
||||
* @param {boolean=} animate = false
|
||||
*/
|
||||
export function i18nToNodes(elements, animate = false)
|
||||
{
|
||||
_.defer(() => {
|
||||
|
||||
$('[data-i18n]', elements).each((index, item) => {
|
||||
i18nToNode(item);
|
||||
});
|
||||
}
|
||||
|
||||
reloadData() {
|
||||
if (window.rainloopI18N)
|
||||
if (animate && bAnimationSupported)
|
||||
{
|
||||
this.data = window.rainloopI18N || {};
|
||||
|
||||
this.i18nToNodes(window.document, true);
|
||||
|
||||
require('Common/Momentor').reload();
|
||||
this.trigger(!this.trigger());
|
||||
}
|
||||
|
||||
window.rainloopI18N = null;
|
||||
}
|
||||
|
||||
initNotificationLanguage() {
|
||||
|
||||
const map = [
|
||||
[Notification.InvalidToken, 'NOTIFICATIONS/INVALID_TOKEN'],
|
||||
[Notification.InvalidToken, 'NOTIFICATIONS/INVALID_TOKEN'],
|
||||
[Notification.AuthError, 'NOTIFICATIONS/AUTH_ERROR'],
|
||||
[Notification.AccessError, 'NOTIFICATIONS/ACCESS_ERROR'],
|
||||
[Notification.ConnectionError, 'NOTIFICATIONS/CONNECTION_ERROR'],
|
||||
[Notification.CaptchaError, 'NOTIFICATIONS/CAPTCHA_ERROR'],
|
||||
[Notification.SocialFacebookLoginAccessDisable, 'NOTIFICATIONS/SOCIAL_FACEBOOK_LOGIN_ACCESS_DISABLE'],
|
||||
[Notification.SocialTwitterLoginAccessDisable, 'NOTIFICATIONS/SOCIAL_TWITTER_LOGIN_ACCESS_DISABLE'],
|
||||
[Notification.SocialGoogleLoginAccessDisable, 'NOTIFICATIONS/SOCIAL_GOOGLE_LOGIN_ACCESS_DISABLE'],
|
||||
[Notification.DomainNotAllowed, 'NOTIFICATIONS/DOMAIN_NOT_ALLOWED'],
|
||||
[Notification.AccountNotAllowed, 'NOTIFICATIONS/ACCOUNT_NOT_ALLOWED'],
|
||||
|
||||
[Notification.AccountTwoFactorAuthRequired, 'NOTIFICATIONS/ACCOUNT_TWO_FACTOR_AUTH_REQUIRED'],
|
||||
[Notification.AccountTwoFactorAuthError, 'NOTIFICATIONS/ACCOUNT_TWO_FACTOR_AUTH_ERROR'],
|
||||
|
||||
[Notification.CouldNotSaveNewPassword, 'NOTIFICATIONS/COULD_NOT_SAVE_NEW_PASSWORD'],
|
||||
[Notification.CurrentPasswordIncorrect, 'NOTIFICATIONS/CURRENT_PASSWORD_INCORRECT'],
|
||||
[Notification.NewPasswordShort, 'NOTIFICATIONS/NEW_PASSWORD_SHORT'],
|
||||
[Notification.NewPasswordWeak, 'NOTIFICATIONS/NEW_PASSWORD_WEAK'],
|
||||
[Notification.NewPasswordForbidden, 'NOTIFICATIONS/NEW_PASSWORD_FORBIDDENT'],
|
||||
|
||||
[Notification.ContactsSyncError, 'NOTIFICATIONS/CONTACTS_SYNC_ERROR'],
|
||||
|
||||
[Notification.CantGetMessageList, 'NOTIFICATIONS/CANT_GET_MESSAGE_LIST'],
|
||||
[Notification.CantGetMessage, 'NOTIFICATIONS/CANT_GET_MESSAGE'],
|
||||
[Notification.CantDeleteMessage, 'NOTIFICATIONS/CANT_DELETE_MESSAGE'],
|
||||
[Notification.CantMoveMessage, 'NOTIFICATIONS/CANT_MOVE_MESSAGE'],
|
||||
[Notification.CantCopyMessage, 'NOTIFICATIONS/CANT_MOVE_MESSAGE'],
|
||||
|
||||
[Notification.CantSaveMessage, 'NOTIFICATIONS/CANT_SAVE_MESSAGE'],
|
||||
[Notification.CantSendMessage, 'NOTIFICATIONS/CANT_SEND_MESSAGE'],
|
||||
[Notification.InvalidRecipients, 'NOTIFICATIONS/INVALID_RECIPIENTS'],
|
||||
|
||||
[Notification.CantSaveFilters, 'NOTIFICATIONS/CANT_SAVE_FILTERS'],
|
||||
[Notification.CantGetFilters, 'NOTIFICATIONS/CANT_GET_FILTERS'],
|
||||
[Notification.FiltersAreNotCorrect, 'NOTIFICATIONS/FILTERS_ARE_NOT_CORRECT'],
|
||||
|
||||
[Notification.CantCreateFolder, 'NOTIFICATIONS/CANT_CREATE_FOLDER'],
|
||||
[Notification.CantRenameFolder, 'NOTIFICATIONS/CANT_RENAME_FOLDER'],
|
||||
[Notification.CantDeleteFolder, 'NOTIFICATIONS/CANT_DELETE_FOLDER'],
|
||||
[Notification.CantDeleteNonEmptyFolder, 'NOTIFICATIONS/CANT_DELETE_NON_EMPTY_FOLDER'],
|
||||
[Notification.CantSubscribeFolder, 'NOTIFICATIONS/CANT_SUBSCRIBE_FOLDER'],
|
||||
[Notification.CantUnsubscribeFolder, 'NOTIFICATIONS/CANT_UNSUBSCRIBE_FOLDER'],
|
||||
|
||||
[Notification.CantSaveSettings, 'NOTIFICATIONS/CANT_SAVE_SETTINGS'],
|
||||
[Notification.CantSavePluginSettings, 'NOTIFICATIONS/CANT_SAVE_PLUGIN_SETTINGS'],
|
||||
|
||||
[Notification.DomainAlreadyExists, 'NOTIFICATIONS/DOMAIN_ALREADY_EXISTS'],
|
||||
|
||||
[Notification.CantInstallPackage, 'NOTIFICATIONS/CANT_INSTALL_PACKAGE'],
|
||||
[Notification.CantDeletePackage, 'NOTIFICATIONS/CANT_DELETE_PACKAGE'],
|
||||
[Notification.InvalidPluginPackage, 'NOTIFICATIONS/INVALID_PLUGIN_PACKAGE'],
|
||||
[Notification.UnsupportedPluginPackage, 'NOTIFICATIONS/UNSUPPORTED_PLUGIN_PACKAGE'],
|
||||
|
||||
[Notification.LicensingServerIsUnavailable, 'NOTIFICATIONS/LICENSING_SERVER_IS_UNAVAILABLE'],
|
||||
[Notification.LicensingExpired, 'NOTIFICATIONS/LICENSING_EXPIRED'],
|
||||
[Notification.LicensingBanned, 'NOTIFICATIONS/LICENSING_BANNED'],
|
||||
|
||||
[Notification.DemoSendMessageError, 'NOTIFICATIONS/DEMO_SEND_MESSAGE_ERROR'],
|
||||
[Notification.DemoAccountError, 'NOTIFICATIONS/DEMO_ACCOUNT_ERROR'],
|
||||
|
||||
[Notification.AccountAlreadyExists, 'NOTIFICATIONS/ACCOUNT_ALREADY_EXISTS'],
|
||||
[Notification.AccountDoesNotExist, 'NOTIFICATIONS/ACCOUNT_DOES_NOT_EXIST'],
|
||||
|
||||
[Notification.MailServerError, 'NOTIFICATIONS/MAIL_SERVER_ERROR'],
|
||||
[Notification.InvalidInputArgument, 'NOTIFICATIONS/INVALID_INPUT_ARGUMENT'],
|
||||
[Notification.UnknownNotification, 'NOTIFICATIONS/UNKNOWN_ERROR'],
|
||||
[Notification.UnknownError, 'NOTIFICATIONS/UNKNOWN_ERROR']
|
||||
];
|
||||
|
||||
this.notificationI18N = this.notificationI18N || {};
|
||||
|
||||
map.forEach((item) => {
|
||||
this.notificationI18N[item[0]] = this.i18n(item[1]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Function} callback
|
||||
* @param {Object} scope
|
||||
* @param {Function=} langCallback
|
||||
*/
|
||||
initOnStartOrLangChange(callback, scope, langCallback = null) {
|
||||
if (callback)
|
||||
{
|
||||
callback.call(scope);
|
||||
}
|
||||
|
||||
if (langCallback)
|
||||
{
|
||||
this.trigger.subscribe(() => {
|
||||
if (callback)
|
||||
{
|
||||
callback.call(scope);
|
||||
}
|
||||
|
||||
langCallback.call(scope);
|
||||
$('.i18n-animation[data-i18n]', elements).letterfx({
|
||||
fx: 'fall fade',
|
||||
backwards: false,
|
||||
timing: 50,
|
||||
fx_duration: '50ms',
|
||||
letter_end: 'restore',
|
||||
element_end: 'restore'
|
||||
});
|
||||
}
|
||||
else if (callback)
|
||||
{
|
||||
this.trigger.subscribe(callback, scope);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const reloadData = () => {
|
||||
if (window.rainloopI18N)
|
||||
{
|
||||
I18N_DATA = window.rainloopI18N || {};
|
||||
|
||||
i18nToNodes(window.document, true);
|
||||
|
||||
momentorReload();
|
||||
trigger(!trigger());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} code
|
||||
* @param {*=} message = ''
|
||||
* @param {*=} defCode = null
|
||||
* @return {string}
|
||||
*/
|
||||
getNotification(code, message = '', defCode = null) {
|
||||
code = window.parseInt(code, 10) || 0;
|
||||
if (Notification.ClientViewError === code && message)
|
||||
{
|
||||
return message;
|
||||
}
|
||||
window.rainloopI18N = null;
|
||||
};
|
||||
|
||||
defCode = defCode ? (window.parseInt(defCode, 10)) || 0 : 0;
|
||||
return isUnd(this.notificationI18N[code]) ? (
|
||||
defCode && isUnd(this.notificationI18N[defCode]) ? this.notificationI18N[defCode] : ''
|
||||
) : this.notificationI18N[code];
|
||||
export function initNotificationLanguage()
|
||||
{
|
||||
I18N_NOTIFICATION_MAP.forEach((item) => {
|
||||
I18N_NOTIFICATION_DATA[item[0]] = i18n(item[1]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Function} callback
|
||||
* @param {Object} scope
|
||||
* @param {Function=} langCallback = null
|
||||
*/
|
||||
export function initOnStartOrLangChange(callback, scope, langCallback = null)
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
callback.call(scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {object} response
|
||||
* @param {number} defCode = Notification.UnknownNotification
|
||||
* @return {string}
|
||||
*/
|
||||
getNotificationFromResponse(response, defCode = Notification.UnknownNotification) {
|
||||
return response && response.ErrorCode ?
|
||||
this.getNotification(pInt(response.ErrorCode), response.ErrorMessage || '') :
|
||||
this.getNotification(defCode);
|
||||
if (langCallback)
|
||||
{
|
||||
trigger.subscribe(() => {
|
||||
if (callback)
|
||||
{
|
||||
callback.call(scope);
|
||||
}
|
||||
|
||||
langCallback.call(scope);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {*} code
|
||||
* @return {string}
|
||||
*/
|
||||
getUploadErrorDescByCode(code) {
|
||||
let result = '';
|
||||
switch (window.parseInt(code, 10) || 0) {
|
||||
case UploadErrorCode.FileIsTooBig:
|
||||
result = this.i18n('UPLOAD/ERROR_FILE_IS_TOO_BIG');
|
||||
break;
|
||||
case UploadErrorCode.FilePartiallyUploaded:
|
||||
result = this.i18n('UPLOAD/ERROR_FILE_PARTIALLY_UPLOADED');
|
||||
break;
|
||||
case UploadErrorCode.FileNoUploaded:
|
||||
result = this.i18n('UPLOAD/ERROR_NO_FILE_UPLOADED');
|
||||
break;
|
||||
case UploadErrorCode.MissingTempFolder:
|
||||
result = this.i18n('UPLOAD/ERROR_MISSING_TEMP_FOLDER');
|
||||
break;
|
||||
case UploadErrorCode.FileOnSaveingError:
|
||||
result = this.i18n('UPLOAD/ERROR_ON_SAVING_FILE');
|
||||
break;
|
||||
case UploadErrorCode.FileType:
|
||||
result = this.i18n('UPLOAD/ERROR_FILE_TYPE');
|
||||
break;
|
||||
default:
|
||||
result = this.i18n('UPLOAD/ERROR_UNKNOWN');
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {boolean} admin
|
||||
* @param {string} language
|
||||
* @param {Function=} done
|
||||
* @param {Function=} fail
|
||||
*/
|
||||
reload(admin, language, done, fail) {
|
||||
|
||||
const
|
||||
self = this,
|
||||
start = microtime()
|
||||
;
|
||||
|
||||
$html.addClass('rl-changing-language');
|
||||
|
||||
$.ajax({
|
||||
url: require('Common/Links').langLink(language, admin),
|
||||
dataType: 'script',
|
||||
cache: true
|
||||
})
|
||||
.fail(fail || noop)
|
||||
.done(function () {
|
||||
_.delay(function () {
|
||||
|
||||
self.reloadData();
|
||||
|
||||
(done || noop)();
|
||||
|
||||
const isRtl = -1 < inArray(language, ['ar', 'ar_sa', 'he', 'he_he', 'ur', 'ur_ir']);
|
||||
|
||||
$html
|
||||
.removeClass('rl-changing-language')
|
||||
.removeClass('rl-rtl rl-ltr')
|
||||
.addClass(isRtl ? 'rl-rtl' : 'rl-ltr')
|
||||
// .attr('dir', isRtl ? 'rtl' : 'ltr')
|
||||
;
|
||||
|
||||
}, 500 < microtime() - start ? 1 : 500);
|
||||
})
|
||||
;
|
||||
}
|
||||
|
||||
init() {
|
||||
$html.addClass('rl-' + ($html.attr('dir') || 'ltr'));
|
||||
else if (callback)
|
||||
{
|
||||
trigger.subscribe(callback, scope);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new Translator();
|
||||
/**
|
||||
* @param {number} code
|
||||
* @param {*=} message = ''
|
||||
* @param {*=} defCode = null
|
||||
* @return {string}
|
||||
*/
|
||||
export function getNotification(code, message = '', defCode = null)
|
||||
{
|
||||
code = window.parseInt(code, 10) || 0;
|
||||
if (Notification.ClientViewError === code && message)
|
||||
{
|
||||
return message;
|
||||
}
|
||||
|
||||
defCode = defCode ? (window.parseInt(defCode, 10)) || 0 : 0;
|
||||
return isUnd(I18N_NOTIFICATION_DATA[code]) ? (
|
||||
defCode && isUnd(I18N_NOTIFICATION_DATA[defCode]) ? I18N_NOTIFICATION_DATA[defCode] : ''
|
||||
) : I18N_NOTIFICATION_DATA[code];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {object} response
|
||||
* @param {number} defCode = Notification.UnknownNotification
|
||||
* @return {string}
|
||||
*/
|
||||
export function getNotificationFromResponse(response, defCode = Notification.UnknownNotification)
|
||||
{
|
||||
return response && response.ErrorCode ?
|
||||
getNotification(pInt(response.ErrorCode), response.ErrorMessage || '') : getNotification(defCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {*} code
|
||||
* @return {string}
|
||||
*/
|
||||
export function getUploadErrorDescByCode(code)
|
||||
{
|
||||
let result = '';
|
||||
switch (window.parseInt(code, 10) || 0)
|
||||
{
|
||||
case UploadErrorCode.FileIsTooBig:
|
||||
result = i18n('UPLOAD/ERROR_FILE_IS_TOO_BIG');
|
||||
break;
|
||||
case UploadErrorCode.FilePartiallyUploaded:
|
||||
result = i18n('UPLOAD/ERROR_FILE_PARTIALLY_UPLOADED');
|
||||
break;
|
||||
case UploadErrorCode.FileNoUploaded:
|
||||
result = i18n('UPLOAD/ERROR_NO_FILE_UPLOADED');
|
||||
break;
|
||||
case UploadErrorCode.MissingTempFolder:
|
||||
result = i18n('UPLOAD/ERROR_MISSING_TEMP_FOLDER');
|
||||
break;
|
||||
case UploadErrorCode.FileOnSaveingError:
|
||||
result = i18n('UPLOAD/ERROR_ON_SAVING_FILE');
|
||||
break;
|
||||
case UploadErrorCode.FileType:
|
||||
result = i18n('UPLOAD/ERROR_FILE_TYPE');
|
||||
break;
|
||||
default:
|
||||
result = i18n('UPLOAD/ERROR_UNKNOWN');
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {boolean} admin
|
||||
* @param {string} language
|
||||
*/
|
||||
export function reload(admin, language)
|
||||
{
|
||||
const start = microtime();
|
||||
|
||||
$html.addClass('rl-changing-language');
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
$.ajax({
|
||||
url: langLink(language, admin),
|
||||
dataType: 'script',
|
||||
cache: true
|
||||
}).then(() => {
|
||||
_.delay(() => {
|
||||
|
||||
reloadData();
|
||||
|
||||
const isRtl = -1 < inArray(language, ['ar', 'ar_sa', 'he', 'he_he', 'ur', 'ur_ir']);
|
||||
|
||||
$html
|
||||
.removeClass('rl-changing-language')
|
||||
.removeClass('rl-rtl rl-ltr')
|
||||
.addClass(isRtl ? 'rl-rtl' : 'rl-ltr')
|
||||
// .attr('dir', isRtl ? 'rtl' : 'ltr')
|
||||
;
|
||||
|
||||
resolve();
|
||||
|
||||
}, 500 < microtime() - start ? 1 : 500);
|
||||
}, () => {
|
||||
$html.removeClass('rl-changing-language');
|
||||
window.rainloopI18N = null;
|
||||
reject();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// init section
|
||||
$html.addClass('rl-' + ($html.attr('dir') || 'ltr'));
|
||||
|
|
|
|||
|
|
@ -20,8 +20,10 @@ const isNull = _.isNull;
|
|||
const has = _.has;
|
||||
const bind = _.bind;
|
||||
const noop = () => {};
|
||||
const noopTrue = () => true;
|
||||
const noopFalse = () => false;
|
||||
|
||||
export {trim, inArray, isArray, isObject, isFunc, isUnd, isNull, has, bind, noop, noop as emptyFunction};
|
||||
export {trim, inArray, isArray, isObject, isFunc, isUnd, isNull, has, bind, noop, noopTrue, noopFalse};
|
||||
|
||||
/**
|
||||
* @param {Function} callback
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue