snappymail/dev/Settings/User/General.js

173 lines
4.4 KiB
JavaScript
Raw Normal View History

2014-08-21 23:08:34 +08:00
2014-09-05 06:49:03 +08:00
(function () {
2014-08-21 23:08:34 +08:00
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'),
Globals = require('Common/Globals'),
Utils = require('Common/Utils'),
2014-08-21 23:08:34 +08:00
2014-10-18 21:43:44 +08:00
Data = require('Storage/User/Data'),
Remote = require('Storage/User/Remote')
2014-08-21 23:08:34 +08:00
;
/**
* @constructor
*/
2014-10-18 21:43:44 +08:00
function GeneralUserSetting()
2014-08-21 23:08:34 +08:00
{
2014-08-22 23:08:56 +08:00
this.mainLanguage = Data.mainLanguage;
this.mainMessagesPerPage = Data.mainMessagesPerPage;
2014-08-21 23:08:34 +08:00
this.mainMessagesPerPageArray = Consts.Defaults.MessagesPerPageArray;
2014-08-22 23:08:56 +08:00
this.editorDefaultType = Data.editorDefaultType;
this.showImages = Data.showImages;
this.interfaceAnimation = Data.interfaceAnimation;
this.useDesktopNotifications = Data.useDesktopNotifications;
this.threading = Data.threading;
this.useThreads = Data.useThreads;
this.replySameFolder = Data.replySameFolder;
this.layout = Data.layout;
this.usePreviewPane = Data.usePreviewPane;
this.useCheckboxesInList = Data.useCheckboxesInList;
this.allowLanguagesOnSettings = Data.allowLanguagesOnSettings;
2014-08-21 23:08:34 +08:00
this.isDesktopNotificationsSupported = ko.computed(function () {
2014-08-22 23:08:56 +08:00
return Enums.DesktopNotifications.NotSupported !== Data.desktopNotificationsPermisions();
2014-08-21 23:08:34 +08:00
});
this.isDesktopNotificationsDenied = ko.computed(function () {
2014-08-22 23:08:56 +08:00
return Enums.DesktopNotifications.NotSupported === Data.desktopNotificationsPermisions() ||
Enums.DesktopNotifications.Denied === Data.desktopNotificationsPermisions();
2014-08-21 23:08:34 +08:00
});
this.mainLanguageFullName = ko.computed(function () {
return Utils.convertLangName(this.mainLanguage());
}, this);
this.languageTrigger = ko.observable(Enums.SaveSettingsStep.Idle).extend({'throttle': 100});
this.mppTrigger = ko.observable(Enums.SaveSettingsStep.Idle);
this.isAnimationSupported = Globals.bAnimationSupported;
}
2014-10-18 21:43:44 +08:00
GeneralUserSetting.prototype.toggleLayout = function ()
2014-08-21 23:08:34 +08:00
{
this.layout(Enums.Layout.NoPreview === this.layout() ? Enums.Layout.SidePreview : Enums.Layout.NoPreview);
};
2014-10-18 21:43:44 +08:00
GeneralUserSetting.prototype.onBuild = function ()
2014-08-21 23:08:34 +08:00
{
var self = this;
_.delay(function () {
var
2014-09-30 04:01:31 +08:00
f1 = Utils.settingsSaveHelperSimpleFunction(self.mppTrigger, self),
fReloadLanguageHelper = function (iSaveSettingsStep) {
return function() {
self.languageTrigger(iSaveSettingsStep);
_.delay(function () {
self.languageTrigger(Enums.SaveSettingsStep.Idle);
}, 1000);
};
}
2014-08-21 23:08:34 +08:00
;
2014-08-22 23:08:56 +08:00
Data.language.subscribe(function (sValue) {
2014-08-21 23:08:34 +08:00
self.languageTrigger(Enums.SaveSettingsStep.Animate);
2014-09-30 04:01:31 +08:00
Utils.reloadLanguage(sValue,
fReloadLanguageHelper(Enums.SaveSettingsStep.TrueResult),
fReloadLanguageHelper(Enums.SaveSettingsStep.FalseResult));
2014-08-21 23:08:34 +08:00
Remote.saveSettings(null, {
2014-08-21 23:08:34 +08:00
'Language': sValue
});
});
2014-08-22 23:08:56 +08:00
Data.editorDefaultType.subscribe(function (sValue) {
Remote.saveSettings(null, {
2014-08-21 23:08:34 +08:00
'EditorDefaultType': sValue
});
});
2014-08-22 23:08:56 +08:00
Data.messagesPerPage.subscribe(function (iValue) {
2014-08-21 23:08:34 +08:00
Remote.saveSettings(f1, {
'MPP': iValue
});
});
2014-08-22 23:08:56 +08:00
Data.showImages.subscribe(function (bValue) {
Remote.saveSettings(null, {
2014-08-21 23:08:34 +08:00
'ShowImages': bValue ? '1' : '0'
});
});
2014-08-22 23:08:56 +08:00
Data.interfaceAnimation.subscribe(function (sValue) {
Remote.saveSettings(null, {
2014-08-21 23:08:34 +08:00
'InterfaceAnimation': sValue
});
});
2014-08-22 23:08:56 +08:00
Data.useDesktopNotifications.subscribe(function (bValue) {
2014-08-21 23:08:34 +08:00
Utils.timeOutAction('SaveDesktopNotifications', function () {
Remote.saveSettings(null, {
2014-08-21 23:08:34 +08:00
'DesktopNotifications': bValue ? '1' : '0'
});
}, 3000);
});
2014-08-22 23:08:56 +08:00
Data.replySameFolder.subscribe(function (bValue) {
2014-08-21 23:08:34 +08:00
Utils.timeOutAction('SaveReplySameFolder', function () {
Remote.saveSettings(null, {
2014-08-21 23:08:34 +08:00
'ReplySameFolder': bValue ? '1' : '0'
});
}, 3000);
});
2014-08-22 23:08:56 +08:00
Data.useThreads.subscribe(function (bValue) {
2014-08-21 23:08:34 +08:00
2014-08-22 23:08:56 +08:00
Data.messageList([]);
2014-08-21 23:08:34 +08:00
Remote.saveSettings(null, {
2014-08-21 23:08:34 +08:00
'UseThreads': bValue ? '1' : '0'
});
});
2014-08-22 23:08:56 +08:00
Data.layout.subscribe(function (nValue) {
2014-08-21 23:08:34 +08:00
2014-08-22 23:08:56 +08:00
Data.messageList([]);
2014-08-21 23:08:34 +08:00
Remote.saveSettings(null, {
2014-08-21 23:08:34 +08:00
'Layout': nValue
});
});
2014-08-22 23:08:56 +08:00
Data.useCheckboxesInList.subscribe(function (bValue) {
Remote.saveSettings(null, {
2014-08-21 23:08:34 +08:00
'UseCheckboxesInList': bValue ? '1' : '0'
});
});
}, 50);
};
2014-10-18 21:43:44 +08:00
GeneralUserSetting.prototype.onShow = function ()
2014-08-21 23:08:34 +08:00
{
2014-08-22 23:08:56 +08:00
Data.desktopNotifications.valueHasMutated();
2014-08-21 23:08:34 +08:00
};
2014-10-18 21:43:44 +08:00
GeneralUserSetting.prototype.selectLanguage = function ()
2014-08-21 23:08:34 +08:00
{
require('Knoin/Knoin').showScreenPopup(require('View/Popup/Languages'));
2014-08-21 23:08:34 +08:00
};
2014-08-25 15:10:51 +08:00
2014-10-18 21:43:44 +08:00
module.exports = GeneralUserSetting;
2014-08-21 23:08:34 +08:00
2014-09-05 06:49:03 +08:00
}());