2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
(function (module, require) {
|
2014-09-02 08:15:31 +08:00
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
'use strict';
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
var
|
2014-09-02 08:15:31 +08:00
|
|
|
_ = require('_'),
|
2014-08-25 23:49:01 +08:00
|
|
|
ko = require('ko'),
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
Enums = require('Enums'),
|
|
|
|
Consts = require('Consts'),
|
|
|
|
Utils = require('Utils'),
|
2013-12-09 23:16:58 +08:00
|
|
|
|
2014-08-27 23:59:44 +08:00
|
|
|
Settings = require('Storage:Settings'),
|
|
|
|
Data = require('Storage:RainLoop:Data'),
|
|
|
|
Remote = require('Storage:RainLoop:Remote'),
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-27 23:59:44 +08:00
|
|
|
kn = require('App:Knoin'),
|
|
|
|
KnoinAbstractViewModel = require('Knoin:AbstractViewModel')
|
2014-08-21 23:08:34 +08:00
|
|
|
;
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
/**
|
|
|
|
* @constructor
|
|
|
|
* @extends KnoinAbstractViewModel
|
|
|
|
*/
|
|
|
|
function PopupsFolderSystemViewModel()
|
|
|
|
{
|
|
|
|
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsFolderSystem');
|
|
|
|
|
|
|
|
Utils.initOnStartOrLangChange(function () {
|
|
|
|
this.sChooseOnText = Utils.i18n('POPUPS_SYSTEM_FOLDERS/SELECT_CHOOSE_ONE');
|
|
|
|
this.sUnuseText = Utils.i18n('POPUPS_SYSTEM_FOLDERS/SELECT_UNUSE_NAME');
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
this.notification = ko.observable('');
|
|
|
|
|
|
|
|
this.folderSelectList = ko.computed(function () {
|
2014-08-22 23:08:56 +08:00
|
|
|
return Utils.folderListOptionsBuilder([], Data.folderList(), Data.folderListSystemNames(), [
|
2014-08-21 23:08:34 +08:00
|
|
|
['', this.sChooseOnText],
|
|
|
|
[Consts.Values.UnuseOptionValue, this.sUnuseText]
|
|
|
|
]);
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
var
|
|
|
|
self = this,
|
|
|
|
fSaveSystemFolders = null,
|
|
|
|
fCallback = null
|
|
|
|
;
|
|
|
|
|
|
|
|
this.sentFolder = Data.sentFolder;
|
|
|
|
this.draftFolder = Data.draftFolder;
|
|
|
|
this.spamFolder = Data.spamFolder;
|
|
|
|
this.trashFolder = Data.trashFolder;
|
|
|
|
this.archiveFolder = Data.archiveFolder;
|
|
|
|
|
|
|
|
fSaveSystemFolders = _.debounce(function () {
|
|
|
|
|
2014-08-27 23:59:44 +08:00
|
|
|
Settings.settingsSet('SentFolder', self.sentFolder());
|
|
|
|
Settings.settingsSet('DraftFolder', self.draftFolder());
|
|
|
|
Settings.settingsSet('SpamFolder', self.spamFolder());
|
|
|
|
Settings.settingsSet('TrashFolder', self.trashFolder());
|
|
|
|
Settings.settingsSet('ArchiveFolder', self.archiveFolder());
|
2014-08-21 23:08:34 +08:00
|
|
|
|
|
|
|
Remote.saveSystemFolders(Utils.emptyFunction, {
|
|
|
|
'SentFolder': self.sentFolder(),
|
|
|
|
'DraftFolder': self.draftFolder(),
|
|
|
|
'SpamFolder': self.spamFolder(),
|
|
|
|
'TrashFolder': self.trashFolder(),
|
|
|
|
'ArchiveFolder': self.archiveFolder(),
|
|
|
|
'NullFolder': 'NullFolder'
|
|
|
|
});
|
|
|
|
|
|
|
|
}, 1000);
|
|
|
|
|
|
|
|
fCallback = function () {
|
|
|
|
|
2014-08-27 23:59:44 +08:00
|
|
|
Settings.settingsSet('SentFolder', self.sentFolder());
|
|
|
|
Settings.settingsSet('DraftFolder', self.draftFolder());
|
|
|
|
Settings.settingsSet('SpamFolder', self.spamFolder());
|
|
|
|
Settings.settingsSet('TrashFolder', self.trashFolder());
|
|
|
|
Settings.settingsSet('ArchiveFolder', self.archiveFolder());
|
2014-08-21 23:08:34 +08:00
|
|
|
|
|
|
|
fSaveSystemFolders();
|
|
|
|
};
|
|
|
|
|
|
|
|
this.sentFolder.subscribe(fCallback);
|
|
|
|
this.draftFolder.subscribe(fCallback);
|
|
|
|
this.spamFolder.subscribe(fCallback);
|
|
|
|
this.trashFolder.subscribe(fCallback);
|
|
|
|
this.archiveFolder.subscribe(fCallback);
|
|
|
|
|
|
|
|
this.defautOptionsAfterRender = Utils.defautOptionsAfterRender;
|
|
|
|
|
|
|
|
kn.constructorEnd(this);
|
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-09-02 08:15:31 +08:00
|
|
|
kn.extendAsViewModel(['View:Popup:FolderSystem', 'PopupsFolderSystemViewModel'], PopupsFolderSystemViewModel);
|
|
|
|
_.extend(PopupsFolderSystemViewModel.prototype, KnoinAbstractViewModel.prototype);
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
PopupsFolderSystemViewModel.prototype.sChooseOnText = '';
|
|
|
|
PopupsFolderSystemViewModel.prototype.sUnuseText = '';
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
/**
|
|
|
|
* @param {number=} iNotificationType = Enums.SetSystemFoldersNotification.None
|
|
|
|
*/
|
|
|
|
PopupsFolderSystemViewModel.prototype.onShow = function (iNotificationType)
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
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 = Utils.i18n('POPUPS_SYSTEM_FOLDERS/NOTIFICATION_SENT');
|
|
|
|
break;
|
|
|
|
case Enums.SetSystemFoldersNotification.Draft:
|
|
|
|
sNotification = Utils.i18n('POPUPS_SYSTEM_FOLDERS/NOTIFICATION_DRAFTS');
|
|
|
|
break;
|
|
|
|
case Enums.SetSystemFoldersNotification.Spam:
|
|
|
|
sNotification = Utils.i18n('POPUPS_SYSTEM_FOLDERS/NOTIFICATION_SPAM');
|
|
|
|
break;
|
|
|
|
case Enums.SetSystemFoldersNotification.Trash:
|
|
|
|
sNotification = Utils.i18n('POPUPS_SYSTEM_FOLDERS/NOTIFICATION_TRASH');
|
|
|
|
break;
|
|
|
|
case Enums.SetSystemFoldersNotification.Archive:
|
|
|
|
sNotification = Utils.i18n('POPUPS_SYSTEM_FOLDERS/NOTIFICATION_ARCHIVE');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.notification(sNotification);
|
|
|
|
};
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-22 23:08:56 +08:00
|
|
|
module.exports = PopupsFolderSystemViewModel;
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
}(module, require));
|