mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Code refactoring
This commit is contained in:
parent
79233ad83c
commit
286ab567af
53 changed files with 618 additions and 581 deletions
75
dev/Stores/User/Folder.js
Normal file
75
dev/Stores/User/Folder.js
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
|
||||
(function () {
|
||||
|
||||
'use strict';
|
||||
|
||||
var
|
||||
ko = require('ko'),
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Consts = require('Common/Consts'),
|
||||
|
||||
Cache = require('Storage/User/Cache')
|
||||
;
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function FolderUserStore()
|
||||
{
|
||||
this.sentFolder = ko.observable('');
|
||||
this.draftFolder = ko.observable('');
|
||||
this.spamFolder = ko.observable('');
|
||||
this.trashFolder = ko.observable('');
|
||||
this.archiveFolder = ko.observable('');
|
||||
|
||||
this.computed();
|
||||
this.subscribe();
|
||||
}
|
||||
|
||||
FolderUserStore.prototype.computed = function ()
|
||||
{
|
||||
this.draftFolderNotEnabled = ko.computed(function () {
|
||||
return '' === this.draftFolder() || Consts.Values.UnuseOptionValue === this.draftFolder();
|
||||
}, this);
|
||||
};
|
||||
|
||||
FolderUserStore.prototype.subscribe = 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(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);
|
||||
};
|
||||
|
||||
module.exports = new FolderUserStore();
|
||||
|
||||
}());
|
||||
Loading…
Add table
Add a link
Reference in a new issue