snappymail/dev/Screens/MailBox.js

197 lines
4.8 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'),
Utils = require('../Common/Utils.js'),
KnoinAbstractScreen = require('../Knoin/KnoinAbstractScreen.js'),
Cache = require('../Storages/WebMailCacheStorage.js'),
Remote = require('../Storages/WebMailAjaxRemoteStorage.js'),
MailBoxSystemDropDownViewModel = require('../ViewModels/MailBoxSystemDropDownViewModel.js'),
MailBoxFolderListViewModel = require('../ViewModels/MailBoxFolderListViewModel.js'),
MailBoxMessageListViewModel = require('../ViewModels/MailBoxMessageListViewModel.js'),
MailBoxMessageViewViewModel = require('../ViewModels/MailBoxMessageViewViewModel.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-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-20 23:03:12 +08:00
sEmail = RL.data().accountEmail(), // TODO cjs
ifoldersInboxUnreadCount = RL.data().foldersInboxUnreadCount() // TODO cjs
;
2014-08-20 23:03:12 +08:00
// TODO cjs
RL.setTitle(('' === sEmail ? '' :
(0 < ifoldersInboxUnreadCount ? '(' + ifoldersInboxUnreadCount + ') ' : ' ') + sEmail + ' - ') + Utils.i18n('TITLES/MAILBOX'));
};
2014-08-20 23:03:12 +08:00
MailBoxScreen.prototype.onShow = function ()
{
this.setNewTitle();
RL.data().keyScope(Enums.KeyState.MessageList);// TODO cjs
};
/**
* @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-20 23:03:12 +08:00
if (Enums.Layout.NoPreview === RL.data().layout() && !RL.data().message())// TODO cjs
{
RL.historyBack();// TODO cjs
}
}
else
{
var
oData = RL.data(),// TODO cjs
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-20 23:03:12 +08:00
oData
.currentFolder(oFolder)
.messageListPage(iPage)
.messageListSearch(sSearch)
;
if (Enums.Layout.NoPreview === oData.layout() && oData.message())
{
oData.message(null);
}
RL.reloadMessageList();// TODO cjs
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
oData = RL.data(),// TODO cjs
fResizeFunction = function () {
Utils.windowResize();
}
;
2014-08-20 23:03:12 +08:00
if (RL.capa(Enums.Capa.AdditionalAccounts) || RL.capa(Enums.Capa.AdditionalIdentities))// TODO cjs
{
2014-08-20 23:03:12 +08:00
RL.accountsAndIdentities();// TODO cjs
}
2014-08-20 23:03:12 +08:00
_.delay(function () {
if ('INBOX' !== oData.currentFolderFullNameRaw())
{
RL.folderInformation('INBOX');// TODO cjs
}
}, 1000);
2014-08-20 23:03:12 +08:00
_.delay(function () {
RL.quota();// TODO cjs
}, 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-20 23:03:12 +08:00
$html.toggleClass('rl-no-preview-pane', Enums.Layout.NoPreview === oData.layout());
2014-08-20 23:03:12 +08:00
oData.folderList.subscribe(fResizeFunction);
oData.messageList.subscribe(fResizeFunction);
oData.message.subscribe(fResizeFunction);
2014-08-07 05:10:16 +08:00
2014-08-20 23:03:12 +08:00
oData.layout.subscribe(function (nValue) {
$html.toggleClass('rl-no-preview-pane', Enums.Layout.NoPreview === nValue);
});
2014-08-20 23:03:12 +08:00
oData.foldersInboxUnreadCount.subscribe(function () {
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));