2013-11-16 06:21:12 +08:00
|
|
|
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @constructor
|
|
|
|
* @extends KnoinAbstractViewModel
|
|
|
|
*/
|
|
|
|
function MailBoxFolderListViewModel()
|
|
|
|
{
|
|
|
|
KnoinAbstractViewModel.call(this, 'Left', 'MailFolderList');
|
2014-04-13 08:32:07 +08:00
|
|
|
|
|
|
|
var oData = RL.data();
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-04-13 08:32:07 +08:00
|
|
|
this.messageList = oData.messageList;
|
|
|
|
this.folderList = oData.folderList;
|
|
|
|
this.folderListSystem = oData.folderListSystem;
|
|
|
|
this.foldersChanging = oData.foldersChanging;
|
|
|
|
|
2013-11-16 06:21:12 +08:00
|
|
|
this.iDropOverTimer = 0;
|
|
|
|
|
2013-12-07 05:50:19 +08:00
|
|
|
this.allowContacts = !!RL.settingsGet('ContactsIsAllowed');
|
2013-12-09 23:16:58 +08:00
|
|
|
|
|
|
|
Knoin.constructorEnd(this);
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Utils.extendAsViewModel('MailBoxFolderListViewModel', MailBoxFolderListViewModel);
|
|
|
|
|
|
|
|
MailBoxFolderListViewModel.prototype.onBuild = function (oDom)
|
|
|
|
{
|
2014-04-13 08:32:07 +08:00
|
|
|
var self = this;
|
|
|
|
|
2013-11-16 06:21:12 +08:00
|
|
|
oDom
|
|
|
|
.on('click', '.b-folders .e-item .e-link .e-collapsed-sign', function (oEvent) {
|
2014-04-08 05:03:58 +08:00
|
|
|
|
2014-04-13 08:32:07 +08:00
|
|
|
var
|
2013-11-16 06:21:12 +08:00
|
|
|
oFolder = ko.dataFor(this),
|
|
|
|
bCollapsed = false
|
|
|
|
;
|
2014-04-08 05:03:58 +08:00
|
|
|
|
2013-11-16 06:21:12 +08:00
|
|
|
if (oFolder && oEvent)
|
|
|
|
{
|
|
|
|
bCollapsed = oFolder.collapsed();
|
|
|
|
Utils.setExpandedFolder(oFolder.fullNameHash, bCollapsed);
|
|
|
|
|
|
|
|
oFolder.collapsed(!bCollapsed);
|
|
|
|
oEvent.preventDefault();
|
|
|
|
oEvent.stopPropagation();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.on('click', '.b-folders .e-item .e-link.selectable', function (oEvent) {
|
|
|
|
|
|
|
|
oEvent.preventDefault();
|
|
|
|
|
2014-02-04 04:06:35 +08:00
|
|
|
var
|
|
|
|
oData = RL.data(),
|
|
|
|
oFolder = ko.dataFor(this)
|
|
|
|
;
|
|
|
|
|
2013-11-16 06:21:12 +08:00
|
|
|
if (oFolder)
|
|
|
|
{
|
2014-02-04 04:06:35 +08:00
|
|
|
if (Enums.Layout.NoPreview === oData.layout())
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2014-02-04 04:06:35 +08:00
|
|
|
oData.message(null);
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
|
|
|
|
2014-02-04 04:06:35 +08:00
|
|
|
if (oFolder.fullNameRaw === oData.currentFolderFullNameRaw())
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
|
|
|
RL.cache().setFolderHash(oFolder.fullNameRaw, '');
|
|
|
|
}
|
|
|
|
|
|
|
|
kn.setHash(RL.link().mailBox(oFolder.fullNameHash));
|
|
|
|
}
|
|
|
|
})
|
|
|
|
;
|
2014-04-13 08:32:07 +08:00
|
|
|
|
|
|
|
key('up, down', Enums.KeyState.FolderList, function (event, handler) {
|
|
|
|
|
|
|
|
var
|
|
|
|
iIndex = -1,
|
|
|
|
iKeyCode = handler && 'up' === handler.shortcut ? 38 : 40,
|
|
|
|
$items = $('.b-folders .e-item .e-link:not(.hidden):visible', oDom)
|
|
|
|
;
|
|
|
|
|
|
|
|
if (event && $items.length)
|
|
|
|
{
|
|
|
|
iIndex = $items.index($items.filter('.focused'));
|
|
|
|
if (-1 < iIndex)
|
|
|
|
{
|
|
|
|
$items.eq(iIndex).removeClass('focused');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iKeyCode === 38 && iIndex > 0)
|
|
|
|
{
|
|
|
|
iIndex--;
|
|
|
|
}
|
|
|
|
else if (iKeyCode === 40 && iIndex < $items.length - 1)
|
|
|
|
{
|
|
|
|
iIndex++;
|
|
|
|
}
|
|
|
|
|
|
|
|
$items.eq(iIndex).addClass('focused');
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
key('enter', Enums.KeyState.FolderList, function () {
|
|
|
|
var $items = $('.b-folders .e-item .e-link:not(.hidden).focused', oDom);
|
|
|
|
if ($items.length && $items[0])
|
|
|
|
{
|
|
|
|
self.folderList.focused(false);
|
|
|
|
$items.click();
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
key('esc, tab, shift+tab', Enums.KeyState.FolderList, function () {
|
|
|
|
self.folderList.focused(false);
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
self.folderList.focused.subscribe(function (bValue) {
|
|
|
|
$('.b-folders .e-item .e-link.focused', oDom).removeClass('focused');
|
|
|
|
if (bValue)
|
|
|
|
{
|
|
|
|
$('.b-folders .e-item .e-link.selected', oDom).addClass('focused');
|
|
|
|
}
|
|
|
|
});
|
2013-11-16 06:21:12 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
MailBoxFolderListViewModel.prototype.messagesDropOver = function (oFolder)
|
|
|
|
{
|
|
|
|
window.clearTimeout(this.iDropOverTimer);
|
|
|
|
if (oFolder && oFolder.collapsed())
|
|
|
|
{
|
|
|
|
this.iDropOverTimer = window.setTimeout(function () {
|
|
|
|
oFolder.collapsed(false);
|
|
|
|
Utils.setExpandedFolder(oFolder.fullNameHash, true);
|
|
|
|
Utils.windowResize();
|
|
|
|
}, 500);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
MailBoxFolderListViewModel.prototype.messagesDropOut = function ()
|
|
|
|
{
|
|
|
|
window.clearTimeout(this.iDropOverTimer);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {FolderModel} oToFolder
|
|
|
|
* @param {{helper:jQuery}} oUi
|
|
|
|
*/
|
|
|
|
MailBoxFolderListViewModel.prototype.messagesDrop = function (oToFolder, oUi)
|
|
|
|
{
|
|
|
|
if (oToFolder && oUi && oUi.helper)
|
|
|
|
{
|
|
|
|
var
|
|
|
|
sFromFolderFullNameRaw = oUi.helper.data('rl-folder'),
|
2013-12-09 05:32:19 +08:00
|
|
|
bCopy = '1' === oUi.helper.data('rl-copy'),
|
2013-11-16 06:21:12 +08:00
|
|
|
aUids = oUi.helper.data('rl-uids')
|
|
|
|
;
|
|
|
|
|
2014-03-20 00:18:28 +08:00
|
|
|
if (Utils.isNormal(sFromFolderFullNameRaw) && '' !== sFromFolderFullNameRaw && Utils.isArray(aUids))
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2014-03-20 00:18:28 +08:00
|
|
|
RL.moveMessagesToFolder(sFromFolderFullNameRaw, aUids, oToFolder.fullNameRaw, bCopy);
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
MailBoxFolderListViewModel.prototype.composeClick = function ()
|
|
|
|
{
|
|
|
|
kn.showScreenPopup(PopupsComposeViewModel);
|
|
|
|
};
|
|
|
|
|
2014-02-08 06:35:48 +08:00
|
|
|
MailBoxFolderListViewModel.prototype.createFolder = function ()
|
|
|
|
{
|
|
|
|
kn.showScreenPopup(PopupsFolderCreateViewModel);
|
|
|
|
};
|
|
|
|
|
|
|
|
MailBoxFolderListViewModel.prototype.configureFolders = function ()
|
|
|
|
{
|
|
|
|
kn.setHash(RL.link().settings('folders'));
|
|
|
|
};
|
|
|
|
|
2013-11-16 06:21:12 +08:00
|
|
|
MailBoxFolderListViewModel.prototype.contactsClick = function ()
|
|
|
|
{
|
|
|
|
if (this.allowContacts)
|
|
|
|
{
|
|
|
|
kn.showScreenPopup(PopupsContactsViewModel);
|
|
|
|
}
|
|
|
|
};
|