mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
eslint (additional rules)
This commit is contained in:
parent
77a1d3f3df
commit
8e8a041032
150 changed files with 21911 additions and 23106 deletions
|
|
@ -1,246 +1,247 @@
|
|||
|
||||
(function () {
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
|
||||
'use strict';
|
||||
Enums = require('Common/Enums'),
|
||||
Consts = require('Common/Consts'),
|
||||
Utils = require('Common/Utils'),
|
||||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
Cache = require('Common/Cache');
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Consts = require('Common/Consts'),
|
||||
Utils = require('Common/Utils'),
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function FolderUserStore()
|
||||
{
|
||||
this.displaySpecSetting = ko.observable(true);
|
||||
|
||||
Cache = require('Common/Cache')
|
||||
;
|
||||
this.sentFolder = ko.observable('');
|
||||
this.draftFolder = ko.observable('');
|
||||
this.spamFolder = ko.observable('');
|
||||
this.trashFolder = ko.observable('');
|
||||
this.archiveFolder = ko.observable('');
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function FolderUserStore()
|
||||
{
|
||||
this.displaySpecSetting = ko.observable(true);
|
||||
this.namespace = '';
|
||||
|
||||
this.sentFolder = ko.observable('');
|
||||
this.draftFolder = ko.observable('');
|
||||
this.spamFolder = ko.observable('');
|
||||
this.trashFolder = ko.observable('');
|
||||
this.archiveFolder = ko.observable('');
|
||||
this.folderList = ko.observableArray([]);
|
||||
this.folderList.optimized = ko.observable(false);
|
||||
this.folderList.error = ko.observable('');
|
||||
|
||||
this.namespace = '';
|
||||
this.foldersLoading = ko.observable(false);
|
||||
this.foldersCreating = ko.observable(false);
|
||||
this.foldersDeleting = ko.observable(false);
|
||||
this.foldersRenaming = ko.observable(false);
|
||||
|
||||
this.folderList = ko.observableArray([]);
|
||||
this.folderList.optimized = ko.observable(false);
|
||||
this.folderList.error = ko.observable('');
|
||||
this.foldersInboxUnreadCount = ko.observable(0);
|
||||
|
||||
this.foldersLoading = ko.observable(false);
|
||||
this.foldersCreating = ko.observable(false);
|
||||
this.foldersDeleting = ko.observable(false);
|
||||
this.foldersRenaming = ko.observable(false);
|
||||
|
||||
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.computers();
|
||||
this.subscribers();
|
||||
}
|
||||
|
||||
FolderUserStore.prototype.computers = function ()
|
||||
{
|
||||
this.draftFolderNotEnabled = ko.computed(function () {
|
||||
return '' === this.draftFolder() || Consts.UNUSED_OPTION_VALUE === this.draftFolder();
|
||||
}, this);
|
||||
|
||||
this.foldersListWithSingleInboxRootFolder = ko.computed(function () {
|
||||
return !_.find(this.folderList(), function (oFolder) {
|
||||
return oFolder && !oFolder.isSystemFolder() && oFolder.visible();
|
||||
});
|
||||
}, this);
|
||||
|
||||
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.foldersChanging = ko.computed(function () {
|
||||
var
|
||||
bLoading = this.foldersLoading(),
|
||||
bCreating = this.foldersCreating(),
|
||||
bDeleting = this.foldersDeleting(),
|
||||
bRenaming = this.foldersRenaming()
|
||||
;
|
||||
return bLoading || bCreating || bDeleting || bRenaming;
|
||||
}, this);
|
||||
|
||||
this.folderListSystemNames = ko.computed(function () {
|
||||
|
||||
var
|
||||
aList = [Cache.getFolderInboxName()],
|
||||
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.UNUSED_OPTION_VALUE !== sSentFolder)
|
||||
{
|
||||
aList.push(sSentFolder);
|
||||
}
|
||||
if ('' !== sDraftFolder && Consts.UNUSED_OPTION_VALUE !== sDraftFolder)
|
||||
{
|
||||
aList.push(sDraftFolder);
|
||||
}
|
||||
if ('' !== sSpamFolder && Consts.UNUSED_OPTION_VALUE !== sSpamFolder)
|
||||
{
|
||||
aList.push(sSpamFolder);
|
||||
}
|
||||
if ('' !== sTrashFolder && Consts.UNUSED_OPTION_VALUE !== sTrashFolder)
|
||||
{
|
||||
aList.push(sTrashFolder);
|
||||
}
|
||||
if ('' !== sArchiveFolder && Consts.UNUSED_OPTION_VALUE !== sArchiveFolder)
|
||||
{
|
||||
aList.push(sArchiveFolder);
|
||||
}
|
||||
this.currentFolder = ko.observable(null).extend({toggleSubscribe: [
|
||||
null,
|
||||
function(oPrev) {
|
||||
if (oPrev) {
|
||||
oPrev.selected(false);
|
||||
}
|
||||
},
|
||||
function(oNext) {
|
||||
if (oNext) {
|
||||
oNext.selected(true);
|
||||
}
|
||||
}
|
||||
]});
|
||||
|
||||
return aList;
|
||||
this.computers();
|
||||
this.subscribers();
|
||||
}
|
||||
|
||||
}, this);
|
||||
FolderUserStore.prototype.computers = function()
|
||||
{
|
||||
this.draftFolderNotEnabled = ko.computed(function() {
|
||||
return '' === this.draftFolder() || Consts.UNUSED_OPTION_VALUE === this.draftFolder();
|
||||
}, this);
|
||||
|
||||
this.folderListSystem = ko.computed(function () {
|
||||
return _.compact(_.map(this.folderListSystemNames(), function (sName) {
|
||||
return Cache.getFolderFromCacheList(sName);
|
||||
}));
|
||||
}, this);
|
||||
this.foldersListWithSingleInboxRootFolder = ko.computed(function() {
|
||||
return !_.find(this.folderList(), function(oFolder) {
|
||||
return oFolder && !oFolder.isSystemFolder() && oFolder.visible();
|
||||
});
|
||||
}, this);
|
||||
|
||||
this.folderMenuForMove = ko.computed(function () {
|
||||
return Utils.folderListOptionsBuilder(this.folderListSystem(), this.folderList(), [
|
||||
this.currentFolderFullNameRaw()
|
||||
], null, null, null, null, function (oItem) {
|
||||
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.foldersChanging = ko.computed(function() {
|
||||
var
|
||||
bLoading = this.foldersLoading(),
|
||||
bCreating = this.foldersCreating(),
|
||||
bDeleting = this.foldersDeleting(),
|
||||
bRenaming = this.foldersRenaming();
|
||||
return bLoading || bCreating || bDeleting || bRenaming;
|
||||
}, this);
|
||||
|
||||
this.folderListSystemNames = ko.computed(function() {
|
||||
|
||||
var
|
||||
aList = [Cache.getFolderInboxName()],
|
||||
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.UNUSED_OPTION_VALUE !== sSentFolder)
|
||||
{
|
||||
aList.push(sSentFolder);
|
||||
}
|
||||
if ('' !== sDraftFolder && Consts.UNUSED_OPTION_VALUE !== sDraftFolder)
|
||||
{
|
||||
aList.push(sDraftFolder);
|
||||
}
|
||||
if ('' !== sSpamFolder && Consts.UNUSED_OPTION_VALUE !== sSpamFolder)
|
||||
{
|
||||
aList.push(sSpamFolder);
|
||||
}
|
||||
if ('' !== sTrashFolder && Consts.UNUSED_OPTION_VALUE !== sTrashFolder)
|
||||
{
|
||||
aList.push(sTrashFolder);
|
||||
}
|
||||
if ('' !== sArchiveFolder && Consts.UNUSED_OPTION_VALUE !== sArchiveFolder)
|
||||
{
|
||||
aList.push(sArchiveFolder);
|
||||
}
|
||||
}
|
||||
|
||||
return aList;
|
||||
|
||||
}, this);
|
||||
|
||||
this.folderListSystem = ko.computed(function() {
|
||||
return _.compact(_.map(this.folderListSystemNames(), function(sName) {
|
||||
return Cache.getFolderFromCacheList(sName);
|
||||
}));
|
||||
}, this);
|
||||
|
||||
this.folderMenuForMove = ko.computed(function() {
|
||||
return Utils.folderListOptionsBuilder(this.folderListSystem(), this.folderList(), [
|
||||
this.currentFolderFullNameRaw()
|
||||
], null, null, null, null, function(oItem) {
|
||||
return oItem ? oItem.localName() : '';
|
||||
});
|
||||
}, this);
|
||||
|
||||
this.folderMenuForFilters = ko.computed(function() {
|
||||
return Utils.folderListOptionsBuilder(this.folderListSystem(), this.folderList(),
|
||||
['INBOX'], [['', '']], null, null, null, function(oItem) {
|
||||
return oItem ? oItem.localName() : '';
|
||||
});
|
||||
}, this);
|
||||
}
|
||||
);
|
||||
}, this);
|
||||
};
|
||||
|
||||
this.folderMenuForFilters = ko.computed(function () {
|
||||
return Utils.folderListOptionsBuilder(this.folderListSystem(), this.folderList(),
|
||||
['INBOX'], [['', '']], null, null, null, function (oItem) {
|
||||
return oItem ? oItem.localName() : '';
|
||||
FolderUserStore.prototype.subscribers = function()
|
||||
{
|
||||
var
|
||||
fRemoveSystemFolderType = function(observable) {
|
||||
return function() {
|
||||
var oFolder = Cache.getFolderFromCacheList(observable());
|
||||
if (oFolder)
|
||||
{
|
||||
oFolder.type(Enums.FolderType.User);
|
||||
}
|
||||
);
|
||||
}, this);
|
||||
};
|
||||
};
|
||||
},
|
||||
fSetSystemFolderType = function(iType) {
|
||||
return function(sValue) {
|
||||
var oFolder = Cache.getFolderFromCacheList(sValue);
|
||||
if (oFolder)
|
||||
{
|
||||
oFolder.type(iType);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
FolderUserStore.prototype.subscribers = function ()
|
||||
{
|
||||
var
|
||||
fRemoveSystemFolderType = function (observable) {
|
||||
return function () {
|
||||
var oFolder = Cache.getFolderFromCacheList(observable());
|
||||
if (oFolder)
|
||||
{
|
||||
oFolder.type(Enums.FolderType.User);
|
||||
}
|
||||
};
|
||||
},
|
||||
fSetSystemFolderType = function (iType) {
|
||||
return function (sValue) {
|
||||
var oFolder = Cache.getFolderFromCacheList(sValue);
|
||||
if (oFolder)
|
||||
{
|
||||
oFolder.type(iType);
|
||||
}
|
||||
};
|
||||
}
|
||||
;
|
||||
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(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.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);
|
||||
};
|
||||
/**
|
||||
* @returns {Array}
|
||||
*/
|
||||
FolderUserStore.prototype.getNextFolderNames = function()
|
||||
{
|
||||
var
|
||||
aResult = [],
|
||||
iLimit = 5,
|
||||
iUtc = require('Common/Momentor').momentNowUnix(),
|
||||
iTimeout = iUtc - 60 * 5,
|
||||
aTimeouts = [],
|
||||
sInboxFolderName = Cache.getFolderInboxName(),
|
||||
fSearchFunction = function(aList) {
|
||||
_.each(aList, function(oFolder) {
|
||||
if (oFolder && sInboxFolderName !== oFolder.fullNameRaw &&
|
||||
oFolder.selectable && oFolder.existen &&
|
||||
iTimeout > oFolder.interval &&
|
||||
(oFolder.isSystemFolder() || (oFolder.subScribed() && oFolder.checkable()))
|
||||
)
|
||||
{
|
||||
aTimeouts.push([oFolder.interval, oFolder.fullNameRaw]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {Array}
|
||||
*/
|
||||
FolderUserStore.prototype.getNextFolderNames = function ()
|
||||
{
|
||||
var
|
||||
aResult = [],
|
||||
iLimit = 5,
|
||||
iUtc = require('Common/Momentor').momentNowUnix(),
|
||||
iTimeout = iUtc - 60 * 5,
|
||||
aTimeouts = [],
|
||||
sInboxFolderName = Cache.getFolderInboxName(),
|
||||
fSearchFunction = function (aList) {
|
||||
_.each(aList, function (oFolder) {
|
||||
if (oFolder && sInboxFolderName !== oFolder.fullNameRaw &&
|
||||
oFolder.selectable && oFolder.existen &&
|
||||
iTimeout > oFolder.interval &&
|
||||
(oFolder.isSystemFolder() || (oFolder.subScribed() && oFolder.checkable()))
|
||||
)
|
||||
{
|
||||
aTimeouts.push([oFolder.interval, oFolder.fullNameRaw]);
|
||||
}
|
||||
if (oFolder && 0 < oFolder.subFolders().length)
|
||||
{
|
||||
fSearchFunction(oFolder.subFolders());
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
if (oFolder && 0 < oFolder.subFolders().length)
|
||||
{
|
||||
fSearchFunction(oFolder.subFolders());
|
||||
}
|
||||
});
|
||||
}
|
||||
;
|
||||
fSearchFunction(this.folderList());
|
||||
|
||||
fSearchFunction(this.folderList());
|
||||
aTimeouts.sort(function(a, b) {
|
||||
if (a[0] < b[0])
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else if (a[0] > b[0])
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
aTimeouts.sort(function(a, b) {
|
||||
if (a[0] < b[0]) {
|
||||
return -1;
|
||||
} else if (a[0] > b[0]) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
return 0;
|
||||
});
|
||||
_.find(aTimeouts, function(aItem) {
|
||||
var oFolder = Cache.getFolderFromCacheList(aItem[1]);
|
||||
if (oFolder)
|
||||
{
|
||||
oFolder.interval = iUtc;
|
||||
aResult.push(aItem[1]);
|
||||
}
|
||||
|
||||
_.find(aTimeouts, function (aItem) {
|
||||
var oFolder = Cache.getFolderFromCacheList(aItem[1]);
|
||||
if (oFolder)
|
||||
{
|
||||
oFolder.interval = iUtc;
|
||||
aResult.push(aItem[1]);
|
||||
}
|
||||
return iLimit <= aResult.length;
|
||||
});
|
||||
|
||||
return iLimit <= aResult.length;
|
||||
});
|
||||
aResult = _.uniq(aResult);
|
||||
|
||||
aResult = _.uniq(aResult);
|
||||
return aResult;
|
||||
};
|
||||
|
||||
return aResult;
|
||||
};
|
||||
|
||||
module.exports = new FolderUserStore();
|
||||
|
||||
}());
|
||||
module.exports = new FolderUserStore();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue