2016-07-16 05:29:42 +08:00
|
|
|
import ko from 'ko';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
import {
|
2019-07-05 03:19:24 +08:00
|
|
|
pInt,
|
|
|
|
settingsSaveHelperSimpleFunction,
|
|
|
|
changeTheme,
|
2021-01-26 05:00:13 +08:00
|
|
|
convertThemeName
|
2016-07-16 05:29:42 +08:00
|
|
|
} from 'Common/Utils';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2020-08-14 04:58:41 +08:00
|
|
|
import { SaveSettingsStep } from 'Common/Enums';
|
2021-03-10 18:44:48 +08:00
|
|
|
import { Settings, SettingsGet } from 'Common/Globals';
|
2021-01-26 05:00:13 +08:00
|
|
|
import { reload as translatorReload, convertLangName } from 'Common/Translator';
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
import { showScreenPopup } from 'Knoin/Knoin';
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2020-09-15 01:40:56 +08:00
|
|
|
import Remote from 'Remote/Admin/Fetch';
|
2016-09-13 04:50:21 +08:00
|
|
|
|
2021-01-27 07:26:31 +08:00
|
|
|
import { ThemeStore } from 'Stores/Theme';
|
2021-01-27 17:59:15 +08:00
|
|
|
import { LanguageStore } from 'Stores/Language';
|
2021-02-17 21:40:21 +08:00
|
|
|
import { AppAdminStore } from 'Stores/Admin/App';
|
|
|
|
import { CapaAdminStore } from 'Stores/Admin/Capa';
|
2021-01-26 05:00:13 +08:00
|
|
|
import LanguagesPopupView from 'View/Popup/Languages';
|
2015-03-28 06:06:56 +08:00
|
|
|
|
2021-01-22 23:32:08 +08:00
|
|
|
export class GeneralAdminSettings {
|
2016-07-16 05:29:42 +08:00
|
|
|
constructor() {
|
|
|
|
this.language = LanguageStore.language;
|
|
|
|
this.languages = LanguageStore.languages;
|
2021-01-27 17:59:15 +08:00
|
|
|
|
2021-03-10 18:44:48 +08:00
|
|
|
const aLanguagesAdmin = Settings.app('languagesAdmin');
|
2021-01-27 17:59:15 +08:00
|
|
|
this.languagesAdmin = ko.observableArray(Array.isArray(aLanguagesAdmin) ? aLanguagesAdmin : []);
|
|
|
|
this.languageAdmin = ko
|
2021-03-10 18:44:48 +08:00
|
|
|
.observable(SettingsGet('LanguageAdmin'))
|
2021-02-17 21:40:21 +08:00
|
|
|
.extend({ limitedList: this.languagesAdmin });
|
2016-07-16 05:29:42 +08:00
|
|
|
|
|
|
|
this.theme = ThemeStore.theme;
|
|
|
|
this.themes = ThemeStore.themes;
|
|
|
|
|
|
|
|
this.capaThemes = CapaAdminStore.themes;
|
|
|
|
this.capaUserBackground = CapaAdminStore.userBackground;
|
|
|
|
this.capaAdditionalAccounts = CapaAdminStore.additionalAccounts;
|
|
|
|
this.capaIdentities = CapaAdminStore.identities;
|
|
|
|
this.capaAttachmentThumbnails = CapaAdminStore.attachmentThumbnails;
|
|
|
|
this.capaTemplates = CapaAdminStore.templates;
|
|
|
|
|
2020-10-27 18:09:24 +08:00
|
|
|
ko.addObservablesTo(this, {
|
2021-03-10 18:44:48 +08:00
|
|
|
allowLanguagesOnSettings: !!SettingsGet('AllowLanguagesOnSettings'),
|
|
|
|
newMoveToFolder: !!SettingsGet('NewMoveToFolder'),
|
2020-10-27 18:09:24 +08:00
|
|
|
attachmentLimitTrigger: SaveSettingsStep.Idle,
|
|
|
|
languageTrigger: SaveSettingsStep.Idle,
|
|
|
|
themeTrigger: SaveSettingsStep.Idle
|
|
|
|
});
|
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
this.weakPassword = AppAdminStore.weakPassword;
|
|
|
|
|
2017-10-02 01:54:50 +08:00
|
|
|
this.dataFolderAccess = AppAdminStore.dataFolderAccess;
|
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
this.mainAttachmentLimit = ko
|
2021-03-10 18:44:48 +08:00
|
|
|
.observable(pInt(SettingsGet('AttachmentLimit')) / (1024 * 1024))
|
2021-02-10 19:12:36 +08:00
|
|
|
.extend({ debounce: 500 });
|
2016-07-16 05:29:42 +08:00
|
|
|
|
2021-03-10 18:44:48 +08:00
|
|
|
this.uploadData = SettingsGet('PhpUploadSizes');
|
2019-07-05 03:19:24 +08:00
|
|
|
this.uploadDataDesc =
|
|
|
|
this.uploadData && (this.uploadData.upload_max_filesize || this.uploadData.post_max_size)
|
|
|
|
? [
|
|
|
|
this.uploadData.upload_max_filesize
|
|
|
|
? 'upload_max_filesize = ' + this.uploadData.upload_max_filesize + '; '
|
|
|
|
: '',
|
|
|
|
this.uploadData.post_max_size ? 'post_max_size = ' + this.uploadData.post_max_size : ''
|
|
|
|
].join('')
|
|
|
|
: '';
|
|
|
|
|
|
|
|
this.themesOptions = ko.computed(() =>
|
2021-01-22 19:23:20 +08:00
|
|
|
this.themes.map(theme => ({ optValue: theme, optText: convertThemeName(theme) }))
|
2019-07-05 03:19:24 +08:00
|
|
|
);
|
2016-07-16 05:29:42 +08:00
|
|
|
|
|
|
|
this.languageFullName = ko.computed(() => convertLangName(this.language()));
|
|
|
|
this.languageAdminFullName = ko.computed(() => convertLangName(this.languageAdmin()));
|
|
|
|
|
2021-02-10 19:12:36 +08:00
|
|
|
this.languageAdminTrigger = ko.observable(SaveSettingsStep.Idle).extend({ debounce: 100 });
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
onBuild() {
|
2020-07-23 02:28:25 +08:00
|
|
|
setTimeout(() => {
|
2019-07-05 03:19:24 +08:00
|
|
|
const f1 = settingsSaveHelperSimpleFunction(this.attachmentLimitTrigger, this),
|
2016-07-16 05:29:42 +08:00
|
|
|
f2 = settingsSaveHelperSimpleFunction(this.languageTrigger, this),
|
|
|
|
f3 = settingsSaveHelperSimpleFunction(this.themeTrigger, this),
|
|
|
|
fReloadLanguageHelper = (saveSettingsStep) => () => {
|
|
|
|
this.languageAdminTrigger(saveSettingsStep);
|
2020-08-14 04:58:41 +08:00
|
|
|
setTimeout(() => this.languageAdminTrigger(SaveSettingsStep.Idle), 1000);
|
2016-07-16 05:29:42 +08:00
|
|
|
};
|
2015-03-28 06:06:56 +08:00
|
|
|
|
2020-10-13 01:46:41 +08:00
|
|
|
this.mainAttachmentLimit.subscribe(value => {
|
2016-07-16 05:29:42 +08:00
|
|
|
Remote.saveAdminConfig(f1, {
|
|
|
|
'AttachmentLimit': pInt(value)
|
2015-03-28 06:06:56 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-10-13 01:46:41 +08:00
|
|
|
this.language.subscribe(value => {
|
2016-07-16 05:29:42 +08:00
|
|
|
Remote.saveAdminConfig(f2, {
|
2020-08-07 00:24:46 +08:00
|
|
|
'Language': value.trim()
|
2016-07-16 05:29:42 +08:00
|
|
|
});
|
2014-08-21 23:08:34 +08:00
|
|
|
});
|
|
|
|
|
2020-10-13 01:46:41 +08:00
|
|
|
this.languageAdmin.subscribe(value => {
|
2016-07-16 05:29:42 +08:00
|
|
|
this.languageAdminTrigger(SaveSettingsStep.Animate);
|
2019-07-05 03:19:24 +08:00
|
|
|
translatorReload(true, value)
|
|
|
|
.then(fReloadLanguageHelper(SaveSettingsStep.TrueResult), fReloadLanguageHelper(SaveSettingsStep.FalseResult))
|
|
|
|
.then(() => {
|
|
|
|
Remote.saveAdminConfig(null, {
|
2020-08-07 00:24:46 +08:00
|
|
|
'LanguageAdmin': value.trim()
|
2019-07-05 03:19:24 +08:00
|
|
|
});
|
2016-07-16 05:29:42 +08:00
|
|
|
});
|
2015-05-18 04:38:20 +08:00
|
|
|
});
|
|
|
|
|
2020-10-13 01:46:41 +08:00
|
|
|
this.theme.subscribe(value => {
|
2016-07-16 05:29:42 +08:00
|
|
|
changeTheme(value, this.themeTrigger);
|
|
|
|
Remote.saveAdminConfig(f3, {
|
2020-08-07 00:24:46 +08:00
|
|
|
'Theme': value.trim()
|
2016-07-16 05:29:42 +08:00
|
|
|
});
|
2015-02-12 05:39:27 +08:00
|
|
|
});
|
|
|
|
|
2020-10-13 01:46:41 +08:00
|
|
|
this.capaAdditionalAccounts.subscribe(value => {
|
2016-07-16 05:29:42 +08:00
|
|
|
Remote.saveAdminConfig(null, {
|
2020-07-30 03:49:41 +08:00
|
|
|
'CapaAdditionalAccounts': value ? '1' : '0'
|
2016-07-16 05:29:42 +08:00
|
|
|
});
|
2014-08-21 23:08:34 +08:00
|
|
|
});
|
|
|
|
|
2020-10-13 01:46:41 +08:00
|
|
|
this.capaIdentities.subscribe(value => {
|
2016-07-16 05:29:42 +08:00
|
|
|
Remote.saveAdminConfig(null, {
|
2020-07-30 03:49:41 +08:00
|
|
|
'CapaIdentities': value ? '1' : '0'
|
2016-07-16 05:29:42 +08:00
|
|
|
});
|
2015-01-05 03:30:07 +08:00
|
|
|
});
|
|
|
|
|
2020-10-13 01:46:41 +08:00
|
|
|
this.capaTemplates.subscribe(value => {
|
2016-07-16 05:29:42 +08:00
|
|
|
Remote.saveAdminConfig(null, {
|
2020-07-30 03:49:41 +08:00
|
|
|
'CapaTemplates': value ? '1' : '0'
|
2016-07-16 05:29:42 +08:00
|
|
|
});
|
2014-08-21 23:08:34 +08:00
|
|
|
});
|
|
|
|
|
2020-10-13 01:46:41 +08:00
|
|
|
this.capaAttachmentThumbnails.subscribe(value => {
|
2016-07-16 05:29:42 +08:00
|
|
|
Remote.saveAdminConfig(null, {
|
2020-07-30 03:49:41 +08:00
|
|
|
'CapaAttachmentThumbnails': value ? '1' : '0'
|
2016-07-16 05:29:42 +08:00
|
|
|
});
|
2014-08-21 23:08:34 +08:00
|
|
|
});
|
|
|
|
|
2020-10-13 01:46:41 +08:00
|
|
|
this.capaThemes.subscribe(value => {
|
2016-07-16 05:29:42 +08:00
|
|
|
Remote.saveAdminConfig(null, {
|
2020-07-30 03:49:41 +08:00
|
|
|
'CapaThemes': value ? '1' : '0'
|
2016-07-16 05:29:42 +08:00
|
|
|
});
|
2016-06-30 08:02:45 +08:00
|
|
|
});
|
|
|
|
|
2020-10-13 01:46:41 +08:00
|
|
|
this.capaUserBackground.subscribe(value => {
|
2016-07-16 05:29:42 +08:00
|
|
|
Remote.saveAdminConfig(null, {
|
2020-07-30 03:49:41 +08:00
|
|
|
'CapaUserBackground': value ? '1' : '0'
|
2016-07-16 05:29:42 +08:00
|
|
|
});
|
|
|
|
});
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2020-10-13 01:46:41 +08:00
|
|
|
this.allowLanguagesOnSettings.subscribe(value => {
|
2016-07-16 05:29:42 +08:00
|
|
|
Remote.saveAdminConfig(null, {
|
2020-07-30 03:49:41 +08:00
|
|
|
'AllowLanguagesOnSettings': value ? '1' : '0'
|
2016-07-16 05:29:42 +08:00
|
|
|
});
|
|
|
|
});
|
2017-02-09 01:48:53 +08:00
|
|
|
|
2020-10-13 01:46:41 +08:00
|
|
|
this.newMoveToFolder.subscribe(value => {
|
2017-02-09 01:48:53 +08:00
|
|
|
Remote.saveAdminConfig(null, {
|
2020-07-30 03:49:41 +08:00
|
|
|
'NewMoveToFolder': value ? '1' : '0'
|
2017-02-09 01:48:53 +08:00
|
|
|
});
|
|
|
|
});
|
2020-08-14 04:58:41 +08:00
|
|
|
}, 50);
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
selectLanguage() {
|
2021-01-26 05:00:13 +08:00
|
|
|
showScreenPopup(LanguagesPopupView, [this.language, this.languages(), LanguageStore.userLanguage()]);
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
selectLanguageAdmin() {
|
2021-01-26 05:00:13 +08:00
|
|
|
showScreenPopup(LanguagesPopupView, [
|
2019-07-05 03:19:24 +08:00
|
|
|
this.languageAdmin,
|
|
|
|
this.languagesAdmin(),
|
2021-03-10 18:44:48 +08:00
|
|
|
SettingsGet('UserLanguageAdmin')
|
2016-07-16 05:29:42 +08:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|