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-09-02 08:15:31 +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-09-05 06:49:03 +08:00
|
|
|
Enums = require('Common/Enums'),
|
|
|
|
Consts = require('Common/Consts'),
|
|
|
|
Globals = require('Common/Globals'),
|
|
|
|
Utils = require('Common/Utils'),
|
2015-01-26 07:09:22 +08:00
|
|
|
Translator = require('Common/Translator'),
|
|
|
|
|
2015-01-27 05:06:00 +08:00
|
|
|
AppStore = require('Stores/User/App'),
|
|
|
|
LanguageStore = require('Stores/Language'),
|
|
|
|
SettingsStore = require('Stores/User/Settings'),
|
|
|
|
NotificationStore = require('Stores/User/Notification'),
|
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-30 21:59:25 +08:00
|
|
|
function GeneralUserSettings()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2015-01-27 05:06:00 +08:00
|
|
|
this.language = LanguageStore.language;
|
|
|
|
this.messagesPerPage = SettingsStore.messagesPerPage;
|
2015-01-26 07:09:22 +08:00
|
|
|
this.messagesPerPageArray = Consts.Defaults.MessagesPerPageArray;
|
|
|
|
|
2015-01-27 05:06:00 +08:00
|
|
|
this.editorDefaultType = SettingsStore.editorDefaultType;
|
|
|
|
this.layout = SettingsStore.layout;
|
|
|
|
this.usePreviewPane = SettingsStore.usePreviewPane;
|
2015-01-26 07:09:22 +08:00
|
|
|
|
2015-01-27 05:06:00 +08:00
|
|
|
this.soundNotificationIsSupported = NotificationStore.soundNotificationIsSupported;
|
|
|
|
this.enableSoundNotification = NotificationStore.enableSoundNotification;
|
2015-01-26 07:09:22 +08:00
|
|
|
|
2015-01-27 05:06:00 +08:00
|
|
|
this.enableDesktopNotification = NotificationStore.enableDesktopNotification;
|
|
|
|
this.isDesktopNotificationSupported = NotificationStore.isDesktopNotificationSupported;
|
|
|
|
this.isDesktopNotificationDenied = NotificationStore.isDesktopNotificationDenied;
|
2015-01-26 07:09:22 +08:00
|
|
|
|
2015-01-27 05:06:00 +08:00
|
|
|
this.showImages = SettingsStore.showImages;
|
|
|
|
this.useCheckboxesInList = SettingsStore.useCheckboxesInList;
|
2015-02-03 07:58:58 +08:00
|
|
|
this.threadsAllowed = AppStore.threadsAllowed;
|
2015-01-27 05:06:00 +08:00
|
|
|
this.useThreads = SettingsStore.useThreads;
|
|
|
|
this.replySameFolder = SettingsStore.replySameFolder;
|
|
|
|
this.allowLanguagesOnSettings = AppStore.allowLanguagesOnSettings;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2015-01-26 07:09:22 +08:00
|
|
|
this.languageFullName = ko.computed(function () {
|
|
|
|
return Utils.convertLangName(this.language());
|
2014-08-21 23:08:34 +08:00
|
|
|
}, this);
|
|
|
|
|
|
|
|
this.languageTrigger = ko.observable(Enums.SaveSettingsStep.Idle).extend({'throttle': 100});
|
2014-10-30 07:27:13 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
this.mppTrigger = ko.observable(Enums.SaveSettingsStep.Idle);
|
2014-10-30 07:27:13 +08:00
|
|
|
this.editorDefaultTypeTrigger = ko.observable(Enums.SaveSettingsStep.Idle);
|
2015-01-05 03:30:07 +08:00
|
|
|
this.layoutTrigger = ko.observable(Enums.SaveSettingsStep.Idle);
|
2014-08-21 23:08:34 +08:00
|
|
|
|
|
|
|
this.isAnimationSupported = Globals.bAnimationSupported;
|
2014-10-30 07:07:48 +08:00
|
|
|
|
|
|
|
this.editorDefaultTypes = ko.computed(function () {
|
2015-01-26 07:09:22 +08:00
|
|
|
Translator.trigger();
|
2014-10-30 07:07:48 +08:00
|
|
|
return [
|
2015-01-26 07:09:22 +08:00
|
|
|
{'id': Enums.EditorDefaultType.Html, 'name': Translator.i18n('SETTINGS_GENERAL/LABEL_EDITOR_HTML')},
|
|
|
|
{'id': Enums.EditorDefaultType.Plain, 'name': Translator.i18n('SETTINGS_GENERAL/LABEL_EDITOR_PLAIN')},
|
|
|
|
{'id': Enums.EditorDefaultType.HtmlForced, 'name': Translator.i18n('SETTINGS_GENERAL/LABEL_EDITOR_HTML_FORCED')},
|
|
|
|
{'id': Enums.EditorDefaultType.PlainForced, 'name': Translator.i18n('SETTINGS_GENERAL/LABEL_EDITOR_PLAIN_FORCED')}
|
2014-10-30 07:07:48 +08:00
|
|
|
];
|
|
|
|
}, this);
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2015-01-05 03:30:07 +08:00
|
|
|
this.layoutTypes = ko.computed(function () {
|
2015-01-26 07:09:22 +08:00
|
|
|
Translator.trigger();
|
2015-01-05 03:30:07 +08:00
|
|
|
return [
|
2015-01-26 07:09:22 +08:00
|
|
|
{'id': Enums.Layout.NoPreview, 'name': Translator.i18n('SETTINGS_GENERAL/LABEL_LAYOUT_NO_SPLIT')},
|
|
|
|
{'id': Enums.Layout.SidePreview, 'name': Translator.i18n('SETTINGS_GENERAL/LABEL_LAYOUT_VERTICAL_SPLIT')},
|
|
|
|
{'id': Enums.Layout.BottomPreview, 'name': Translator.i18n('SETTINGS_GENERAL/LABEL_LAYOUT_HORIZONTAL_SPLIT')}
|
2015-01-05 03:30:07 +08:00
|
|
|
];
|
|
|
|
}, this);
|
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2015-01-27 05:06:00 +08:00
|
|
|
GeneralUserSettings.prototype.testSoundNotification = function ()
|
|
|
|
{
|
|
|
|
NotificationStore.playSoundNotification(true);
|
|
|
|
};
|
|
|
|
|
2014-10-30 21:59:25 +08:00
|
|
|
GeneralUserSettings.prototype.onBuild = function ()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
_.delay(function () {
|
|
|
|
|
|
|
|
var
|
2014-10-30 07:27:13 +08:00
|
|
|
f0 = Utils.settingsSaveHelperSimpleFunction(self.editorDefaultTypeTrigger, self),
|
2014-09-30 04:01:31 +08:00
|
|
|
f1 = Utils.settingsSaveHelperSimpleFunction(self.mppTrigger, self),
|
2015-01-05 03:30:07 +08:00
|
|
|
f2 = Utils.settingsSaveHelperSimpleFunction(self.layoutTrigger, self),
|
2014-09-30 04:01:31 +08:00
|
|
|
fReloadLanguageHelper = function (iSaveSettingsStep) {
|
|
|
|
return function() {
|
|
|
|
self.languageTrigger(iSaveSettingsStep);
|
|
|
|
_.delay(function () {
|
|
|
|
self.languageTrigger(Enums.SaveSettingsStep.Idle);
|
|
|
|
}, 1000);
|
|
|
|
};
|
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
;
|
|
|
|
|
2015-01-26 07:09:22 +08:00
|
|
|
self.language.subscribe(function (sValue) {
|
2014-08-21 23:08:34 +08:00
|
|
|
|
|
|
|
self.languageTrigger(Enums.SaveSettingsStep.Animate);
|
|
|
|
|
2015-01-26 07:09:22 +08:00
|
|
|
Translator.reload(sValue,
|
2014-09-30 04:01:31 +08:00
|
|
|
fReloadLanguageHelper(Enums.SaveSettingsStep.TrueResult),
|
|
|
|
fReloadLanguageHelper(Enums.SaveSettingsStep.FalseResult));
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-09-05 23:53:44 +08:00
|
|
|
Remote.saveSettings(null, {
|
2014-08-21 23:08:34 +08:00
|
|
|
'Language': sValue
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-01-26 07:09:22 +08:00
|
|
|
self.editorDefaultType.subscribe(function (sValue) {
|
2014-10-30 07:27:13 +08:00
|
|
|
Remote.saveSettings(f0, {
|
2014-08-21 23:08:34 +08:00
|
|
|
'EditorDefaultType': sValue
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-01-26 07:09:22 +08:00
|
|
|
self.messagesPerPage.subscribe(function (iValue) {
|
2014-08-21 23:08:34 +08:00
|
|
|
Remote.saveSettings(f1, {
|
|
|
|
'MPP': iValue
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-01-27 05:06:00 +08:00
|
|
|
self.showImages.subscribe(function (bValue) {
|
2014-09-05 23:53:44 +08:00
|
|
|
Remote.saveSettings(null, {
|
2014-08-21 23:08:34 +08:00
|
|
|
'ShowImages': bValue ? '1' : '0'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-01-26 07:09:22 +08:00
|
|
|
self.enableDesktopNotification.subscribe(function (bValue) {
|
2014-08-21 23:08:34 +08:00
|
|
|
Utils.timeOutAction('SaveDesktopNotifications', function () {
|
2014-09-05 23:53:44 +08:00
|
|
|
Remote.saveSettings(null, {
|
2014-08-21 23:08:34 +08:00
|
|
|
'DesktopNotifications': bValue ? '1' : '0'
|
|
|
|
});
|
|
|
|
}, 3000);
|
|
|
|
});
|
|
|
|
|
2015-01-27 05:06:00 +08:00
|
|
|
self.enableSoundNotification.subscribe(function (bValue) {
|
|
|
|
Utils.timeOutAction('SaveSoundNotification', function () {
|
|
|
|
Remote.saveSettings(null, {
|
|
|
|
'SoundNotification': bValue ? '1' : '0'
|
|
|
|
});
|
|
|
|
}, 3000);
|
|
|
|
});
|
|
|
|
|
|
|
|
self.replySameFolder.subscribe(function (bValue) {
|
2014-08-21 23:08:34 +08:00
|
|
|
Utils.timeOutAction('SaveReplySameFolder', function () {
|
2014-09-05 23:53:44 +08:00
|
|
|
Remote.saveSettings(null, {
|
2014-08-21 23:08:34 +08:00
|
|
|
'ReplySameFolder': bValue ? '1' : '0'
|
|
|
|
});
|
|
|
|
}, 3000);
|
|
|
|
});
|
|
|
|
|
2015-01-27 05:06:00 +08:00
|
|
|
self.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
|
|
|
|
2014-09-05 23:53:44 +08:00
|
|
|
Remote.saveSettings(null, {
|
2014-08-21 23:08:34 +08:00
|
|
|
'UseThreads': bValue ? '1' : '0'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-01-26 07:09:22 +08:00
|
|
|
self.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
|
|
|
|
2015-01-05 03:30:07 +08:00
|
|
|
Remote.saveSettings(f2, {
|
2014-08-21 23:08:34 +08:00
|
|
|
'Layout': nValue
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-01-27 05:06:00 +08:00
|
|
|
self.useCheckboxesInList.subscribe(function (bValue) {
|
2014-09-05 23:53:44 +08:00
|
|
|
Remote.saveSettings(null, {
|
2014-08-21 23:08:34 +08:00
|
|
|
'UseCheckboxesInList': bValue ? '1' : '0'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}, 50);
|
|
|
|
};
|
|
|
|
|
2014-10-30 21:59:25 +08:00
|
|
|
GeneralUserSettings.prototype.onShow = function ()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2015-01-26 07:09:22 +08:00
|
|
|
this.enableDesktopNotification.valueHasMutated();
|
2014-08-21 23:08:34 +08:00
|
|
|
};
|
|
|
|
|
2014-10-30 21:59:25 +08:00
|
|
|
GeneralUserSettings.prototype.selectLanguage = function ()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2014-09-06 05:44:29 +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-30 21:59:25 +08:00
|
|
|
module.exports = GeneralUserSettings;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
}());
|