snappymail/dev/View/Popup/FolderSystem.js

131 lines
4.1 KiB
JavaScript
Raw Normal View History

2016-06-30 08:02:45 +08:00
var
_ = require('_'),
ko = require('ko'),
2016-06-30 08:02:45 +08:00
Enums = require('Common/Enums'),
Consts = require('Common/Consts'),
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
FolderStore = require('Stores/User/Folder'),
Settings = require('Storage/Settings'),
Remote = require('Remote/User/Ajax'),
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView');
/**
* @constructor
* @extends AbstractView
*/
function FolderSystemPopupView()
{
AbstractView.call(this, 'Popups', 'PopupsFolderSystem');
2016-07-07 07:11:13 +08:00
Translator.initOnStartOrLangChange(_.bind(function() {
2016-06-30 08:02:45 +08:00
this.sChooseOnText = Translator.i18n('POPUPS_SYSTEM_FOLDERS/SELECT_CHOOSE_ONE');
this.sUnuseText = Translator.i18n('POPUPS_SYSTEM_FOLDERS/SELECT_UNUSE_NAME');
2016-07-07 07:11:13 +08:00
}, this));
2016-06-30 08:02:45 +08:00
this.notification = ko.observable('');
this.folderSelectList = ko.computed(function() {
return Utils.folderListOptionsBuilder([], FolderStore.folderList(), FolderStore.folderListSystemNames(), [
['', this.sChooseOnText],
[Consts.UNUSED_OPTION_VALUE, this.sUnuseText]
], null, null, null, null, null, true);
}, this);
2014-08-21 23:08:34 +08:00
var
2016-06-30 08:02:45 +08:00
fSaveSystemFolders = null,
fCallback = null;
this.sentFolder = FolderStore.sentFolder;
this.draftFolder = FolderStore.draftFolder;
this.spamFolder = FolderStore.spamFolder;
this.trashFolder = FolderStore.trashFolder;
this.archiveFolder = FolderStore.archiveFolder;
fSaveSystemFolders = _.debounce(function() {
Settings.settingsSet('SentFolder', FolderStore.sentFolder());
Settings.settingsSet('DraftFolder', FolderStore.draftFolder());
Settings.settingsSet('SpamFolder', FolderStore.spamFolder());
Settings.settingsSet('TrashFolder', FolderStore.trashFolder());
Settings.settingsSet('ArchiveFolder', FolderStore.archiveFolder());
Remote.saveSystemFolders(Utils.noop, {
'SentFolder': FolderStore.sentFolder(),
'DraftFolder': FolderStore.draftFolder(),
'SpamFolder': FolderStore.spamFolder(),
'TrashFolder': FolderStore.trashFolder(),
'ArchiveFolder': FolderStore.archiveFolder(),
'NullFolder': 'NullFolder'
});
2016-07-06 03:52:52 +08:00
}, Enums.Magics.Time1s);
2016-06-30 08:02:45 +08:00
fCallback = function() {
Settings.settingsSet('SentFolder', FolderStore.sentFolder());
Settings.settingsSet('DraftFolder', FolderStore.draftFolder());
Settings.settingsSet('SpamFolder', FolderStore.spamFolder());
Settings.settingsSet('TrashFolder', FolderStore.trashFolder());
Settings.settingsSet('ArchiveFolder', FolderStore.archiveFolder());
fSaveSystemFolders();
};
2014-08-25 15:10:51 +08:00
2016-06-30 08:02:45 +08:00
FolderStore.sentFolder.subscribe(fCallback);
FolderStore.draftFolder.subscribe(fCallback);
FolderStore.spamFolder.subscribe(fCallback);
FolderStore.trashFolder.subscribe(fCallback);
FolderStore.archiveFolder.subscribe(fCallback);
2016-06-30 08:02:45 +08:00
this.defautOptionsAfterRender = Utils.defautOptionsAfterRender;
2015-02-03 07:58:58 +08:00
2016-06-30 08:02:45 +08:00
kn.constructorEnd(this);
}
2016-06-30 08:02:45 +08:00
kn.extendAsViewModel(['View/Popup/FolderSystem', 'PopupsFolderSystemViewModel'], FolderSystemPopupView);
_.extend(FolderSystemPopupView.prototype, AbstractView.prototype);
2016-06-30 08:02:45 +08:00
FolderSystemPopupView.prototype.sChooseOnText = '';
FolderSystemPopupView.prototype.sUnuseText = '';
2016-06-30 08:02:45 +08:00
/**
* @param {number=} iNotificationType = Enums.SetSystemFoldersNotification.None
*/
FolderSystemPopupView.prototype.onShow = function(iNotificationType)
{
var sNotification = '';
2016-06-30 08:02:45 +08:00
iNotificationType = Utils.isUnd(iNotificationType) ? Enums.SetSystemFoldersNotification.None : iNotificationType;
2016-06-30 08:02:45 +08:00
switch (iNotificationType)
{
2016-06-30 08:02:45 +08:00
case Enums.SetSystemFoldersNotification.Sent:
sNotification = Translator.i18n('POPUPS_SYSTEM_FOLDERS/NOTIFICATION_SENT');
break;
case Enums.SetSystemFoldersNotification.Draft:
sNotification = Translator.i18n('POPUPS_SYSTEM_FOLDERS/NOTIFICATION_DRAFTS');
break;
case Enums.SetSystemFoldersNotification.Spam:
sNotification = Translator.i18n('POPUPS_SYSTEM_FOLDERS/NOTIFICATION_SPAM');
break;
case Enums.SetSystemFoldersNotification.Trash:
sNotification = Translator.i18n('POPUPS_SYSTEM_FOLDERS/NOTIFICATION_TRASH');
break;
case Enums.SetSystemFoldersNotification.Archive:
sNotification = Translator.i18n('POPUPS_SYSTEM_FOLDERS/NOTIFICATION_ARCHIVE');
break;
// no default
}
2016-06-30 08:02:45 +08:00
this.notification(sNotification);
};
2016-06-30 08:02:45 +08:00
module.exports = FolderSystemPopupView;