Completed
Push — master ( e88c19...17669b )
by Rain
03:00
created

dev/Stores/User/Settings.js   A

Size

Lines of Code 80

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
nc 1
dl 0
loc 80
rs 10
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B Settings.js ➔ ??? 0 26 1
1
2
import window from 'window';
3
import ko from 'ko';
4
5
import {MESSAGES_PER_PAGE, MESSAGES_PER_PAGE_VALUES} from 'Common/Consts';
6
import {Layout, EditorDefaultType, Magics} from 'Common/Enums';
7
import {$html} from 'Common/Globals';
8
import {pInt} from 'Common/Utils';
9
import * as Events from 'Common/Events';
10
11
import * as Settings from 'Storage/Settings';
12
13
class SettingsUserStore
14
{
15
	constructor() {
16
17
		this.iAutoLogoutTimer = 0;
18
19
		this.layout = ko.observable(Layout.SidePreview)
20
			.extend({limitedList: [Layout.SidePreview, Layout.BottomPreview, Layout.NoPreview]});
21
22
		this.editorDefaultType = ko.observable(EditorDefaultType.Html)
23
			.extend({limitedList: [
24
				EditorDefaultType.Html, EditorDefaultType.Plain,
25
				EditorDefaultType.HtmlForced, EditorDefaultType.PlainForced
26
			]});
27
28
		this.messagesPerPage = ko.observable(MESSAGES_PER_PAGE)
29
			.extend({limitedList: MESSAGES_PER_PAGE_VALUES});
30
31
		this.showImages = ko.observable(false);
32
		this.useCheckboxesInList = ko.observable(true);
33
		this.useThreads = ko.observable(false);
34
		this.replySameFolder = ko.observable(false);
35
36
		this.autoLogout = ko.observable(30);
37
38
		this.computers();
39
		this.subscribers();
40
	}
41
42
	computers() {
43
		this.usePreviewPane = ko.computed(() => Layout.NoPreview !== this.layout());
44
	}
45
46
	subscribers() {
47
		this.layout.subscribe((nValue) => {
48
			$html.toggleClass('rl-no-preview-pane', Layout.NoPreview === nValue);
49
			$html.toggleClass('rl-side-preview-pane', Layout.SidePreview === nValue);
50
			$html.toggleClass('rl-bottom-preview-pane', Layout.BottomPreview === nValue);
51
			Events.pub('layout', [nValue]);
52
		});
53
	}
54
55
	populate() {
56
		this.layout(pInt(Settings.settingsGet('Layout')));
57
		this.editorDefaultType(Settings.settingsGet('EditorDefaultType'));
58
59
		this.autoLogout(pInt(Settings.settingsGet('AutoLogout')));
60
		this.messagesPerPage(Settings.settingsGet('MPP'));
61
62
		this.showImages(!!Settings.settingsGet('ShowImages'));
63
		this.useCheckboxesInList(!!Settings.settingsGet('UseCheckboxesInList'));
64
		this.useThreads(!!Settings.settingsGet('UseThreads'));
65
		this.replySameFolder(!!Settings.settingsGet('ReplySameFolder'));
66
67
		Events.sub('rl.auto-logout-refresh', () => {
68
			window.clearTimeout(this.iAutoLogoutTimer);
69
			if (0 < this.autoLogout() && !Settings.settingsGet('AccountSignMe'))
70
			{
71
				this.iAutoLogoutTimer = window.setTimeout(() => {
72
					Events.pub('rl.auto-logout');
73
				}, this.autoLogout() * Magics.Time1m);
74
			}
75
		});
76
77
		Events.pub('rl.auto-logout-refresh');
78
	}
79
}
80
81
module.exports = new SettingsUserStore();
82