snappymail/dev/Screen/User/MailBox.js

193 lines
4.4 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'),
Translator = require('Common/Translator'),
AccountStore = require('Stores/User/Account'),
SettingsStore = require('Stores/User/Settings'),
2014-08-21 23:08:34 +08:00
2014-10-18 21:43:44 +08:00
Data = require('Storage/User/Data'),
Cache = require('Storage/User/Cache'),
2014-08-21 23:08:34 +08:00
AbstractScreen = require('Knoin/AbstractScreen')
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 AbstractScreen
2014-08-20 23:03:12 +08:00
*/
2014-10-18 21:43:44 +08:00
function MailBoxUserScreen()
{
AbstractScreen.call(this, 'mailbox', [
2014-10-18 21:43:44 +08:00
require('View/User/MailBox/SystemDropDown'),
require('View/User/MailBox/FolderList'),
require('View/User/MailBox/MessageList'),
require('View/User/MailBox/MessageView')
2014-08-20 23:03:12 +08:00
]);
this.oLastRoute = {};
}
2014-08-20 23:03:12 +08:00
2014-10-18 21:43:44 +08:00
_.extend(MailBoxUserScreen.prototype, AbstractScreen.prototype);
2014-08-20 23:03:12 +08:00
/**
* @type {Object}
*/
2014-10-18 21:43:44 +08:00
MailBoxUserScreen.prototype.oLastRoute = {};
2014-08-20 23:03:12 +08:00
2014-10-18 21:43:44 +08:00
MailBoxUserScreen.prototype.setNewTitle = function ()
{
var
2015-02-03 07:58:58 +08:00
sEmail = AccountStore.email(),
2014-08-22 23:08:56 +08:00
nFoldersInboxUnreadCount = Data.foldersInboxUnreadCount()
;
2014-08-25 15:10:51 +08:00
2014-10-18 21:43:44 +08:00
require('App/User').setTitle(('' === sEmail ? '' :
(0 < nFoldersInboxUnreadCount ? '(' + nFoldersInboxUnreadCount + ') ' : ' ') +
sEmail + ' - ') + Translator.i18n('TITLES/MAILBOX'));
2014-08-20 23:03:12 +08:00
};
2014-10-18 21:43:44 +08:00
MailBoxUserScreen.prototype.onShow = function ()
2014-08-20 23:03:12 +08:00
{
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
*/
2014-10-18 21:43:44 +08:00
MailBoxUserScreen.prototype.onRoute = function (sFolderHash, iPage, sSearch, bPreview)
2014-08-20 23:03:12 +08:00
{
if (Utils.isUnd(bPreview) ? false : !!bPreview)
{
if (Enums.Layout.NoPreview === SettingsStore.layout() && !Data.message())
2014-08-20 23:03:12 +08:00
{
2014-10-18 21:43:44 +08:00
require('App/User').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)
;
if (Enums.Layout.NoPreview === SettingsStore.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-10-18 21:43:44 +08:00
require('App/User').reloadMessageList();
2013-12-16 06:02:03 +08:00
}
}
2014-08-20 23:03:12 +08:00
};
2014-10-18 21:43:44 +08:00
MailBoxUserScreen.prototype.onStart = function ()
{
Data.folderList.subscribe(Utils.windowResizeCallback);
Data.messageList.subscribe(Utils.windowResizeCallback);
Data.message.subscribe(Utils.windowResizeCallback);
2014-08-07 05:10:16 +08:00
_.delay(function () {
SettingsStore.layout.valueHasMutated();
}, 50);
2015-01-09 07:31:31 +08:00
Events.sub('mailbox.inbox-unread-count', function (iCount) {
2015-02-03 07:58:58 +08:00
Data.foldersInboxUnreadCount(iCount);
2015-02-03 07:58:58 +08:00
var sEmail = AccountStore.email();
_.each(AccountStore.accounts(), function (oItem) {
if (oItem && sEmail === oItem.email)
{
oItem.count(iCount);
}
});
2014-08-22 23:08:56 +08:00
});
Data.foldersInboxUnreadCount.subscribe(function () {
2014-08-20 23:03:12 +08:00
this.setNewTitle();
}, this);
2015-01-09 07:31:31 +08:00
};
MailBoxUserScreen.prototype.onBuild = function ()
{
if (!Globals.bMobileDevice)
{
_.defer(function () {
require('App/User').initHorizontalLayoutResizer(Enums.ClientSideKeyName.MessageListSize);
});
}
2014-08-20 23:03:12 +08:00
};
2014-08-20 23:03:12 +08:00
/**
* @return {Array}
*/
2014-10-18 21:43:44 +08:00
MailBoxUserScreen.prototype.routes = function ()
2014-08-20 23:03:12 +08:00
{
var
sInboxFolderName = Cache.getFolderInboxName(),
2014-08-20 23:03:12 +08:00
fNormP = function () {
return [sInboxFolderName, 1, '', true];
2014-08-20 23:03:12 +08:00
},
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] = sInboxFolderName;
2014-08-20 23:03:12 +08:00
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] = sInboxFolderName;
2014-08-20 23:03:12 +08:00
}
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}]
];
};
2014-10-18 21:43:44 +08:00
module.exports = MailBoxUserScreen;
2014-09-05 06:49:03 +08:00
}());