snappymail/dev/Screens/MailBoxScreen.js

196 lines
4.5 KiB
JavaScript
Raw Normal View History

2014-09-05 06:49:03 +08:00
(function () {
2014-08-25 23:49:01 +08:00
'use strict';
2014-08-20 23:03:12 +08:00
2013-12-13 05:27:22 +08:00
var
2014-08-25 23:49:01 +08:00
_ = require('_'),
2014-08-25 15:10:51 +08:00
2014-09-05 06:49:03 +08:00
Enums = require('Common/Enums'),
Globals = require('Common/Globals'),
Utils = require('Common/Utils'),
Events = require('Common/Events'),
2014-08-21 23:08:34 +08:00
2014-08-27 23:59:44 +08:00
KnoinAbstractScreen = require('Knoin:AbstractScreen'),
2014-08-21 23:08:34 +08:00
2014-08-27 23:59:44 +08:00
Settings = require('Storage:Settings'),
Data = require('Storage:RainLoop:Data'),
Cache = require('Storage:RainLoop:Cache'),
Remote = require('Storage:RainLoop:Remote')
2013-12-13 05:27:22 +08:00
;
2014-08-07 05:10:16 +08:00
2014-08-20 23:03:12 +08:00
/**
* @constructor
* @extends KnoinAbstractScreen
*/
function MailBoxScreen()
{
2014-08-20 23:03:12 +08:00
KnoinAbstractScreen.call(this, 'mailbox', [
2014-08-27 23:59:44 +08:00
require('View:RainLoop:MailBoxSystemDropDown'),
require('View:RainLoop:MailBoxFolderList'),
require('View:RainLoop:MailBoxMessageList'),
require('View:RainLoop:MailBoxMessageView')
2014-08-20 23:03:12 +08:00
]);
this.oLastRoute = {};
}
2014-08-20 23:03:12 +08:00
_.extend(MailBoxScreen.prototype, KnoinAbstractScreen.prototype);
/**
* @type {Object}
*/
MailBoxScreen.prototype.oLastRoute = {};
MailBoxScreen.prototype.setNewTitle = function ()
{
var
2014-08-22 23:08:56 +08:00
sEmail = Data.accountEmail(),
nFoldersInboxUnreadCount = Data.foldersInboxUnreadCount()
;
2014-08-25 15:10:51 +08:00
2014-08-27 23:59:44 +08:00
require('App:RainLoop').setTitle(('' === sEmail ? '' :
2014-08-22 23:08:56 +08:00
(0 < nFoldersInboxUnreadCount ? '(' + nFoldersInboxUnreadCount + ') ' : ' ') + sEmail + ' - ') + Utils.i18n('TITLES/MAILBOX'));
2014-08-20 23:03:12 +08:00
};
2014-08-20 23:03:12 +08:00
MailBoxScreen.prototype.onShow = function ()
{
this.setNewTitle();
2014-08-22 23:08:56 +08:00
Globals.keyScope(Enums.KeyState.MessageList);
2014-08-20 23:03:12 +08:00
};
/**
* @param {string} sFolderHash
* @param {number} iPage
* @param {string} sSearch
* @param {boolean=} bPreview = false
*/
MailBoxScreen.prototype.onRoute = function (sFolderHash, iPage, sSearch, bPreview)
{
if (Utils.isUnd(bPreview) ? false : !!bPreview)
{
2014-08-22 23:08:56 +08:00
if (Enums.Layout.NoPreview === Data.layout() && !Data.message())
2014-08-20 23:03:12 +08:00
{
2014-08-27 23:59:44 +08:00
require('App:RainLoop').historyBack();
2014-08-20 23:03:12 +08:00
}
}
else
{
var
2014-08-21 23:08:34 +08:00
sFolderFullNameRaw = Cache.getFolderFullNameRaw(sFolderHash),
oFolder = Cache.getFolderFromCacheList(sFolderFullNameRaw)
2013-12-16 06:02:03 +08:00
;
2014-08-20 23:03:12 +08:00
if (oFolder)
2013-12-16 06:02:03 +08:00
{
2014-08-22 23:08:56 +08:00
Data
2014-08-20 23:03:12 +08:00
.currentFolder(oFolder)
.messageListPage(iPage)
.messageListSearch(sSearch)
;
2014-08-22 23:08:56 +08:00
if (Enums.Layout.NoPreview === Data.layout() && Data.message())
2014-08-20 23:03:12 +08:00
{
2014-08-22 23:08:56 +08:00
Data.message(null);
2014-08-20 23:03:12 +08:00
}
2014-08-27 23:59:44 +08:00
require('App:RainLoop').reloadMessageList();
2013-12-16 06:02:03 +08:00
}
}
2014-08-20 23:03:12 +08:00
};
2014-08-20 23:03:12 +08:00
MailBoxScreen.prototype.onStart = function ()
{
2014-08-20 23:03:12 +08:00
var
fResizeFunction = function () {
Utils.windowResize();
}
;
2014-08-27 23:59:44 +08:00
if (Settings.capa(Enums.Capa.AdditionalAccounts) || Settings.capa(Enums.Capa.AdditionalIdentities))
{
2014-08-27 23:59:44 +08:00
require('App:RainLoop').accountsAndIdentities();
}
2014-08-20 23:03:12 +08:00
_.delay(function () {
2014-08-22 23:08:56 +08:00
if ('INBOX' !== Data.currentFolderFullNameRaw())
2014-08-20 23:03:12 +08:00
{
2014-08-27 23:59:44 +08:00
require('App:RainLoop').folderInformation('INBOX');
2014-08-20 23:03:12 +08:00
}
}, 1000);
2014-08-20 23:03:12 +08:00
_.delay(function () {
2014-08-27 23:59:44 +08:00
require('App:RainLoop').quota();
2014-08-20 23:03:12 +08:00
}, 5000);
2014-08-20 23:03:12 +08:00
_.delay(function () {
2014-08-21 23:08:34 +08:00
Remote.appDelayStart(Utils.emptyFunction);
2014-08-20 23:03:12 +08:00
}, 35000);
2014-09-02 00:05:32 +08:00
Globals.$html.toggleClass('rl-no-preview-pane', Enums.Layout.NoPreview === Data.layout());
2014-08-22 23:08:56 +08:00
Data.folderList.subscribe(fResizeFunction);
Data.messageList.subscribe(fResizeFunction);
Data.message.subscribe(fResizeFunction);
2014-08-07 05:10:16 +08:00
2014-08-22 23:08:56 +08:00
Data.layout.subscribe(function (nValue) {
2014-09-02 00:05:32 +08:00
Globals.$html.toggleClass('rl-no-preview-pane', Enums.Layout.NoPreview === nValue);
2014-08-20 23:03:12 +08:00
});
2014-08-22 23:08:56 +08:00
Events.sub('mailbox.inbox-unread-count', function (nCount) {
2014-08-25 15:10:51 +08:00
Data.foldersInboxUnreadCount(nCount);
2014-08-22 23:08:56 +08:00
});
Data.foldersInboxUnreadCount.subscribe(function () {
2014-08-20 23:03:12 +08:00
this.setNewTitle();
}, this);
};
2014-08-20 23:03:12 +08:00
/**
* @return {Array}
*/
MailBoxScreen.prototype.routes = function ()
{
var
fNormP = function () {
return ['Inbox', 1, '', true];
},
fNormS = function (oRequest, oVals) {
oVals[0] = Utils.pString(oVals[0]);
oVals[1] = Utils.pInt(oVals[1]);
oVals[1] = 0 >= oVals[1] ? 1 : oVals[1];
oVals[2] = Utils.pString(oVals[2]);
if ('' === oRequest)
{
oVals[0] = 'Inbox';
oVals[1] = 1;
}
return [decodeURI(oVals[0]), oVals[1], decodeURI(oVals[2]), false];
},
fNormD = function (oRequest, oVals) {
oVals[0] = Utils.pString(oVals[0]);
oVals[1] = Utils.pString(oVals[1]);
if ('' === oRequest)
{
oVals[0] = 'Inbox';
}
return [decodeURI(oVals[0]), 1, decodeURI(oVals[1]), false];
}
2014-08-20 23:03:12 +08:00
;
2014-08-20 23:03:12 +08:00
return [
[/^([a-zA-Z0-9]+)\/p([1-9][0-9]*)\/(.+)\/?$/, {'normalize_': fNormS}],
[/^([a-zA-Z0-9]+)\/p([1-9][0-9]*)$/, {'normalize_': fNormS}],
[/^([a-zA-Z0-9]+)\/(.+)\/?$/, {'normalize_': fNormD}],
[/^message-preview$/, {'normalize_': fNormP}],
[/^([^\/]*)$/, {'normalize_': fNormS}]
];
};
module.exports = MailBoxScreen;
2014-09-05 06:49:03 +08:00
}());