snappymail/dev/View/Popup/FolderSystem.js

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