mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-29 20:19:22 +03:00
Cleanup some JavaScript
This commit is contained in:
parent
18fbf332c2
commit
24b638cd82
16 changed files with 64 additions and 88 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import ko from 'ko';
|
||||
import { addObservablesTo } from 'External/ko';
|
||||
|
||||
import { SaveSettingsStep, UploadErrorCode, Capa } from 'Common/Enums';
|
||||
import { changeTheme, convertThemeName } from 'Common/Utils';
|
||||
|
|
@ -10,24 +10,29 @@ import { ThemeStore } from 'Stores/Theme';
|
|||
|
||||
import Remote from 'Remote/User/Fetch';
|
||||
|
||||
const themeBackground = {
|
||||
name: ThemeStore.userBackgroundName,
|
||||
hash: ThemeStore.userBackgroundHash
|
||||
};
|
||||
addObservablesTo(themeBackground, {
|
||||
uploaderButton: null,
|
||||
loading: false,
|
||||
error: ''
|
||||
});
|
||||
|
||||
export class ThemesUserSettings /*extends AbstractViewSettings*/ {
|
||||
constructor() {
|
||||
this.theme = ThemeStore.theme;
|
||||
this.themes = ThemeStore.themes;
|
||||
this.themesObjects = ko.observableArray();
|
||||
|
||||
this.background = {};
|
||||
this.background.name = ThemeStore.userBackgroundName;
|
||||
this.background.hash = ThemeStore.userBackgroundHash;
|
||||
this.background.uploaderButton = ko.observable(null);
|
||||
this.background.loading = ko.observable(false);
|
||||
this.background.error = ko.observable('');
|
||||
this.background = themeBackground;
|
||||
|
||||
this.capaUserBackground = ko.observable(Settings.capa(Capa.UserBackground));
|
||||
this.capaUserBackground = Settings.capa(Capa.UserBackground);
|
||||
|
||||
this.themeTrigger = ko.observable(SaveSettingsStep.Idle).extend({ debounce: 100 });
|
||||
|
||||
this.theme.subscribe((value) => {
|
||||
ThemeStore.theme.subscribe(value => {
|
||||
this.themesObjects.forEach(theme => {
|
||||
theme.selected(value === theme.name);
|
||||
});
|
||||
|
|
@ -41,10 +46,10 @@ export class ThemesUserSettings /*extends AbstractViewSettings*/ {
|
|||
}
|
||||
|
||||
onBuild() {
|
||||
const currentTheme = this.theme();
|
||||
const currentTheme = ThemeStore.theme();
|
||||
|
||||
this.themesObjects(
|
||||
this.themes.map(theme => ({
|
||||
ThemeStore.themes.map(theme => ({
|
||||
name: theme,
|
||||
nameDisplay: convertThemeName(theme),
|
||||
selected: ko.observable(theme === currentTheme),
|
||||
|
|
@ -54,28 +59,28 @@ export class ThemesUserSettings /*extends AbstractViewSettings*/ {
|
|||
|
||||
// initUploader
|
||||
|
||||
if (this.background.uploaderButton() && this.capaUserBackground()) {
|
||||
if (themeBackground.uploaderButton() && this.capaUserBackground) {
|
||||
const oJua = new Jua({
|
||||
action: serverRequest('UploadBackground'),
|
||||
limit: 1,
|
||||
clickElement: this.background.uploaderButton()
|
||||
clickElement: themeBackground.uploaderButton()
|
||||
});
|
||||
|
||||
oJua
|
||||
.on('onStart', () => {
|
||||
this.background.loading(true);
|
||||
this.background.error('');
|
||||
themeBackground.loading(true);
|
||||
themeBackground.error('');
|
||||
return true;
|
||||
})
|
||||
.on('onComplete', (id, result, data) => {
|
||||
this.background.loading(false);
|
||||
themeBackground.loading(false);
|
||||
|
||||
if (result && id && data && data.Result && data.Result.Name && data.Result.Hash) {
|
||||
this.background.name(data.Result.Name);
|
||||
this.background.hash(data.Result.Hash);
|
||||
themeBackground.name(data.Result.Name);
|
||||
themeBackground.hash(data.Result.Hash);
|
||||
} else {
|
||||
this.background.name('');
|
||||
this.background.hash('');
|
||||
themeBackground.name('');
|
||||
themeBackground.hash('');
|
||||
|
||||
let errorMsg = '';
|
||||
if (data.ErrorCode) {
|
||||
|
|
@ -94,7 +99,7 @@ export class ThemesUserSettings /*extends AbstractViewSettings*/ {
|
|||
errorMsg = data.ErrorMessage;
|
||||
}
|
||||
|
||||
this.background.error(errorMsg || i18n('SETTINGS_THEMES/ERROR_UNKNOWN'));
|
||||
themeBackground.error(errorMsg || i18n('SETTINGS_THEMES/ERROR_UNKNOWN'));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
@ -103,14 +108,14 @@ export class ThemesUserSettings /*extends AbstractViewSettings*/ {
|
|||
}
|
||||
|
||||
onShow() {
|
||||
this.background.error('');
|
||||
themeBackground.error('');
|
||||
}
|
||||
|
||||
clearBackground() {
|
||||
if (this.capaUserBackground()) {
|
||||
if (this.capaUserBackground) {
|
||||
Remote.request('ClearUserBackground', () => {
|
||||
this.background.name('');
|
||||
this.background.hash('');
|
||||
themeBackground.name('');
|
||||
themeBackground.hash('');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue