snappymail/dev/Screens/MailBoxScreen.js

208 lines
5 KiB
JavaScript
Raw Normal View History

/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
2014-08-20 23:03:12 +08:00
(function (module) {
'use strict';
2013-12-13 05:27:22 +08:00
var
2014-08-21 23:08:34 +08:00
_ = require('../External/underscore.js'),
$html = require('../External/$html.js'),
Enums = require('../Common/Enums.js'),
2014-08-22 23:08:56 +08:00
Globals = require('../Common/Globals.js'),
2014-08-21 23:08:34 +08:00
Utils = require('../Common/Utils.js'),
2014-08-22 23:08:56 +08:00
Events = require('../Common/Events.js'),
2014-08-21 23:08:34 +08:00
KnoinAbstractScreen = require('../Knoin/KnoinAbstractScreen.js'),
2014-08-22 23:08:56 +08:00
AppSettings = require('../Storages/AppSettings.js'),
Data = require('../Storages/WebMailDataStorage.js'),
2014-08-21 23:08:34 +08:00
Cache = require('../Storages/WebMailCacheStorage.js'),
2014-08-22 23:08:56 +08:00
Remote = require('../Storages/WebMailAjaxRemoteStorage.js')
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-22 23:08:56 +08:00
var
MailBoxSystemDropDownViewModel = require('../ViewModels/MailBoxSystemDropDownViewModel.js'),
MailBoxFolderListViewModel = require('../ViewModels/MailBoxFolderListViewModel.js'),
MailBoxMessageListViewModel = require('../ViewModels/MailBoxMessageListViewModel.js'),
MailBoxMessageViewViewModel = require('../ViewModels/MailBoxMessageViewViewModel.js')
;
2014-08-20 23:03:12 +08:00
KnoinAbstractScreen.call(this, 'mailbox', [
MailBoxSystemDropDownViewModel,
MailBoxFolderListViewModel,
MailBoxMessageListViewModel,
MailBoxMessageViewViewModel
]);
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
RL = require('../Boots/RainLoopApp.js'),
sEmail = Data.accountEmail(),
nFoldersInboxUnreadCount = Data.foldersInboxUnreadCount()
;
2014-08-22 23:08:56 +08:00
2014-08-20 23:03:12 +08:00
RL.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)
{
2014-08-22 23:08:56 +08:00
var RL = require('../Boots/RainLoopApp.js');
2014-08-20 23:03:12 +08:00
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-22 23:08:56 +08:00
RL.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-22 23:08:56 +08:00
RL.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
2014-08-22 23:08:56 +08:00
RL = require('../Boots/RainLoopApp.js'),
2014-08-20 23:03:12 +08:00
fResizeFunction = function () {
Utils.windowResize();
}
;
2014-08-22 23:08:56 +08:00
if (AppSettings.capa(Enums.Capa.AdditionalAccounts) || AppSettings.capa(Enums.Capa.AdditionalIdentities))
{
2014-08-22 23:08:56 +08:00
RL.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-22 23:08:56 +08:00
RL.folderInformation('INBOX');
2014-08-20 23:03:12 +08:00
}
}, 1000);
2014-08-20 23:03:12 +08:00
_.delay(function () {
2014-08-22 23:08:56 +08:00
RL.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-08-22 23:08:56 +08:00
$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-08-20 23:03:12 +08:00
$html.toggleClass('rl-no-preview-pane', Enums.Layout.NoPreview === nValue);
});
2014-08-22 23:08:56 +08:00
Events.sub('mailbox.inbox-unread-count', function (nCount) {
Data.foldersInboxUnreadCount(nCount)
});
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-08-20 23:03:12 +08:00
}(module));