2013-11-16 06:21:12 +08:00
|
|
|
|
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-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
|
|
|
|
2014-09-06 05:44:29 +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
|
2014-09-06 05:44:29 +08:00
|
|
|
* @extends AbstractScreen
|
2014-08-20 23:03:12 +08:00
|
|
|
*/
|
2014-10-18 21:43:44 +08:00
|
|
|
function MailBoxUserScreen()
|
2014-02-03 23:54:05 +08:00
|
|
|
{
|
2014-09-06 05:44:29 +08:00
|
|
|
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-02-03 23:54:05 +08:00
|
|
|
}
|
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 ()
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2014-02-03 23:54:05 +08:00
|
|
|
var
|
2014-08-22 23:08:56 +08:00
|
|
|
sEmail = Data.accountEmail(),
|
|
|
|
nFoldersInboxUnreadCount = Data.foldersInboxUnreadCount()
|
2014-02-03 23:54:05 +08:00
|
|
|
;
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2014-10-18 21:43:44 +08:00
|
|
|
require('App/User').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-02-03 23:54:05 +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)
|
2014-02-03 23:54:05 +08:00
|
|
|
{
|
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-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
|
|
|
;
|
2013-11-16 06:21:12 +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-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
|
|
|
};
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-10-18 21:43:44 +08:00
|
|
|
MailBoxUserScreen.prototype.onStart = function ()
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2014-08-20 23:03:12 +08:00
|
|
|
var
|
|
|
|
fResizeFunction = function () {
|
|
|
|
Utils.windowResize();
|
|
|
|
}
|
|
|
|
;
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-09-02 00:05:32 +08:00
|
|
|
Globals.$html.toggleClass('rl-no-preview-pane', Enums.Layout.NoPreview === Data.layout());
|
2015-01-05 03:30:07 +08:00
|
|
|
Globals.$html.toggleClass('rl-bottom-preview-pane', Enums.Layout.BottomPreview === Data.layout());
|
2013-11-16 06:21:12 +08:00
|
|
|
|
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);
|
2015-01-05 03:30:07 +08:00
|
|
|
Globals.$html.toggleClass('rl-bottom-preview-pane', Enums.Layout.BottomPreview === nValue);
|
2014-08-20 23:03:12 +08:00
|
|
|
});
|
2013-11-16 06:21: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);
|
|
|
|
};
|
2013-11-16 06:21: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
|
2014-10-18 05:02:19 +08:00
|
|
|
sInboxFolderName = Cache.getFolderInboxName(),
|
2014-08-20 23:03:12 +08:00
|
|
|
fNormP = function () {
|
2014-10-18 05:02:19 +08:00
|
|
|
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)
|
|
|
|
{
|
2014-10-18 05:02:19 +08:00
|
|
|
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)
|
|
|
|
{
|
2014-10-18 05:02:19 +08:00
|
|
|
oVals[0] = sInboxFolderName;
|
2014-08-20 23:03:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return [decodeURI(oVals[0]), 1, decodeURI(oVals[1]), false];
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
2014-08-20 23:03:12 +08:00
|
|
|
;
|
2013-11-16 06:21: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;
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
}());
|